lld: 2MB- or 4MB-aligned .text
Ed Maste via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 22 11:25:27 PST 2016
On x86-64 it's beneficial to align the text segment it to 2MB, then
the FreeBSD kernel can automatically promote the mapping to a 2MB
superpage. On most architectures both GNU ld and gold put the text
segment at 0x400000 so this can happen, while lld defaults to 0x10000.
I'm guessing that the GNU linker developers ended up with 4MB as the
lowest common multiple of large page sizes on common platforms and
just used the same value in all of those cases, although AFAICT 2MB
would be just as good on x86-64. In typical GNU changelog style the
description for the change that increased it to 4MB (from 4K
previously) is:
* elf_x86_64.sh (NONPAGED_TEXT_START_ADDR): Increase.
(TEXT_START_ADDR): Likewise.
Is there a reason we shouldn't start the text segment at 0x400000 as well?
--- a/ELF/Target.h
+++ b/ELF/Target.h
@@ -70,7 +70,7 @@ public:
// Given that, the smallest value that can be used in here is 0x10000.
// If using 2MB pages, the smallest page aligned address that works is
// 0x200000, but it looks like every OS uses 4k pages for executables.
- uint64_t DefaultImageBase = 0x10000;
+ uint64_t DefaultImageBase = 0x400000;
uint32_t CopyRel;
uint32_t GotRel;
More information about the llvm-commits
mailing list