lto

How can I use lto with static libraries?

回眸只為那壹抹淺笑 提交于 2019-11-27 14:38:35
问题 When I try to build static libraries with -flto , I get undefined reference errors: library.cpp : #include <iostream> void foo() { std::cout << "Test!" << std::endl; } main.cpp : void foo(); int main() { foo(); return 0; } Compilation output : $ g++ -flto -c library.cpp $ ar rcs library.a library.o $ g++ -flto main.cpp library.a /tmp/ccZIgxCY.ltrans0.ltrans.o: In function `main': ccZIgxCY.ltrans0.o:(.text+0x5): undefined reference to `foo()' collect2: error: ld returned 1 exit status It works

Requirements to use flto

蹲街弑〆低调 提交于 2019-11-27 06:49:52
问题 If I want to compile my project with -flto is it enough to have built gcc with --enable-gold or do I also need to build gold and replace ld with it? And do I need any other flags? Ie I'm doing this gcc -flto one.c two.c 回答1: According to https://gcc.gnu.org/wiki/LinkTimeOptimization#Requirements, Despite the " link time " name, LTO does not need to use any special linker features. The basic mechanism needed is the detection of GIMPLE sections inside object files. This is currently implemented

What information does GCC Profile Guided Optimization (PGO) collect and which optimizations use it?

雨燕双飞 提交于 2019-11-27 04:21:00
问题 Which information does GCC collect when I enable -fprofile-generate and which optimization does in fact uses the collected information (when setting the -fprofile-use flag) ? I need citations here. I've searched for a while but didn't found anything documented. Information regarding link-time optimization (LTO) would be a plus! =D 回答1: -fprofile-generate enables -fprofile-arcs , -fprofile-values and -fvpt . -fprofile-use enables -fbranch-probabilities , -fvpt , -funroll-loops , -fpeel-loops