LD: Cannot add content to ctors section

Fangrui Song i@maskray.me
Thu May 21 06:12:30 GMT 2020


On Wed, May 20, 2020 at 9:57 PM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> On Wed, May 20, 2020 at 09:15:42AM +0000, Ben Hirschberg wrote:
> > Hi!
> >
> > I have a setup (Alpine Linux with Go executables) where I cannot rely on contents of ".init_array" to be called, but ".ctors" are called by musl-libc's loader.
> >
> > I am trying to add my constructors (C or ASM) to the ".ctors" section, but after linking my shared object they seem to be moved to ".init_array" (however in Alpine the ".ctors" section stays in the final image but it is empty)
> >
> > Why is this happening? Can make my array stay in ".ctors" section?
>
> There is a binutils configure option --disable-initfini-array that may
> help in building a linker that should not map .ctors to .init_array.
> Whether this all still works is another question.
>
> --
> Alan Modra
> Australia Development Lab, IBM

musl has supported DT_INIT_ARRAY since 2013
https://git.musl-libc.org/cgit/musl/commit/?id=e69ae844dcc978f68761e4bc44fc5543717b9684
Only on arm and aarch64 DT_INIT is disabled.

In gold, the feature is provided by an enabled-by-default option
--ctors-in-init-array


More information about the Binutils mailing list