[ELF][X86-64] Use the correct base address.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 25 Jan 2013 23:23:24 +0000 (23:23 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 25 Jan 2013 23:23:24 +0000 (23:23 +0000)
llvm-svn: 173527

lld/include/lld/ReaderWriter/ELFTargetInfo.h
lld/lib/ReaderWriter/ELF/DefaultELFLayout.h
lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h
lld/test/elf/phdr.objtxt

index 37874c0..237bd4f 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef LLD_READER_WRITER_ELF_TARGET_INFO_H
 #define LLD_READER_WRITER_ELF_TARGET_INFO_H
 
+#include "lld/Core/LinkerOptions.h"
 #include "lld/Core/TargetInfo.h"
 #include "llvm/Object/ELF.h"
 #include "llvm/Support/ELF.h"
@@ -33,6 +34,8 @@ public:
   uint16_t getOutputType() const;
   uint16_t getOutputMachine() const;
 
+  virtual uint64_t getBaseAddress() const { return _options._baseAddress; }
+
   static std::unique_ptr<ELFTargetInfo> create(const LinkerOptions &lo);
 
   template <typename ELFT>
index 86e61ec..fb97a1d 100644 (file)
@@ -518,7 +518,7 @@ DefaultELFLayout<ELFT>::assignVirtualAddress() {
   if (_segments.empty())
     return;
   
-  uint64_t virtualAddress = _targetInfo.getLinkerOptions()._baseAddress;
+  uint64_t virtualAddress = _targetInfo.getBaseAddress();
   
   // HACK: This is a super dirty hack. The elf header and program header are
   // not part of a section, but we need them to be loaded at the base address
index 4410d3b..9098d20 100644 (file)
@@ -30,6 +30,12 @@ public:
 
   virtual uint64_t getPageSize() const { return 0x1000; }
 
+  virtual uint64_t getBaseAddress() const {
+    if (_options._baseAddress == 0)
+      return 0x400000;
+    return _options._baseAddress;
+  }
+
 };
 } // elf
 } // lld
index 79a4e42..1956db3 100644 (file)
@@ -1,4 +1,7 @@
-RUN: lld-core -reader ELF -writer ELF -o %t1 %p/Inputs/phdr.i386 | elf-dump %t1 |  FileCheck -check-prefix=ED %s 
+RUN: lld-core -reader ELF -writer ELF -o %t1 %p/Inputs/phdr.i386 | elf-dump %t1 |  FileCheck -check-prefix=ED %s
+
+RUN: lld -core -target x86_64-linux -output=%t1 %p/Inputs/relocs.x86-64 \
+RUN: && llvm-objdump -p %t1 | FileCheck %s -check-prefix=X86_64
 
 ED:  # Program Header 0
 ED:  (('p_type', 0x00000001)
@@ -40,3 +43,5 @@ ED:   ('p_filesz', 0x0000008c)
 ED:   ('p_memsz', 0x0000008c)
 ED:   ('p_align', 0x00001000)
 ED:  ),
+
+X86_64: vaddr 0x0000000000400000