[lld] [lld/ELF] Add --override-section-flags flag (PR #109454)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 03:31:47 PDT 2024


smithp35 wrote:

My initial reaction is that this seems like a low-level solution that could work, but could interact in unforeseen ways with other features as it could break some assumptions that some sections have particular flags. This may be resolvable with a tighter specification of what the option does and any restriction on what it applies to. For example can the section have dynamic relocations like .data.rel.ro if writeable is removed? My intuition is that this might be worth a RFC to see if there are alternative solutions that are perhaps a bit more specific.

To make sure I understand, the desire is to have an area of the program that is mapped read-only by the dynamic-linker, ideally aligned on page boundaries. The application, presumably using some kind of linker generated `_start` and `_stop` will dynamically alter the permission to write to the section.

This is kind of like .data.rel.ro which is writeable at static link time, but the dynamic loader marks read-only post dynamic relocation. This sounds like it is almost exactly what you want, with the exception that you probably don't want to make the genuinely RELRO sections temporarily writeable. Perhaps there's a way of making this work by using .data.rel.ro? For example if there were a page aligned sub-section of .data.rel.ro? The dynamic linker would make the RELRO segment read-only. Could the application temporarily map the sub-section of .data.rel.ro as read-write.

If we want to pursue the option I'd like to know (in the description) what the semantics of the option are. For example:
* Does it behave like the linker script (NOLOAD) so the linker just give the output section the flags regardless of what the input section flags are.
* What flags are supported by the option, and what ELF flags do they map to?
* If you support overwrite, what about modify? For example can I add or subtract individual flags? I'm thinking of someone that has processor/OS specific flags that may not be representable by the option, or at least cumbersome to represent in it.
* How does it interact with a PHDRS command that changes the flags like your example above?
* How does it interact with conventions like .data.rel.ro, if the flags are overridden does that section cease to be RELRO?
* What happens if there are clashes like read-only SHT-NOBITS?
* If a section is marked read-only should the linker forbid dynamic relocations? I would expect so.

https://github.com/llvm/llvm-project/pull/109454


More information about the llvm-commits mailing list