mold icon indicating copy to clipboard operation
mold copied to clipboard

Mapping input sections to specific output sections

Open christycylee opened this issue 8 months ago • 3 comments

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?

christycylee avatar Apr 02 '25 19:04 christycylee

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?

rui314 avatar Apr 03 '25 00:04 rui314

We have a lot of precompiled code that we cannot annotate.

christycylee avatar Apr 07 '25 16:04 christycylee

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.

christycylee avatar Apr 09 '25 18:04 christycylee