https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68678
Bug ID: 68678 Summary: Initialization of pointer by constant expression using static ctor. Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sorganov at gmail dot com Target Milestone: --- g++ 5 produces initialization for the following case using static constructor, while earlier versions of g++ as well as gcc 5 in C compilation mode do it using simple entry in .data section. This sounds like missed optimization. $ cat dynamic-init.cc typedef struct S { int x; } S; void const* p = (void*)(0x1234 + sizeof(S)); $ ~/try/gcc-5.2.0/bin/gcc -O2 -c -save-temps dynamic-init.cc $ cat dynamic-init.s .file "dynamic-init.cc" .section .text.unlikely,"ax",@progbits .LCOLDB0: .section .text.startup,"ax",@progbits .LHOTB0: .p2align 4,,15 .type _GLOBAL__sub_I_p, @function _GLOBAL__sub_I_p: .LFB1: .cfi_startproc movq $4664, p(%rip) ret .cfi_endproc .LFE1: .size _GLOBAL__sub_I_p, .-_GLOBAL__sub_I_p .section .text.unlikely .LCOLDE0: .section .text.startup .LHOTE0: .section .init_array,"aw" .align 8 .quad _GLOBAL__sub_I_p .globl p .bss .align 8 .type p, @object .size p, 8 p: .zero 8 .ident "GCC: (GNU) 5.2.1 20151116" .section .note.GNU-stack,"",@progbits Here is what gcc 4.4.5 did: $ gcc -O2 -c -save-temps dynamic-init.cc $ cat dynamic-init.s .file "dynamic-init.cc" .globl p .data .align 8 .type p, @object .size p, 8 p: .quad 4664 .ident "GCC: (GNU) 4.4.5 20101112 (Red Hat 4.4.5-2)" .section .note.GNU-stack,"",@progbits $