Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Last active February 17, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushieno/9116656290e1a028c0074cba1943a7ce to your computer and use it in GitHub Desktop.
Save atsushieno/9116656290e1a028c0074cba1943a7ce to your computer and use it in GitHub Desktop.
LTO
all: run
x:
clang++ -g -O0 -shared -fPIC x.cpp -o libx.so
y: x
clang++ -g -O0 -shared -fPIC y.cpp -o liby.so -L . -l x
z: y
clang++ -g -O0 z.cpp -o z -L . -lx -ly -lc++ -flto
run: z
LD_LIBRARY_PATH=. ./z
int x() { return 5; }
int a() { return 0; }
extern "C" __attribute__ ((visibility ("default"))) int b() { return 7; }
int x();
int y() { return x() + 3; }
int a() { return 4; }
extern "C" __attribute__ ((visibility ("default"))) int b() { return 8; }
#include <iostream>
int x();
int y();
int a();
//extern "C" int b();
extern "C" __attribute__ ((visibility ("default"))) int b() { return 20; }
int main() { std::cout << x() + y() + a() + b() << std::endl; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment