LD: Cannot add content to ctors section

H.J. Lu hjl.tools@gmail.com
Wed May 20 11:45:26 GMT 2020


On Wed, May 20, 2020 at 2:40 AM Ben Hirschberg <bhirschb@cyberarmor.io> 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?
>
> Thanks
> Ben
>
> Here is my ASM code:
>
>        .intel_syntax noprefix
>        .text
>
>        .section      .rodata
> .Message:
>        .string "Constructor called!"
>
>        .text
> Constructor:
>        lea    rdi, .Message[rip]
>        jmp    puts@PLT
>
>        .section      .ctors,"a"
> __CTOR_LIST__:
>        .quad  Constructor
>

Do it in C with constructor attribute.

-- 
H.J.


More information about the Binutils mailing list