The bug report is about the use of the option "-fwhole-program".
When I compiled a program (crlibm-0.18beta1.tar.gz , described in bug report http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32180 ) I found that GCC 4.2.0 with option "-O2" produced code that was _slightly_ faster than GCC 4.3.0 with option "-O3" (on this _one_ particular program). I set out to make GCC 4.3.0 produce better results and read the info file for gcc. I added a huge list of options intending to whittle them down a few at a time. I did eventually get a huge speedup, but this bug report is not about benchmarking. This is about the option "-fwhole-program". I had it on the huge list and it caused problems. The docs for "-fwhole-program" say this: `-fwhole-program' Assume that the current compilation unit represents whole program being compiled. All public functions and variables with the exception of `main' and those merged by attribute `externally_visible' become static functions and in a affect gets more aggressively optimized by interprocedural optimizers. While this option is equivalent to proper use of `static' keyword for programs consisting of single file, in combination with option `--combine' this flag can be used to compile most of smaller scale C programs since the functions and variables become local for the whole combined compilation unit, not for the single source file itself. Problem: Using "-fwhole-program" to compile "C" files that are then archived into a library produces a library without any functions to call. /usr/test/bin/gcc -O0 -std=c89 -g -fgcse-sm -fgcse-las -fgcse-after-reload -fsee -ftree-loop-linear -ftree-loop-im -fivopts -ftree-vectorize -ftracer -fvariable-expansion-in-unroller -fweb -fwhole-program -ffast-math -finline-limit=2400 -fmodulo-sched -Winline -march=athlon-xp -fgnu89-inline -finline-functions -o crlibm_testval test_val.o test_common.o ../libcrlibm.a -lmpfr -lmpfr -lgmp -lgmp -lm test_val.o: In function `main': /root/downloads/crlibm/tests/test_val.c:114: undefined reference to `crlibm_init' test_common.o: In function `rand_for_pow_perf': /root/downloads/crlibm/tests/test_common.c:326: undefined reference to `log_rn' /root/downloads/crlibm/tests/test_common.c:327: undefined reference to `log_rn' test_common.o: In function `test_init': /root/downloads/crlibm/tests/test_common.c:604: undefined reference to `exp_ru' /root/downloads/crlibm/tests/test_common.c:606: undefined reference to `exp_rd' ... Would we need to specify every single file in the library PLUS the final file we would link to the library to produce an executable using "-fwhole-program" ? Another way of saying that is _IF_ you use "-fwhole-program" you can not use the "-c" option since you must link everything. Example: Yes: gcc "-fwhole-program" file_1.c file_2.c file_3.c file_4.c -o result No: gcc "-fwhole-program" -c file_1.c file_2.c gcc "-fwhole-program" -c file_3.c file_4.c ar cru library.a file_1.o file_2.o file_3.o file_4.o gcc "-fwhole-program" file_5.c -o result -lrary file_1.c:000: undefined reference to `xyz' ... If there are circumstances where it can NOT be used it should be documented. The docs say it can be used on multiple files. If "-fwhole-program" and "-c" can not be used together the "spec" file should make the options mutually exclusive. The "-fwhole-program" option _could_ be used for libraries if it respected a tag like "extern" that meant that the function would be called from outside the current compilation unit. A new GNU extension is needed, something like "antistatic" or "declare" to tell the "-fwhole-program" option to leave the ABI alone and work on everything else. Here is a puny example: void usage(){ fprintf (stderr, "\nUsage: [-v] file\n"); exit (EXIT_SUCCESS); } char* do_something(FILE* f, char* line) { } antistatic void ABI_check_program(int x) { if (x) usage(); else do_something("test", 3); } If we compiled the above example with the proposed GNU extension and used "-fwhole-program" as an option to gcc then the only visible function would be ABI_check_program(), the rest would disappear. That would allow "-fwhole-program" to have more uses (libraries or sections of programs not intended to interact with each other _except_ through a common file). It could be used to "protect" libraries from people looking in the .h file and going around the ABI to make direct calls (possibly inadvertantly due to similar spelling). -- Summary: Use of option "-fwhole-program" needs to exclude option "-c" in spec file Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rob1weld at aol dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32329