Skip to contentSkip to conversation

x86: also discard .fini_array in linker script

PATCH In review Jan Beulich 2 participants 4 messages Mar 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: also discard .fini_array in linker script

This simply parallels .dtors. Both section types can reference .text.exit, which requires them to be discarded together with that one. Compilers, depending on their findings during the configure phase, may elect to use either model. While .{init,fini}_array look to be preferred, cross compilers apparently have this guessed, likely resulting in a fallback to .{c,d}tors. Hence we need to support both sets.

Fixes 4b7fd8153ddf ("x86: fold sections in final binaries")

---
As mentioned elsewhere, I don't think init_constructors() is correct for the .ctors variant. But that's a separate issue.

xen/arch/x86/xen.lds.S +2 -0
@@ -415,6 +415,8 @@ SECTIONS
        *(.eh_frame)
        *(.dtors)
        *(.dtors.*)
+       *(.fini_array)
+       *(.fini_array.*)
 #ifdef EFI
        *(.comment)
        *(.comment.*)
#1 lore raw
Quoted 7 lines · Jan Beulich

This simply parallels .dtors. Both section types can reference .text.exit, which requires them to be discarded together with that one. Compilers, depending on their findings during the configure phase, may elect to use either model. While .{init,fini}_array look to be preferred, cross compilers apparently have this guessed, likely resulting in a fallback to .{c,d}tors. Hence we need to support both sets.

Do we also need to consider discarding .fini? Or that's guaranteed to not be used by the compiler?

Thanks, Roger.

#2 lore raw
Quoted 11 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

This simply parallels .dtors. Both section types can reference .text.exit, which requires them to be discarded together with that one. Compilers, depending on their findings during the configure phase, may elect to use either model. While .{init,fini}_array look to be preferred, cross compilers apparently have this guessed, likely resulting in a fallback to .{c,d}tors. Hence we need to support both sets.

Do we also need to consider discarding .fini? Or that's guaranteed to not be used by the compiler?

I'm not aware of it being used anymore; if it was used, we'd also need to deal with .init (which - logically, but not technically - would conflict with our own section of this same name in xen.efi).

Jan

Reviewed-by
#3 lore raw
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

This simply parallels .dtors. Both section types can reference .text.exit, which requires them to be discarded together with that one. Compilers, depending on their findings during the configure phase, may elect to use either model. While .{init,fini}_array look to be preferred, cross compilers apparently have this guessed, likely resulting in a fallback to .{c,d}tors. Hence we need to support both sets.

Quoted 6 lines
Quoted 2 lines

Do we also need to consider discarding .fini? Or that's guaranteed to not be used by the compiler?

I'm not aware of it being used anymore; if it was used, we'd also need to deal with .init (which - logically, but not technically - would conflict with our own section of this same name in xen.efi).

We would realize if having the orphaned check (or like here would get missing references.

Thanks, Roger.