On Thu, Oct 28, 2021 at 1:26 PM Rasmus Villemoes <r...@rasmusvillemoes.dk> wrote: > > Hi > > I was wondering why the vx_crtbegin.o file had a .init_array section and > not a .init_array.00101, when the function is defined with > __attribute__((constructor (101))) (see libgcc/config/vxcrtstuff.c). > > After a lot of digging, including making sure that EH_CTOR_ATTRIBUTE > actually gets defined as I expect and adding -frecord-gcc-switches to > the build to see if any of those made ctor priorities ignored, it turns > out that the problem is the declarations preceding the definitions. This > can easily be reproduced by > > #define ac(prio) __attribute__((constructor(prio))) > > unsigned x = 987; > > static void f101(void); > void f102(void); > > static void ac(101) f101(void) { x += 101; } > void ac(102) f102(void) { x *= 102; } > > static void ac(103) f103(void) { x -= 103; } > void ac(104) f104(void) { x /= 104; } > > This results in a .init_array section with two pointers, plus the > expected .init_array.00103 and .init_array.00104 with one each. > > This is rather unexpected, especially since the attribute is not > entirely ignored, just the priority part.
Probably a bug in decl merging, failing to copy DECL_HAS_INIT_PRIORITY_P and altering the on-the-side init priority mapping (decl_{init,fini}_priority_insert). I suggest to file a bugreport or try to fix it yourself (gcc/c/c-decl.c:merge_decls) Richard. > > Rasmus