mold
mold copied to clipboard
Mapping input sections to specific output sections
I'm reading through https://docs.google.com/document/d/1bVRrKsB6iMGmay1odsmS44PyUzPXgQBH83gYGMY6LWM/edit?tab=t.0#heading=h.yyyj057hy9w8, in particular
You can't control how input sections are mapped to output sections. Input sections are mapped to output sections with the same rule as the normal link. I don't think that causes a trouble: for example, if you want to place ".boot" at the beginning of ".text", you can just place ".boot" and ".text" next to each other in the section order list, instead of embedding ".boot" to the beginning of ".text". Sections are not run-time data structures; they exist only in executable files and aren't even mapped to memory at runtime. So no code should care whether a section is in another section or not.
We have use cases where we need to match file paths that match a certain regex, extract the .text / .data sections and map it to a named output section, and lastly reorder those sections. Would you be opposed to a functionality like this?
It depends. If you explicitly annotate your code or data with __attribute__((section("name"))), that's the best way to achieve it rather than defining magical rules to rename sections in an obscure way. That would be not only easier to handle for the linker but also easier to understand for programmers. But I guess there might be a reason to avoid doing that?
We have a lot of precompiled code that we cannot annotate.
We have a monorepo, there's also a use case where we need to compile and link the same code differently based on the target binary.