Skip to content

How can I attach ld file with lld or mold? #1070

Answered by rui314
bossjisu asked this question in Q&A
Discussion options

You must be logged in to vote

You don't need to use a linker script to do what you want to do.

Just place all initialization functions to init_reg section (notice the lack of the leading .), then the linker concatenate input object file's init_reg sections 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_reg and __stop_init_reg linker-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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bossjisu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants