unrelenting.technology

Hi! You are viewing the archive of unrelenting.technology. This website is no longer updated, my current one is val.packett.cool. Check it out instead :)

Another weird LLVM mystery solved!

So, I was porting LDC to FreeBSD/aarch64, wondering why global constructors (you know, the before-main() code you can make in C using an __attribute__ thingy) aren’t running… but only when the executable is linked with LLD. Turns out:

  • .init_array is the only supported way to do constructors on AArch64
  • and everything in general is moving towards .init_array β€” but the default in LLVM is still to emit .ctors
  • clang has code to enable .init_array when appropriate, ldc did not
  • and the reason it all worked fine with bfd and gold is that these linkers SILENTLY convert .ctors to .init_array. For PERFORMANCE REASONS.

Published

Updated

Categories and tags

Notes #freebsd #arm #llvm