[lld] r219088 - PE/COFF: remove another use of PECOFFLinkingContext::is64bit

Saleem Abdulrasool compnerd at compnerd.org
Sun Oct 5 14:30:29 PDT 2014


Author: compnerd
Date: Sun Oct  5 16:30:29 2014
New Revision: 219088

URL: http://llvm.org/viewvc/llvm-project?rev=219088&view=rev
Log:
PE/COFF: remove another use of PECOFFLinkingContext::is64bit

In order to support more than x86/x86_64, we need to change the behaviour to use
the actual machine type rather than checking the bitness and assuming that we
are on X86.  This replaces the use of is64bit in applyAllRelocations with a
check on the machine type.  This will enable adding support for handling ARM
relocations.

Rename the existing applyRelocation methods to be similarly named and to make it
clear the types of relocations they will process.

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=219088&r1=219087&r2=219088&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Sun Oct  5 16:30:29 2014
@@ -216,14 +216,18 @@ public:
   void appendAtom(const DefinedAtom *atom);
   void buildAtomRvaMap(std::map<const Atom *, uint64_t> &atomRva) const;
 
-  void applyRelocations32(uint8_t *buffer,
-                          std::map<const Atom *, uint64_t> &atomRva,
-                          std::vector<uint64_t> &sectionRva,
-                          uint64_t imageBaseAddress);
-  void applyRelocations64(uint8_t *buffer,
-                          std::map<const Atom *, uint64_t> &atomRva,
-                          std::vector<uint64_t> &sectionRva,
-                          uint64_t imageBaseAddress);
+  void applyRelocationsARM(uint8_t *buffer,
+                           std::map<const Atom *, uint64_t> &atomRva,
+                           std::vector<uint64_t> &sectionRva,
+                           uint64_t imageBaseAddress);
+  void applyRelocationsX86_32(uint8_t *buffer,
+                              std::map<const Atom *, uint64_t> &atomRva,
+                              std::vector<uint64_t> &sectionRva,
+                              uint64_t imageBaseAddress);
+  void applyRelocationsX86_64(uint8_t *buffer,
+                              std::map<const Atom *, uint64_t> &atomRva,
+                              std::vector<uint64_t> &sectionRva,
+                              uint64_t imageBaseAddress);
 
   void printAtomAddresses(uint64_t baseAddr) const;
   void addBaseRelocations(std::vector<uint64_t> &relocSites) const;
@@ -501,10 +505,16 @@ static uint32_t getSectionStartAddr(uint
   llvm_unreachable("Section missing");
 }
 
-void AtomChunk::applyRelocations32(uint8_t *buffer,
-                                   std::map<const Atom *, uint64_t> &atomRva,
-                                   std::vector<uint64_t> &sectionRva,
-                                   uint64_t imageBaseAddress) {
+void AtomChunk::applyRelocationsARM(uint8_t *buffer,
+                                    std::map<const Atom *, uint64_t> &atomRva,
+                                    std::vector<uint64_t> &sectionRva,
+                                    uint64_t imageBaseAddress) {
+}
+
+void AtomChunk::applyRelocationsX86_32(uint8_t *buffer,
+                                       std::map<const Atom *, uint64_t> &atomRva,
+                                       std::vector<uint64_t> &sectionRva,
+                                       uint64_t imageBaseAddress) {
   buffer += _fileOffset;
   for (const auto *layout : _atomLayouts) {
     const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
@@ -554,10 +564,10 @@ void AtomChunk::applyRelocations32(uint8
   }
 }
 
-void AtomChunk::applyRelocations64(uint8_t *buffer,
-                                   std::map<const Atom *, uint64_t> &atomRva,
-                                   std::vector<uint64_t> &sectionRva,
-                                   uint64_t imageBase) {
+void AtomChunk::applyRelocationsX86_64(uint8_t *buffer,
+                                       std::map<const Atom *, uint64_t> &atomRva,
+                                       std::vector<uint64_t> &sectionRva,
+                                       uint64_t imageBase) {
   buffer += _fileOffset;
   for (const auto *layout : _atomLayouts) {
     const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
@@ -1100,10 +1110,17 @@ void PECOFFWriter::applyAllRelocations(u
   uint64_t base = _ctx.getBaseAddress();
   for (auto &cp : _chunks) {
     if (AtomChunk *chunk = dyn_cast<AtomChunk>(&*cp)) {
-      if (_ctx.is64Bit()) {
-        chunk->applyRelocations64(bufferStart, _atomRva, sectionRva, base);
-      } else {
-        chunk->applyRelocations32(bufferStart, _atomRva, sectionRva, base);
+      switch (_ctx.getMachineType()) {
+      default: llvm_unreachable("unsupported machine type");
+      case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
+        chunk->applyRelocationsARM(bufferStart, _atomRva, sectionRva, base);
+        break;
+      case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+        chunk->applyRelocationsX86_32(bufferStart, _atomRva, sectionRva, base);
+        break;
+      case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+        chunk->applyRelocationsX86_64(bufferStart, _atomRva, sectionRva, base);
+        break;
       }
     }
   }





More information about the llvm-commits mailing list