LD: Cannot add content to ctors section

Ben Hirschberg bhirschb@cyberarmor.io
Wed May 20 12:50:28 GMT 2020


It is not working, because Alpine container images are using musl-libc. The dynamic loader in musl doesn't call the functions in ".init_array", it delegates this requirement to C runtime (crt0.o). It works in case of Alpine executable which was linked against musl's crt0, because musl's crt0 calls ".init_array" functions.

In my project I have a shared object which is loaded into a Go application. Go application does not use crt0.o and does not call ".init_array" functions. They say that it is ok, because this is the responsibility of the dynamic loader. (see this discussion if you're interested https://github.com/golang/go/issues/28909)

I want to do a workaround this issue and put my static constructors into ".ctros" section because it is supported across the board.



-----Original Message-----
From: H.J. Lu <hjl.tools@gmail.com>
Sent: Wednesday, May 20, 2020 3:12 PM
To: Ben Hirschberg <bhirschb@cyberarmor.io>
Cc: binutils@sourceware.org
Subject: Re: LD: Cannot add content to ctors section

On Wed, May 20, 2020 at 4:52 AM Ben Hirschberg <bhirschb@cyberarmor.io> wrote:
>
> Yeah, well, if life was so easy...
>
> The original solution was using C with attribute constructor. It it is not working in this scenario because it adds the function to the ".init_array" section and not the ".ctors".
>

Why didn't .init_array work?

--
H.J.
The content of this email is confidential and intended for the recipient specified in message only. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.


More information about the Binutils mailing list