https://sourceware.org/bugzilla/show_bug.cgi?id=19161
Bug ID: 19161 Summary: GNU ld wrongly garbage collects section referenced via __start_SECTIONNAME Product: binutils Version: unspecified Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: xinliangli at gmail dot com Target Milestone: --- 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' 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