[lld] r250378 - [ELF2] Set a target-specific VAStart for PPC64
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 15 00:49:08 PDT 2015
Author: hfinkel
Date: Thu Oct 15 02:49:07 2015
New Revision: 250378
URL: http://llvm.org/viewvc/llvm-project?rev=250378&view=rev
Log:
[ELF2] Set a target-specific VAStart for PPC64
After some additional post-commit (post-revert) discussion and research, this
reverts, in part, r250205, so the ABI-recommended starting address can be used
on PPC64 (as is done by other linkers).
Also, this addresses the FIXME in ELF/Writer.cpp by making VAStart a
target-dependent property.
Modified:
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Target.h
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/basic64be.s
lld/trunk/test/elf2/emulation.s
lld/trunk/test/elf2/ppc64-rel-calls.s
lld/trunk/test/elf2/ppc64-relocs.s
lld/trunk/test/elf2/ppc64-toc-restore.s
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Oct 15 02:49:07 2015
@@ -346,6 +346,16 @@ PPC64TargetInfo::PPC64TargetInfo() {
// We need 64K pages (at least under glibc/Linux, the loader won't
// set different permissions on a finer granularity than that).
PageSize = 65536;
+
+ // The PPC64 ELF ABI v1 spec, says:
+ //
+ // It is normally desirable to put segments with different characteristics
+ // in separate 256 Mbyte portions of the address space, to give the
+ // operating system full paging flexibility in the 64-bit address space.
+ //
+ // And because the lowest non-zero 256M boundary is 0x10000000, PPC64 linkers
+ // use 0x10000000 as the starting address.
+ VAStart = 0x10000000;
}
static uint64_t getPPC64TocBase() {
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Oct 15 02:49:07 2015
@@ -21,6 +21,7 @@ class SymbolBody;
class TargetInfo {
public:
unsigned getPageSize() const { return PageSize; }
+ uint64_t getVAStart() const { return VAStart; }
unsigned getPCRelReloc() const { return PCRelReloc; }
unsigned getGotReloc() const { return GotReloc; }
unsigned getGotRefReloc() const { return GotRefReloc; }
@@ -41,6 +42,15 @@ public:
protected:
unsigned PageSize = 4096;
+
+ // On freebsd x86_64 the first page cannot be mmaped.
+ // On linux that is controled by vm.mmap_min_addr. At least on some x86_64
+ // installs that is 65536, so the first 15 pages cannot be used.
+ // 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 VAStart = 0x10000;
+
unsigned PCRelReloc;
unsigned GotRefReloc;
unsigned GotReloc;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 15 02:49:07 2015
@@ -24,15 +24,6 @@ using namespace llvm::object;
using namespace lld;
using namespace lld::elf2;
-// On freebsd x86_64 the first page cannot be mmaped.
-// On linux that is controled by vm.mmap_min_addr. At least on some x86_64
-// installs that is 65536, so the first 15 pages cannot be used.
-// 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.
-// FIXME: This is architecture and OS dependent.
-static const int VAStart = 0x10000;
-
namespace {
static uint32_t toPhdrFlags(uint64_t Flags) {
@@ -74,7 +65,7 @@ private:
bool isOutputDynamic() const {
return !Symtab.getSharedFiles().empty() || Config->Shared;
}
- uintX_t getVAStart() const { return Config->Shared ? 0 : VAStart; }
+ uintX_t getVAStart() const { return Config->Shared ? 0 : Target->getVAStart(); }
std::unique_ptr<llvm::FileOutputBuffer> Buffer;
Modified: lld/trunk/test/elf2/basic64be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic64be.s (original)
+++ lld/trunk/test/elf2/basic64be.s Thu Oct 15 02:49:07 2015
@@ -36,7 +36,7 @@ _start:
# CHECK-NEXT: Type: Executable (0x2)
# CHECK-NEXT: Machine: EM_PPC64 (0x15)
# CHECK-NEXT: Version: 1
-# CHECK-NEXT: Entry: 0x30040
+# CHECK-NEXT: Entry: 0x10020040
# CHECK-NEXT: ProgramHeaderOffset: 0x40
# CHECK-NEXT: SectionHeaderOffset: 0x200C8
# CHECK-NEXT: Flags [ (0x0)
@@ -73,7 +73,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_EXECINSTR (0x4)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address:
+# CHECK-NEXT: Address: 0x10010000
# CHECK-NEXT: Offset: 0x10000
# CHECK-NEXT: Size: 12
# CHECK-NEXT: Link: 0
@@ -91,7 +91,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000C
+# CHECK-NEXT: Address: 0x1001000C
# CHECK-NEXT: Offset: 0x1000C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
@@ -109,7 +109,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x30000
+# CHECK-NEXT: Address: 0x10020000
# CHECK-NEXT: Offset: 0x20000
# CHECK-NEXT: Size: 32
# CHECK-NEXT: Link: 0
@@ -129,7 +129,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x30020
+# CHECK-NEXT: Address: 0x10020020
# CHECK-NEXT: Offset: 0x20020
# CHECK-NEXT: Size: 32
# CHECK-NEXT: Link: 0
@@ -149,7 +149,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x30040
+# CHECK-NEXT: Address: 0x10020040
# CHECK-NEXT: Offset: 0x20040
# CHECK-NEXT: Size: 24
# CHECK-NEXT: Link: 0
@@ -157,7 +157,7 @@ _start:
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 0
# CHECK-NEXT: SectionData (
-# CHECK-NEXT: 0000: 00000000 00020000 00000000 00008000 |................|
+# CHECK-NEXT: 0000: 00000000 10010000 00000000 00008000 |................|
# CHECK-NEXT: 0010: 00000000 00000000 |........|
# CHECK-NEXT: )
# CHECK-NEXT: }
@@ -169,7 +169,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x30058
+# CHECK-NEXT: Address: 0x10020058
# CHECK-NEXT: Offset: 0x20058
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
@@ -214,8 +214,8 @@ _start:
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_PHDR (0x6)
# CHECK-NEXT: Offset: 0x40
-# CHECK-NEXT: VirtualAddress: 0x10040
-# CHECK-NEXT: PhysicalAddress: 0x10040
+# CHECK-NEXT: VirtualAddress: 0x10000040
+# CHECK-NEXT: PhysicalAddress: 0x10000040
# CHECK-NEXT: FileSize: 224
# CHECK-NEXT: MemSize: 224
# CHECK-NEXT: Flags [ (0x4)
@@ -226,8 +226,8 @@ _start:
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
-# CHECK-NEXT: VirtualAddress: 0x10000
-# CHECK-NEXT: PhysicalAddress: 0x10000
+# CHECK-NEXT: VirtualAddress: 0x10000000
+# CHECK-NEXT: PhysicalAddress: 0x10000000
# CHECK-NEXT: FileSize: 288
# CHECK-NEXT: MemSize: 288
# CHECK-NEXT: Flags [
@@ -238,8 +238,8 @@ _start:
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x1000
-# CHECK-NEXT: VirtualAddress: 0x20000
-# CHECK-NEXT: PhysicalAddress: 0x20000
+# CHECK-NEXT: VirtualAddress: 0x10010000
+# CHECK-NEXT: PhysicalAddress: 0x10010000
# CHECK-NEXT: FileSize: 12
# CHECK-NEXT: MemSize: 12
# CHECK-NEXT: Flags [ (0x5)
@@ -251,8 +251,8 @@ _start:
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x2000
-# CHECK-NEXT: VirtualAddress: 0x30000
-# CHECK-NEXT: PhysicalAddress: 0x30000
+# CHECK-NEXT: VirtualAddress: 0x10020000
+# CHECK-NEXT: PhysicalAddress: 0x10020000
# CHECK-NEXT: FileSize: 88
# CHECK-NEXT: MemSize: 88
# CHECK-NEXT: Flags [ (0x6)
Modified: lld/trunk/test/elf2/emulation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/emulation.s?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/test/elf2/emulation.s (original)
+++ lld/trunk/test/elf2/emulation.s Thu Oct 15 02:49:07 2015
@@ -78,7 +78,7 @@
# PPC64-NEXT: Type: Executable (0x2)
# PPC64-NEXT: Machine: EM_PPC64 (0x15)
# PPC64-NEXT: Version: 1
-# PPC64-NEXT: Entry: 0x100B0
+# PPC64-NEXT: Entry: 0x100000B0
# PPC64-NEXT: ProgramHeaderOffset: 0x40
# PPC64-NEXT: SectionHeaderOffset: 0x110
# PPC64-NEXT: Flags [ (0x0)
Modified: lld/trunk/test/elf2/ppc64-rel-calls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-rel-calls.s?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-rel-calls.s (original)
+++ lld/trunk/test/elf2/ppc64-rel-calls.s Thu Oct 15 02:49:07 2015
@@ -16,9 +16,9 @@ _start:
li 3,42
sc
-# CHECK: 20000: 38 00 00 01 li 0, 1
-# CHECK: 20004: 38 60 00 2a li 3, 42
-# CHECK: 20008: 44 00 00 02 sc
+# CHECK: 10010000: 38 00 00 01 li 0, 1
+# CHECK: 10010004: 38 60 00 2a li 3, 42
+# CHECK: 10010008: 44 00 00 02 sc
.section ".opd","aw"
.global bar
@@ -34,9 +34,9 @@ bar:
blr
# FIXME: The printing here is misleading, the branch offset here is negative.
-# CHECK: 2000c: 4b ff ff f5 bl .+67108852
-# CHECK: 20010: 60 00 00 00 nop
-# CHECK: 20014: 4b ff ff ed bl .+67108844
-# CHECK: 20018: 60 00 00 00 nop
-# CHECK: 2001c: 4e 80 00 20 blr
+# CHECK: 1001000c: 4b ff ff f5 bl .+67108852
+# CHECK: 10010010: 60 00 00 00 nop
+# CHECK: 10010014: 4b ff ff ed bl .+67108844
+# CHECK: 10010018: 60 00 00 00 nop
+# CHECK: 1001001c: 4e 80 00 20 blr
Modified: lld/trunk/test/elf2/ppc64-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-relocs.s?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-relocs.s (original)
+++ lld/trunk/test/elf2/ppc64-relocs.s Thu Oct 15 02:49:07 2015
@@ -25,7 +25,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_TOC16_LO_DS:
# CHECK: .FR_PPC64_TOC16_LO_DS:
-# CHECK: 2000c: e8 22 80 00 ld 1, -32768(2)
+# CHECK: 1001000c: e8 22 80 00 ld 1, -32768(2)
.section .R_PPC64_TOC16_LO,"ax", at progbits
.globl .FR_PPC64_TOC16_LO
@@ -34,7 +34,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_TOC16_LO:
# CHECK: .FR_PPC64_TOC16_LO:
-# CHECK: 20010: 38 22 80 00 addi 1, 2, -32768
+# CHECK: 10010010: 38 22 80 00 addi 1, 2, -32768
.section .R_PPC64_TOC16_HI,"ax", at progbits
.globl .FR_PPC64_TOC16_HI
@@ -43,7 +43,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_TOC16_HI:
# CHECK: .FR_PPC64_TOC16_HI:
-# CHECK: 20014: 3c 22 00 02 addis 1, 2, 2
+# CHECK: 10010014: 3c 22 10 01 addis 1, 2, 4097
.section .R_PPC64_TOC16_HA,"ax", at progbits
.globl .FR_PPC64_TOC16_HA
@@ -52,7 +52,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_TOC16_HA:
# CHECK: .FR_PPC64_TOC16_HA:
-# CHECK: 20018: 3c 22 00 03 addis 1, 2, 3
+# CHECK: 10010018: 3c 22 10 02 addis 1, 2, 4098
.section .R_PPC64_REL24,"ax", at progbits
.globl .FR_PPC64_REL24
@@ -63,7 +63,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_REL24:
# CHECK: .FR_PPC64_REL24:
-# CHECK: 2001c: 48 00 00 04 b .+4
+# CHECK: 1001001c: 48 00 00 04 b .+4
.section .R_PPC64_ADDR16_LO,"ax", at progbits
.globl .FR_PPC64_ADDR16_LO
@@ -72,7 +72,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_LO:
# CHECK: .FR_PPC64_ADDR16_LO:
-# CHECK: 20020: 38 20 00 00 li 1, 0
+# CHECK: 10010020: 38 20 00 00 li 1, 0
.section .R_PPC64_ADDR16_HI,"ax", at progbits
.globl .FR_PPC64_ADDR16_HI
@@ -81,7 +81,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HI:
# CHECK: .FR_PPC64_ADDR16_HI:
-# CHECK: 20024: 38 20 00 02 li 1, 2
+# CHECK: 10010024: 38 20 10 01 li 1, 4097
.section .R_PPC64_ADDR16_HA,"ax", at progbits
.globl .FR_PPC64_ADDR16_HA
@@ -90,7 +90,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HA:
# CHECK: .FR_PPC64_ADDR16_HA:
-# CHECK: 20028: 38 20 00 02 li 1, 2
+# CHECK: 10010028: 38 20 10 01 li 1, 4097
.section .R_PPC64_ADDR16_HIGHER,"ax", at progbits
.globl .FR_PPC64_ADDR16_HIGHER
@@ -99,7 +99,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHER:
# CHECK: .FR_PPC64_ADDR16_HIGHER:
-# CHECK: 2002c: 38 20 00 00 li 1, 0
+# CHECK: 1001002c: 38 20 00 00 li 1, 0
.section .R_PPC64_ADDR16_HIGHERA,"ax", at progbits
.globl .FR_PPC64_ADDR16_HIGHERA
@@ -108,7 +108,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHERA:
# CHECK: .FR_PPC64_ADDR16_HIGHERA:
-# CHECK: 20030: 38 20 00 00 li 1, 0
+# CHECK: 10010030: 38 20 00 00 li 1, 0
.section .R_PPC64_ADDR16_HIGHEST,"ax", at progbits
.globl .FR_PPC64_ADDR16_HIGHEST
@@ -117,7 +117,7 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHEST:
# CHECK: .FR_PPC64_ADDR16_HIGHEST:
-# CHECK: 20034: 38 20 00 00 li 1, 0
+# CHECK: 10010034: 38 20 00 00 li 1, 0
.section .R_PPC64_ADDR16_HIGHESTA,"ax", at progbits
.globl .FR_PPC64_ADDR16_HIGHESTA
@@ -126,5 +126,5 @@ _start:
# CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHESTA:
# CHECK: .FR_PPC64_ADDR16_HIGHESTA:
-# CHECK: 20038: 38 20 00 00 li 1, 0
+# CHECK: 10010038: 38 20 00 00 li 1, 0
Modified: lld/trunk/test/elf2/ppc64-toc-restore.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-toc-restore.s?rev=250378&r1=250377&r2=250378&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-toc-restore.s (original)
+++ lld/trunk/test/elf2/ppc64-toc-restore.s Thu Oct 15 02:49:07 2015
@@ -13,9 +13,9 @@ _start:
nop
// CHECK: _start:
-// CHECK: 20000: 48 00 00 21 bl .+32
-// CHECK-NOT: 20004: 60 00 00 00 nop
-// CHECK: 20004: e8 41 00 28 ld 2, 40(1)
+// CHECK: 10010000: 48 00 00 21 bl .+32
+// CHECK-NOT: 10010004: 60 00 00 00 nop
+// CHECK: 10010004: e8 41 00 28 ld 2, 40(1)
.global noret
noret:
@@ -23,22 +23,22 @@ noret:
li 5, 7
// CHECK: noret:
-// CHECK: 20008: 48 00 00 19 bl .+24
-// CHECK: 2000c: 38 a0 00 07 li 5, 7
+// CHECK: 10010008: 48 00 00 19 bl .+24
+// CHECK: 1001000c: 38 a0 00 07 li 5, 7
.global noretend
noretend:
bl bar
// CHECK: noretend:
-// CHECK: 20010: 48 00 00 11 bl .+16
+// CHECK: 10010010: 48 00 00 11 bl .+16
.global noretb
noretb:
b bar
// CHECK: noretb:
-// CHECK: 20014: 48 00 00 0c b .+12
+// CHECK: 10010014: 48 00 00 0c b .+12
// This should come last to check the end-of-buffer condition.
.global last
@@ -47,16 +47,16 @@ last:
nop
// CHECK: last:
-// CHECK: 20018: 48 00 00 09 bl .+8
-// CHECK: 2001c: e8 41 00 28 ld 2, 40(1)
+// CHECK: 10010018: 48 00 00 09 bl .+8
+// CHECK: 1001001c: e8 41 00 28 ld 2, 40(1)
// CHECK: Disassembly of section .plt:
// CHECK: .plt:
-// CHECK: 20020: f8 41 00 28 std 2, 40(1)
-// CHECK: 20024: 3d 62 00 00 addis 11, 2, 0
-// CHECK: 20028: e9 8b 80 00 ld 12, -32768(11)
-// CHECK: 2002c: e9 6c 00 00 ld 11, 0(12)
-// CHECK: 20030: 7d 69 03 a6 mtctr 11
-// CHECK: 20034: e8 4c 00 08 ld 2, 8(12)
-// CHECK: 20038: e9 6c 00 10 ld 11, 16(12)
-// CHECK: 2003c: 4e 80 04 20 bctr
+// CHECK: 10010020: f8 41 00 28 std 2, 40(1)
+// CHECK: 10010024: 3d 62 00 00 addis 11, 2, 0
+// CHECK: 10010028: e9 8b 80 00 ld 12, -32768(11)
+// CHECK: 1001002c: e9 6c 00 00 ld 11, 0(12)
+// CHECK: 10010030: 7d 69 03 a6 mtctr 11
+// CHECK: 10010034: e8 4c 00 08 ld 2, 8(12)
+// CHECK: 10010038: e9 6c 00 10 ld 11, 16(12)
+// CHECK: 1001003c: 4e 80 04 20 bctr
More information about the llvm-commits
mailing list