cat <<EOF >a.c extern int puts(const char*); char *program; void fail() {puts(program);} EOF cat <<EOF >b.c extern int puts(const char*); extern char *program; extern void fail(); void usage() {puts(program);} int main(int argc, char *argv[]) { program = argv[0]; if (argc) usage(); else fail(); return 0; } EOF
gcc -flto -fuse-linker-plugin -O2 b.c a.c /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccvkxseZ.lto.o: in function usage:ccHTGBCK.o(.text+0x3): error: undefined reference to 'program' /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccvkxseZ.lto.o: in function fail:ccHTGBCK.o(.text+0x13): error: undefined reference to 'program' /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccvkxseZ.lto.o: in function main:ccHTGBCK.o(.text+0x2c): error: undefined reference to 'program' collect2: ld returned 1 exit status Works with reversed ordering or without -fuse-linker-plugin -- Summary: Undefined references with -flto -fuse-linker-plugin, dependent on object file ordering Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: amonakov at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43355