diff options
| author | Peter Smith <peter.smith@linaro.org> | 2019-05-13 16:01:26 +0000 |
|---|---|---|
| committer | Peter Smith <peter.smith@linaro.org> | 2019-05-13 16:01:26 +0000 |
| commit | 4e21c770ec328bf03fac6f729602a744b7ef4bca (patch) | |
| tree | aecd2d104a296a3c5856cec4dc2a681db7e13a46 /lld/ELF/Writer.cpp | |
| parent | d3cedee3c609270335f82400999b4fa6ffb2e441 (diff) | |
| download | bcm5719-llvm-4e21c770ec328bf03fac6f729602a744b7ef4bca.tar.gz bcm5719-llvm-4e21c770ec328bf03fac6f729602a744b7ef4bca.zip | |
[ELF] Full support for -n (--nmagic) and -N (--omagic) via common page
The -n (--nmagic) disables page alignment, and acts as a -Bstatic
The -N (--omagic) does what -n does but also marks the executable segment as
writeable. As page alignment is disabled headers are not allocated unless
explicit in the linker script.
To disable page alignment in LLD we choose to set the page sizes to 1 so
that any alignment based on the page size does nothing. To set the
Target->PageSize to 1 we implement -z common-page-size, which has the side
effect of allowing the user to set the value as well.
Setting the page alignments to 1 does mean that any use of
CONSTANT(MAXPAGESIZE) or CONSTANT(COMMONPAGESIZE) in a linker script will
return 1, unlike in ld.bfd. However given that -n and -N disable paging
these probably shouldn't be used in a linker script where -n or -N is in
use.
Differential Revision: https://reviews.llvm.org/D61688
llvm-svn: 360593
Diffstat (limited to 'lld/ELF/Writer.cpp')
| -rw-r--r-- | lld/ELF/Writer.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 1ca359e0443..0678f73a387 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2132,7 +2132,7 @@ template <class ELFT> void Writer<ELFT>::assignFileOffsets() { // segment is the last loadable segment, align the offset of the // following section to avoid loading non-segments parts of the file. if (LastRX && LastRX->LastSec == Sec) - Off = alignTo(Off, Target->PageSize); + Off = alignTo(Off, Config->CommonPageSize); } SectionHeaderOff = alignTo(Off, Config->Wordsize); @@ -2184,7 +2184,7 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() { // The glibc dynamic loader rounds the size down, so we need to round up // to protect the last page. This is a no-op on FreeBSD which always // rounds up. - P->p_memsz = alignTo(P->p_memsz, Target->PageSize); + P->p_memsz = alignTo(P->p_memsz, Config->CommonPageSize); } if (P->p_type == PT_TLS && P->p_memsz) { @@ -2477,10 +2477,10 @@ template <class ELFT> void Writer<ELFT>::writeTrapInstr() { // Fill the last page. for (PhdrEntry *P : Phdrs) if (P->p_type == PT_LOAD && (P->p_flags & PF_X)) - fillTrap(Out::BufferStart + - alignDown(P->p_offset + P->p_filesz, Target->PageSize), + fillTrap(Out::BufferStart + alignDown(P->p_offset + P->p_filesz, + Config->CommonPageSize), Out::BufferStart + - alignTo(P->p_offset + P->p_filesz, Target->PageSize)); + alignTo(P->p_offset + P->p_filesz, Config->CommonPageSize)); // Round up the file size of the last segment to the page boundary iff it is // an executable segment to ensure that other tools don't accidentally @@ -2491,7 +2491,8 @@ template <class ELFT> void Writer<ELFT>::writeTrapInstr() { Last = P; if (Last && (Last->p_flags & PF_X)) - Last->p_memsz = Last->p_filesz = alignTo(Last->p_filesz, Target->PageSize); + Last->p_memsz = Last->p_filesz = + alignTo(Last->p_filesz, Config->CommonPageSize); } // Write section contents to a mmap'ed file. |

