[lld] r200511 - [PECOFF] Default image base address for PE32+ is 0x140000000, not 0x400000.

Rui Ueyama ruiu at google.com
Thu Jan 30 20:49:14 PST 2014


Author: ruiu
Date: Thu Jan 30 22:49:13 2014
New Revision: 200511

URL: http://llvm.org/viewvc/llvm-project?rev=200511&view=rev
Log:
[PECOFF] Default image base address for PE32+ is 0x140000000, not 0x400000.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
    lld/trunk/test/pecoff/pe32plus.test

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=200511&r1=200510&r2=200511&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Thu Jan 30 22:49:13 2014
@@ -35,9 +35,9 @@ class Group;
 class PECOFFLinkingContext : public LinkingContext {
 public:
   PECOFFLinkingContext()
-      : _baseAddress(0x400000), _stackReserve(1024 * 1024), _stackCommit(4096),
-        _heapReserve(1024 * 1024), _heapCommit(4096), _noDefaultLibAll(false),
-        _sectionDefaultAlignment(4096),
+      : _baseAddress(invalidBaseAddress), _stackReserve(1024 * 1024),
+        _stackCommit(4096), _heapReserve(1024 * 1024), _heapCommit(4096),
+        _noDefaultLibAll(false), _sectionDefaultAlignment(4096),
         _subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN),
         _machineType(llvm::COFF::IMAGE_FILE_MACHINE_I386), _imageVersion(0, 0),
         _minOSVersion(6, 0), _nxCompat(true), _largeAddressAware(false),
@@ -108,7 +108,7 @@ public:
   }
 
   void setBaseAddress(uint64_t addr) { _baseAddress = addr; }
-  uint64_t getBaseAddress() const { return _baseAddress; }
+  uint64_t getBaseAddress() const;
 
   void setStackReserve(uint64_t size) { _stackReserve = size; }
   void setStackCommit(uint64_t size) { _stackCommit = size; }
@@ -250,6 +250,8 @@ protected:
   virtual std::unique_ptr<File> createUndefinedSymbolFile() const;
 
 private:
+  enum { invalidBaseAddress = UINT64_MAX };
+
   // The start address for the program. The default value for the executable is
   // 0x400000, but can be altered using /base command line option.
   uint64_t _baseAddress;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=200511&r1=200510&r2=200511&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Jan 30 22:49:13 2014
@@ -48,9 +48,9 @@ bool PECOFFLinkingContext::validateImpl(
   }
 
   // It's an error if the base address is not multiple of 64K.
-  if (_baseAddress & 0xffff) {
+  if (getBaseAddress() & 0xffff) {
     diagnostics << "Base address have to be multiple of 64K, but got "
-                << _baseAddress << "\n";
+                << getBaseAddress() << "\n";
     return false;
   }
 
@@ -201,8 +201,13 @@ StringRef PECOFFLinkingContext::undecora
   return name.substr(1);
 }
 
-Writer &PECOFFLinkingContext::writer() const { return *_writer; }
+uint64_t PECOFFLinkingContext::getBaseAddress() const {
+  if (_baseAddress == invalidBaseAddress)
+    return is64Bit() ? 0x140000000UL : 0x400000UL;
+  return _baseAddress;
+}
 
+Writer &PECOFFLinkingContext::writer() const { return *_writer; }
 
 void PECOFFLinkingContext::setSectionSetMask(StringRef sectionName,
                                              uint32_t newFlags) {

Modified: lld/trunk/test/pecoff/pe32plus.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/pe32plus.test?rev=200511&r1=200510&r2=200511&view=diff
==============================================================================
--- lld/trunk/test/pecoff/pe32plus.test (original)
+++ lld/trunk/test/pecoff/pe32plus.test Thu Jan 30 22:49:13 2014
@@ -27,7 +27,7 @@ CHECK-NEXT:   SizeOfInitializedData: 108
 CHECK-NEXT:   SizeOfUninitializedData: 0
 CHECK-NEXT:   AddressOfEntryPoint: 0x2000
 CHECK-NEXT:   BaseOfCode: 0x2000
-CHECK-NEXT:   ImageBase: 0x400000
+CHECK-NEXT:   ImageBase: 0x140000000
 CHECK-NEXT:   SectionAlignment: 4096
 CHECK-NEXT:   FileAlignment: 512
 CHECK-NEXT:   MajorOperatingSystemVersion: 6





More information about the llvm-commits mailing list