https://sourceware.org/bugzilla/show_bug.cgi?id=19161
Sriraman Tallam <tmsriram at google dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tmsriram at google dot com --- Comment #1 from Sriraman Tallam <tmsriram at google dot com> --- (In reply to David Li from comment #0) > Here is a small reproducible: > > // Failed with gnu ld > > gcc -fuse-ld=bfd -fdata-sections -Wl,--gc-sections gctest.c gctest2.c > > /tmp/cc4jxArE.o: In function `dump': > gctest2.c:(.text+0xc): undefined reference to `__start_my_section' gold linker has this check to prevent any named section 'XXX' from being garbage collected if it finds a symbol __start_XXX or __stop_XXX: In gold/gc.h: //If the symbol name matches '__start_XXX' then the section with // the C identifier like name 'XXX' should not be garbage collected. // A similar treatment to symbols with the name '__stop_XXX'. if (is_prefix_of(cident_section_start_prefix, gsym->name())) { ... GNU ld should also be doing this? > collect2: error: ld returned 1 exit status > > > // Fine with Gold: > > gcc -fuse-ld=gold -fdata-sections -Wl,--gc-sections gctest.c gctest2.c > > > > > // gctest.c > > extern int variable; > int main() > { > return variable; > } > > > // gctest2.c > > typedef struct A { > int i; > int j; > } A; > > extern int printf(const char*,...); > extern int atexit(void (*)(void)); > A __attribute__((section("my_section"))) a[2] = {{1,2}, {3,4}}; > > extern A __start_my_section; > extern A __stop_my_section; > > int variable = 0; > > > void dump() > { > A* ap = &__start_my_section; > printf("%d %d\n", ap->i, ap->j); > } > > void __attribute__((constructor)) foo() { > atexit(dump); > } -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils