[PATCH] D45508: Implement --ctors-in-init-array.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 13:24:17 PST 2023


MaskRay added a comment.

In D45508#4136044 <https://reviews.llvm.org/D45508#4136044>, @skirkovski wrote:

>> I think you misunderstand things. GCC 4.7 switched from .ctors to .init_array . At the current GCC 12 time .ctors is very obsoleted now.
>
> I don't think I am. I was debugging this issue today. I had some binaries and libraries built and linked with gcc9, now while transitioning to gcc12 I can clearly see that that .ctors from those libraries are present but are not executed when the resulting binary is linked with lld, only .init_array.
>
> But sure whatever, I really didn't expect anything else with (atleast) 3 attempts to fix this upstream.

You might build a GCC by yourself, instead of using a distro-provided one. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100896

If you want GCC's `.ctors` work without `.ctors`=>`.init_array` conversion, you can patch GCC `libgcc/crtstuff.c` to always support `.ctors`.
Alternatively, search `objcopy` on https://maskray.me/blog/2021-11-07-init-ctors-init-array (just updated).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D45508/new/

https://reviews.llvm.org/D45508



More information about the llvm-commits mailing list