https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108761
Bug ID: 108761 Summary: Add option to produce a unique section for non-COMDAT __attribute__((section("foo"))) object Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: i at maskray dot me Target Milestone: --- % cat a.cc __attribute__((section("foo"))) void f() {} __attribute__((section("foo"))) void g() {} % g++ -c -ffunction-sections a.cc % readelf -WS a.o | grep foo [ 4] foo PROGBITS 0000000000000000 000040 00000e 00 AX 0 0 1 There is one section named `foo`, with f and g in it (they do not use COMDAT). In ld --gc-sections, f and g are retained or discarded as a unit. If we place f and g in two `foo` sections, --gc-sections can discard them separately. (We need assembler syntax `.section foo,"ax",@progbits,unique,1` which requires binutils>=2.35.) https://reviews.llvm.org/D143745 proposes to add such a feature with an option name like `-ffunction-sections[=(default,all)]`. I feel that the option argument is non-intuitive but do not come up with a better name right now. I raise this feature request to seek feedback from GCC :)