-
|
A.ld A.hpp A.cpp B.cpp I have this implementation on my project using linker script, and I attach the A.ld with the CMAKE option below.
It works well with gcc linker but it doesn't work with lld and mold. Thanks for reading! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You don't need to use a linker script to do what you want to do. Just place all initialization functions to But perhaps you don't even need the above mechanisms. Are you aware of GCC's |
Beta Was this translation helpful? Give feedback.
You don't need to use a linker script to do what you want to do.
Just place all initialization functions to
init_regsection (notice the lack of the leading.), then the linker concatenate input object file'sinit_regsections and create a single "init_reg" section in an output file. You can refer to the beginning and ending of the section with__start_init_regand__stop_init_reglinker-generated symbols, respectively.But perhaps you don't even need the above mechanisms. Are you aware of GCC's
__attribute__((constructor))? With that, you can let the dynamic loader to call arbitrary functions before main.