https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61848
Bug ID: 61848 Summary: a previous declaration causes the section attribute to be lost Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Take: void f(void); void __attribute__ ((__section__(".init.text"))) f(void) { } ---- CUT --- The section attribute is lost from the function. at -O1, -O0, -Og we get: .file "t.c" .text .globl f .type f, @function f: .LFB0: .cfi_startproc rep; ret .cfi_endproc .LFE0: .size f, .-f .ident "GCC: (GNU) 4.10.0 20140718 (experimental)" .section .note.GNU-stack,"",@progbits While at -O2 and above (including -Os), we get: .file "t.c" .section .text.unlikely,"ax",@progbits .LCOLDB0: .text .LHOTB0: .p2align 4,,15 .globl f .type f, @function f: .LFB0: .cfi_startproc rep; ret .cfi_endproc .LFE0: .size f, .-f .section .text.unlikely .LCOLDE0: .text .LHOTE0: .ident "GCC: (GNU) 4.10.0 20140718 (experimental)" .section .note.GNU-stack,"",@progbits Notice how f is no longer in the correct section. If we comment out the declaration (prototype), we get: .file "t.c" .section .init.text,"ax",@progbits .globl f .type f, @function f: .LFB0: .cfi_startproc rep; ret .cfi_endproc .LFE0: .size f, .-f .ident "GCC: (GNU) 4.10.0 20140718 (experimental)" .section .note.GNU-stack,"",@progbits