[lld] r218106 - PECOFF: loosen another assumption of x86 only

Saleem Abdulrasool compnerd at compnerd.org
Thu Sep 18 23:09:34 PDT 2014


Author: compnerd
Date: Fri Sep 19 01:09:33 2014
New Revision: 218106

URL: http://llvm.org/viewvc/llvm-project?rev=218106&view=rev
Log:
PECOFF: loosen another assumption of x86 only

Cache the machine type value of the linking context.  We need this in order to
calculate the virtual address of the atom when resolving function symbols.
Windows on ARM must check if the atom is a function and if so, set the Thumb bit
for the returned virtual address.  Failure to do so will result in an abnormal
exit due to a trap caused by invalid instruction decoding.  The same information
can be used to determine the relocation type that was previously being done via
is64 to select between x86 and x86_64.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=218106&r1=218105&r2=218106&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Fri Sep 19 01:09:33 2014
@@ -249,7 +249,7 @@ private:
       StringRef name, const std::vector<const DefinedAtom *> &atoms) const;
 
   mutable llvm::BumpPtrAllocator _alloc;
-  bool is64;
+  llvm::COFF::MachineTypes _machineType;
 };
 
 /// A DataDirectoryChunk represents data directory entries that follows the PE
@@ -447,7 +447,7 @@ AtomChunk::AtomChunk(const PECOFFLinking
                      const std::vector<const DefinedAtom *> &atoms)
     : SectionChunk(kindAtomChunk, sectionName,
                    computeCharacteristics(ctx, sectionName, atoms)),
-      _virtualAddress(0), is64(ctx.is64Bit()) {
+      _virtualAddress(0), _machineType(ctx.getMachineType()) {
   for (auto *a : atoms)
     appendAtom(a);
 }
@@ -635,8 +635,18 @@ void AtomChunk::addBaseRelocations(std::
   // should output debug messages with atom names and addresses so that we
   // can inspect relocations, and fix the tests (base-reloc.test, maybe
   // others) to use those messages.
-  int relType = is64 ? llvm::COFF::IMAGE_REL_AMD64_ADDR64
-                     : llvm::COFF::IMAGE_REL_I386_DIR32;
+
+  int16_t relType = 0; /* IMAGE_REL_*_ABSOLUTE */
+  switch (_machineType) {
+  default: llvm_unreachable("unsupported machine type");
+  case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+    relType = llvm::COFF::IMAGE_REL_I386_DIR32;
+    break;
+  case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+    relType = llvm::COFF::IMAGE_REL_AMD64_ADDR64;
+    break;
+  }
+
   for (const auto *layout : _atomLayouts) {
     const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
     for (const Reference *ref : *atom)





More information about the llvm-commits mailing list