[lld] r218104 - PECOFF: loosen assumptions about x86-only targets

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


Author: compnerd
Date: Fri Sep 19 01:09:25 2014
New Revision: 218104

URL: http://llvm.org/viewvc/llvm-project?rev=218104&view=rev
Log:
PECOFF: loosen assumptions about x86-only targets

Rather than saving whether we are targeting 64-bit x86 (x86_64), simply convert
the single use of that information to the actual relocation type.  This will
permit the selection of non-x86 relocation types (e.g. for WoA support).

Inline the access of the machine type field as it is relatively cheap (a couple
of pointer dereferences) rather than storing the relocation type as a member
variable.

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

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=218104&r1=218103&r2=218104&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Sep 19 01:09:25 2014
@@ -139,7 +139,6 @@ private:
   std::error_code getSectionContents(StringRef sectionName,
                                      ArrayRef<uint8_t> &result);
   std::error_code getReferenceArch(Reference::KindArch &result);
-  std::error_code is64(bool &result);
   std::error_code addRelocationReferenceToAtoms();
   std::error_code findSection(StringRef name, const coff_section *&result);
   StringRef ArrayRefToString(ArrayRef<uint8_t> array);
@@ -190,7 +189,6 @@ private:
   _definedAtomLocations;
 
   uint64_t _ordinal;
-  bool _is64;
 };
 
 class BumpPtrStringSaver : public llvm::cl::StringSaver {
@@ -315,8 +313,6 @@ FileCOFF::FileCOFF(std::unique_ptr<Memor
 std::error_code FileCOFF::parse() {
   if (std::error_code ec = getReferenceArch(_referenceArch))
     return ec;
-  if (std::error_code ec = is64(_is64))
-    return ec;
 
   // Read the symbol table and atomize them if possible. Defined atoms
   // cannot be atomized in one pass, so they will be not be atomized but
@@ -831,11 +827,6 @@ std::error_code FileCOFF::getReferenceAr
   return llvm::object::object_error::parse_failed;
 }
 
-std::error_code FileCOFF::is64(bool &result) {
-  result = (_obj->getMachine() == llvm::COFF::IMAGE_FILE_MACHINE_AMD64);
-  return std::error_code();
-}
-
 /// Add relocation information to atoms.
 std::error_code FileCOFF::addRelocationReferenceToAtoms() {
   // Relocation entries are defined for each section.
@@ -894,10 +885,21 @@ std::error_code FileCOFF::maybeCreateSXD
     if (std::error_code ec = getAtomBySymbolIndex(symbolIndex[i], handlerFunc))
       return ec;
     int offsetInAtom = i * sizeof(uint32_t);
+
+    uint16_t rtype;
+    switch (_obj->getMachine()) {
+    case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+      rtype = llvm::COFF::IMAGE_REL_AMD64_ADDR32;
+      break;
+    case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+      rtype = llvm::COFF::IMAGE_REL_I386_DIR32;
+      break;
+    default:
+      llvm_unreachable("unsupported machine type");
+    }
+
     atom->addReference(std::unique_ptr<COFFReference>(new COFFReference(
-        handlerFunc, offsetInAtom, _is64 ? llvm::COFF::IMAGE_REL_AMD64_ADDR32
-                                         : llvm::COFF::IMAGE_REL_I386_DIR32,
-        _referenceArch)));
+        handlerFunc, offsetInAtom, rtype, _referenceArch)));
   }
 
   _definedAtoms._atoms.push_back(atom);





More information about the llvm-commits mailing list