https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92938
Bug ID: 92938 Summary: constprop function is assigned to a different section than the original function Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jcmvbkbc at gcc dot gnu.org Target Milestone: --- Created attachment 47496 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47496&action=edit test_bitmap.i A bug is reported on the linux kernel mailing list: https://lore.kernel.org/lkml/20191213211901.gl32...@smile.fi.intel.com/T/#t In linux kernel there must be no references from .text* sections to data or functions in .init* sections. In the attached source there's no such reference: __init test_replace calls regular bitmap_replace passing it a pointer to __initconst exp2_to_exp3_mask variable. But during optimization process such reference appears. When I look into test_bitmap.i.085t.fixup_cfg3 I see the following: __attribute__((no_instrument_function, unused, gnu_inline)) bitmap_replace.constprop (long unsigned int * dst, const long unsigned int * old, const long unsigned int * new) { ... __bitmap_replace (dst_11(D), old_3(D), new_6(D), &exp2_to_exp3_mask, 64); ... } __attribute__((cold, section (".init.text"))) test_replace () { ... bitmap_replace.constprop (&bmap, &exp2[0], &exp2[1]); ... } It looks like the function bitmap_replace.constprop should belong to the same section as the function test_replace. Compiler command line: cc1 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -std=gnu89 -ffreestanding -mlongcalls -mtext-section-literals -mforce-no-pic -mno-serialize-volatile -fno-delete-null-pointer-checks -O2 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -femit-struct-debug-baseonly -fno-var-tracking -fno-inline-functions-called-once -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack test_bitmap.i