The -n (--nmagic) and -N (--omagic) options are used in non-paged environments such as embedded systems. They have the following documented
behavior:
--nmagic disables page alignment of OutputSections and disables linking against dynamic libraries.
--omagic is the same as --nmagic but additionally makes the text and data sections to be readable and writeable.
In addition to the documented behavior:
- We don't generate a PT_RELO as there are no pages.
- Unless explicitly instructed to by PHDRS we do not allocate the headers in the first program segment.
- The linkerscript expressions that refer to the max and common page size are unaffected.
fixes pr40542 https://bugs.llvm.org/show_bug.cgi?id=40542
Our previous implementation of -N in D26888 just made the text and data sections to be readable and writeable as this was sufficient for the use-case needed at the time. This change builds upon that to add the remaining behavior from GNU ld.bfd.
Implementation Notes:
I originally thought that this would be as simple as -n = --max-page-size=1, unfortunately we have both MaxPageSize which is configurable and Target->PageSize (often known as common-page-size) that isn't. It could be possible to make Target->PageSize configurable via implementing -z common-page-size, however while looking into GNU ld, it seems like the linkerscript expressions like COMMONPAGESIZE and MAXPAGESIZE are not affected by --nmagic or --omagic.
It is worth mentioning that it is not clear that LLD -n will give sensible results with the builtin layout which assumes paging. In practice using -n will require a linker script. I've tested against the aarch64 linux vdso which uses -n with its own linker script and it does give the required result.
Considered alternatives:
- Implement -z common-page-size (handle Target->PageSize in the way that we handle Config->MaxPageSize) and set both common and max page sizes to 1. This leaves the page calculations untouched but would also affect COMMONPAGESIZE and MAXPAGESIZE and other linker script expressions. This could break some scripts.
- Make specific versions of alignTo and alignDown for page alignment rather than calling them directly and then test for Config->Paged. I rejected this as we would need at least 4 functions to handle the combination of (To, Down) and (PageSize, MaxPageSize).
Should it be here? I think it is the place for the flags that
are named similar to a command line option. Since there is no --paged option,
should it be below, under the following comment?