mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-31 08:16:47 +00:00 
			
		
		
		
	Code cleanup in RuntimeDyld:
- Add comments - Change field names to be more reasonable - Fix indentation and naming to conform to coding conventions - Remove unnecessary includes / replace them by forward declatations git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155815 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -308,10 +308,10 @@ unsigned RuntimeDyldImpl::findOrEmitSection(ObjectImage &Obj, | |||||||
|   return SectionID; |   return SectionID; | ||||||
| } | } | ||||||
|  |  | ||||||
| void RuntimeDyldImpl::AddRelocation(const RelocationValueRef &Value, | void RuntimeDyldImpl::addRelocation(const RelocationValueRef &Value, | ||||||
|                                     unsigned SectionID, uintptr_t Offset, |                                     unsigned SectionID, uintptr_t Offset, | ||||||
|                                     uint32_t RelType) { |                                     uint32_t RelType) { | ||||||
|   DEBUG(dbgs() << "AddRelocation SymNamePtr: " << format("%p", Value.SymbolName) |   DEBUG(dbgs() << "addRelocation SymNamePtr: " << format("%p", Value.SymbolName) | ||||||
|                << " SID: " << Value.SectionID |                << " SID: " << Value.SectionID | ||||||
|                << " Addend: " << format("%p", Value.Addend) |                << " Addend: " << format("%p", Value.Addend) | ||||||
|                << " Offset: " << format("%p", Offset) |                << " Offset: " << format("%p", Offset) | ||||||
| @@ -370,12 +370,12 @@ void RuntimeDyldImpl::resolveRelocationEntry(const RelocationEntry &RE, | |||||||
|       uint8_t *Target = Sections[RE.SectionID].Address + RE.Offset; |       uint8_t *Target = Sections[RE.SectionID].Address + RE.Offset; | ||||||
|       DEBUG(dbgs() << "\tSectionID: " << RE.SectionID |       DEBUG(dbgs() << "\tSectionID: " << RE.SectionID | ||||||
|             << " + " << RE.Offset << " (" << format("%p", Target) << ")" |             << " + " << RE.Offset << " (" << format("%p", Target) << ")" | ||||||
|             << " Data: " << RE.Data |             << " RelType: " << RE.RelType | ||||||
|             << " Addend: " << RE.Addend |             << " Addend: " << RE.Addend | ||||||
|             << "\n"); |             << "\n"); | ||||||
|  |  | ||||||
|       resolveRelocation(Target, Sections[RE.SectionID].LoadAddress + RE.Offset, |       resolveRelocation(Target, Sections[RE.SectionID].LoadAddress + RE.Offset, | ||||||
|                         Value, RE.Data, RE.Addend); |                         Value, RE.RelType, RE.Addend); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -410,14 +410,14 @@ void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel, | |||||||
|       Stubs[Value] = Section.StubOffset; |       Stubs[Value] = Section.StubOffset; | ||||||
|       uint8_t *StubTargetAddr = createStubFunction(Section.Address + |       uint8_t *StubTargetAddr = createStubFunction(Section.Address + | ||||||
|                                                    Section.StubOffset); |                                                    Section.StubOffset); | ||||||
|       AddRelocation(Value, Rel.SectionID, |       addRelocation(Value, Rel.SectionID, | ||||||
|                     StubTargetAddr - Section.Address, ELF::R_ARM_ABS32); |                     StubTargetAddr - Section.Address, ELF::R_ARM_ABS32); | ||||||
|       resolveRelocation(Target, (uint64_t)Target, (uint64_t)Section.Address + |       resolveRelocation(Target, (uint64_t)Target, (uint64_t)Section.Address + | ||||||
|                         Section.StubOffset, RelType, 0); |                         Section.StubOffset, RelType, 0); | ||||||
|       Section.StubOffset += getMaxStubSize(); |       Section.StubOffset += getMaxStubSize(); | ||||||
|     } |     } | ||||||
|   } else |   } else | ||||||
|     AddRelocation(Value, Rel.SectionID, Rel.Offset, RelType); |     addRelocation(Value, Rel.SectionID, Rel.Offset, RelType); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool RuntimeDyldELF::isCompatibleFormat(const MemoryBuffer *InputBuffer) const { | bool RuntimeDyldELF::isCompatibleFormat(const MemoryBuffer *InputBuffer) const { | ||||||
|   | |||||||
| @@ -14,60 +14,83 @@ | |||||||
| #ifndef LLVM_RUNTIME_DYLD_IMPL_H | #ifndef LLVM_RUNTIME_DYLD_IMPL_H | ||||||
| #define LLVM_RUNTIME_DYLD_IMPL_H | #define LLVM_RUNTIME_DYLD_IMPL_H | ||||||
|  |  | ||||||
|  | #include "ObjectImage.h" | ||||||
| #include "llvm/ExecutionEngine/RuntimeDyld.h" | #include "llvm/ExecutionEngine/RuntimeDyld.h" | ||||||
| #include "llvm/Object/ObjectFile.h" |  | ||||||
| #include "llvm/ADT/DenseMap.h" | #include "llvm/ADT/DenseMap.h" | ||||||
| #include "llvm/ADT/StringMap.h" |  | ||||||
| #include "llvm/ADT/Twine.h" |  | ||||||
| #include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallVector.h" | ||||||
| #include "llvm/Support/Memory.h" | #include "llvm/ADT/StringMap.h" | ||||||
| #include "llvm/Support/MemoryBuffer.h" | #include "llvm/ADT/Triple.h" | ||||||
| #include "llvm/Support/system_error.h" | #include "llvm/Object/ObjectFile.h" | ||||||
| #include "llvm/Support/raw_ostream.h" |  | ||||||
| #include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||||
| #include "llvm/Support/ErrorHandling.h" | #include "llvm/Support/ErrorHandling.h" | ||||||
| #include "llvm/ADT/Triple.h" |  | ||||||
| #include <map> |  | ||||||
| #include "llvm/Support/Format.h" | #include "llvm/Support/Format.h" | ||||||
| #include "ObjectImage.h" | #include "llvm/Support/raw_ostream.h" | ||||||
|  | #include "llvm/Support/system_error.h" | ||||||
|  | #include <map> | ||||||
|  |  | ||||||
| using namespace llvm; | using namespace llvm; | ||||||
| using namespace llvm::object; | using namespace llvm::object; | ||||||
|  |  | ||||||
| namespace llvm { | namespace llvm { | ||||||
|  |  | ||||||
|  | class MemoryBuffer; | ||||||
|  | class Twine; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /// SectionEntry - represents a section emitted into memory by the dynamic | ||||||
|  | /// linker. | ||||||
| class SectionEntry { | class SectionEntry { | ||||||
| public: | public: | ||||||
|   uint8_t  *Address; |   /// Address - address in the linker's memory where the section resides. | ||||||
|   size_t   Size; |   uint8_t *Address; | ||||||
|   uint64_t LoadAddress;   // For each section, the address it will be |  | ||||||
|                           // considered to live at for relocations. The same |   /// Size - section size. | ||||||
|                           // as the pointer to the above memory block for |   size_t Size; | ||||||
|                           // hosted JITs. |  | ||||||
|   uintptr_t StubOffset;   // It's used for architectures with stub |   /// LoadAddress - the address of the section in the target process's memory. | ||||||
|                           // functions for far relocations like ARM. |   /// Used for situations in which JIT-ed code is being executed in the address | ||||||
|   uintptr_t ObjAddress;   // Section address in object file. It's used for |   /// space of a separate process.  If the code executes in the same address | ||||||
|                           // calculating the MachO relocation addend. |   /// space where it was JIT-ed, this just equals Address. | ||||||
|  |   uint64_t LoadAddress; | ||||||
|  |  | ||||||
|  |   /// StubOffset - used for architectures with stub functions for far | ||||||
|  |   /// relocations (like ARM). | ||||||
|  |   uintptr_t StubOffset; | ||||||
|  |  | ||||||
|  |   /// ObjAddress - address of the section in the in-memory object file.  Used | ||||||
|  |   /// for calculating relocations in some object formats (like MachO). | ||||||
|  |   uintptr_t ObjAddress; | ||||||
|  |  | ||||||
|   SectionEntry(uint8_t *address, size_t size, uintptr_t stubOffset, |   SectionEntry(uint8_t *address, size_t size, uintptr_t stubOffset, | ||||||
|                uintptr_t objAddress) |                uintptr_t objAddress) | ||||||
|     : Address(address), Size(size), LoadAddress((uintptr_t)address), |     : Address(address), Size(size), LoadAddress((uintptr_t)address), | ||||||
|       StubOffset(stubOffset), ObjAddress(objAddress) {} |       StubOffset(stubOffset), ObjAddress(objAddress) {} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | /// RelocationEntry - used to represent relocations internally in the dynamic | ||||||
|  | /// linker. | ||||||
| class RelocationEntry { | class RelocationEntry { | ||||||
| public: | public: | ||||||
|   unsigned    SectionID;  // Section the relocation is contained in. |   /// SectionID - the section this relocation points to. | ||||||
|   uintptr_t   Offset;     // Offset into the section for the relocation. |   unsigned SectionID; | ||||||
|   uint32_t    Data;       // Relocation data. Including type of relocation |  | ||||||
|                           // and other flags. |   /// Offset - offset into the section. | ||||||
|   intptr_t    Addend;     // Addend encoded in the instruction itself, if any, |   uintptr_t Offset; | ||||||
|                           // plus the offset into the source section for |  | ||||||
|                           // the symbol once the relocation is resolvable. |   /// RelType - relocation type. | ||||||
|   RelocationEntry(unsigned id, uint64_t offset, uint32_t data, int64_t addend) |   uint32_t RelType; | ||||||
|     : SectionID(id), Offset(offset), Data(data), Addend(addend) {} |  | ||||||
|  |   /// Addend - the relocation addend encoded in the instruction itself.  Also | ||||||
|  |   /// used to make a relocation section relative instead of symbol relative. | ||||||
|  |   intptr_t Addend; | ||||||
|  |  | ||||||
|  |   RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend) | ||||||
|  |     : SectionID(id), Offset(offset), RelType(type), Addend(addend) {} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // Raw relocation data from object file | /// ObjRelocationInfo - relocation information as read from the object file. | ||||||
|  | /// Used to pass around data taken from object::RelocationRef, together with | ||||||
|  | /// the section to which the relocation points (represented by a SectionID). | ||||||
| class ObjRelocationInfo { | class ObjRelocationInfo { | ||||||
| public: | public: | ||||||
|   unsigned  SectionID; |   unsigned  SectionID; | ||||||
| @@ -97,7 +120,8 @@ protected: | |||||||
|   // The MemoryManager to load objects into. |   // The MemoryManager to load objects into. | ||||||
|   RTDyldMemoryManager *MemMgr; |   RTDyldMemoryManager *MemMgr; | ||||||
|  |  | ||||||
|   // A list of emmitted sections. |   // A list of all sections emitted by the dynamic linker.  These sections are | ||||||
|  |   // referenced in the code by means of their index in this list - SectionID. | ||||||
|   typedef SmallVector<SectionEntry, 64> SectionList; |   typedef SmallVector<SectionEntry, 64> SectionList; | ||||||
|   SectionList Sections; |   SectionList Sections; | ||||||
|  |  | ||||||
| @@ -180,7 +204,7 @@ protected: | |||||||
|  |  | ||||||
|   /// \brief If Value.SymbolName is NULL then store relocation to the |   /// \brief If Value.SymbolName is NULL then store relocation to the | ||||||
|   ///        Relocations, else store it in the SymbolRelocations. |   ///        Relocations, else store it in the SymbolRelocations. | ||||||
|   void AddRelocation(const RelocationValueRef &Value, unsigned SectionID, |   void addRelocation(const RelocationValueRef &Value, unsigned SectionID, | ||||||
|                      uintptr_t Offset, uint32_t RelType); |                      uintptr_t Offset, uint32_t RelType); | ||||||
|  |  | ||||||
|   /// \brief Emits long jump instruction to Addr. |   /// \brief Emits long jump instruction to Addr. | ||||||
|   | |||||||
| @@ -30,7 +30,8 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, | |||||||
|   unsigned MachoType = (Type >> 28) & 0xf; |   unsigned MachoType = (Type >> 28) & 0xf; | ||||||
|   unsigned Size = 1 << ((Type >> 25) & 3); |   unsigned Size = 1 << ((Type >> 25) & 3); | ||||||
|  |  | ||||||
|   DEBUG(dbgs() << "resolveRelocation LocalAddress: " << format("%p", LocalAddress) |   DEBUG(dbgs() << "resolveRelocation LocalAddress: "  | ||||||
|  |         << format("%p", LocalAddress) | ||||||
|         << " FinalAddress: " << format("%p", FinalAddress) |         << " FinalAddress: " << format("%p", FinalAddress) | ||||||
|         << " Value: " << format("%p", Value) |         << " Value: " << format("%p", Value) | ||||||
|         << " Addend: " << Addend |         << " Addend: " << Addend | ||||||
| @@ -53,12 +54,12 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, | |||||||
|     break; |     break; | ||||||
|   case Triple::x86: |   case Triple::x86: | ||||||
|     resolveI386Relocation(LocalAddress, |     resolveI386Relocation(LocalAddress, | ||||||
|                                  FinalAddress, |                           FinalAddress, | ||||||
|                                  (uintptr_t)Value, |                           (uintptr_t)Value, | ||||||
|                                  isPCRel, |                           isPCRel, | ||||||
|                                  Type, |                           Type, | ||||||
|                                  Size, |                           Size, | ||||||
|                                  Addend); |                           Addend); | ||||||
|     break; |     break; | ||||||
|   case Triple::arm:    // Fall through. |   case Triple::arm:    // Fall through. | ||||||
|   case Triple::thumb: |   case Triple::thumb: | ||||||
| @@ -73,14 +74,13 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| bool RuntimeDyldMachO:: | bool RuntimeDyldMachO::resolveI386Relocation(uint8_t *LocalAddress, | ||||||
| resolveI386Relocation(uint8_t *LocalAddress, |                                              uint64_t FinalAddress, | ||||||
|                       uint64_t FinalAddress, |                                              uint64_t Value, | ||||||
|                       uint64_t Value, |                                              bool isPCRel, | ||||||
|                       bool isPCRel, |                                              unsigned Type, | ||||||
|                       unsigned Type, |                                              unsigned Size, | ||||||
|                       unsigned Size, |                                              int64_t Addend) { | ||||||
|                       int64_t Addend) { |  | ||||||
|   if (isPCRel) |   if (isPCRel) | ||||||
|     Value -= FinalAddress + 4; // see resolveX86_64Relocation |     Value -= FinalAddress + 4; // see resolveX86_64Relocation | ||||||
|  |  | ||||||
| @@ -102,14 +102,13 @@ resolveI386Relocation(uint8_t *LocalAddress, | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| bool RuntimeDyldMachO:: | bool RuntimeDyldMachO::resolveX86_64Relocation(uint8_t *LocalAddress, | ||||||
| resolveX86_64Relocation(uint8_t *LocalAddress, |                                                uint64_t FinalAddress, | ||||||
|                         uint64_t FinalAddress, |                                                uint64_t Value, | ||||||
|                         uint64_t Value, |                                                bool isPCRel, | ||||||
|                         bool isPCRel, |                                                unsigned Type, | ||||||
|                         unsigned Type, |                                                unsigned Size, | ||||||
|                         unsigned Size, |                                                int64_t Addend) { | ||||||
|                         int64_t Addend) { |  | ||||||
|   // If the relocation is PC-relative, the value to be encoded is the |   // If the relocation is PC-relative, the value to be encoded is the | ||||||
|   // pointer difference. |   // pointer difference. | ||||||
|   if (isPCRel) |   if (isPCRel) | ||||||
| @@ -144,14 +143,13 @@ resolveX86_64Relocation(uint8_t *LocalAddress, | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| bool RuntimeDyldMachO:: | bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress, | ||||||
| resolveARMRelocation(uint8_t *LocalAddress, |                                             uint64_t FinalAddress, | ||||||
|                      uint64_t FinalAddress, |                                             uint64_t Value, | ||||||
|                      uint64_t Value, |                                             bool isPCRel, | ||||||
|                      bool isPCRel, |                                             unsigned Type, | ||||||
|                      unsigned Type, |                                             unsigned Size, | ||||||
|                      unsigned Size, |                                             int64_t Addend) { | ||||||
|                      int64_t Addend) { |  | ||||||
|   // If the relocation is PC-relative, the value to be encoded is the |   // If the relocation is PC-relative, the value to be encoded is the | ||||||
|   // pointer difference. |   // pointer difference. | ||||||
|   if (isPCRel) { |   if (isPCRel) { | ||||||
| @@ -269,7 +267,7 @@ void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel, | |||||||
|       Stubs[Value] = Section.StubOffset; |       Stubs[Value] = Section.StubOffset; | ||||||
|       uint8_t *StubTargetAddr = createStubFunction(Section.Address + |       uint8_t *StubTargetAddr = createStubFunction(Section.Address + | ||||||
|                                                    Section.StubOffset); |                                                    Section.StubOffset); | ||||||
|       AddRelocation(Value, Rel.SectionID, StubTargetAddr - Section.Address, |       addRelocation(Value, Rel.SectionID, StubTargetAddr - Section.Address, | ||||||
|                     macho::RIT_Vanilla); |                     macho::RIT_Vanilla); | ||||||
|       resolveRelocation(Target, (uint64_t)Target, |       resolveRelocation(Target, (uint64_t)Target, | ||||||
|                         (uint64_t)Section.Address + Section.StubOffset, |                         (uint64_t)Section.Address + Section.StubOffset, | ||||||
| @@ -277,11 +275,12 @@ void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel, | |||||||
|       Section.StubOffset += getMaxStubSize(); |       Section.StubOffset += getMaxStubSize(); | ||||||
|     } |     } | ||||||
|   } else |   } else | ||||||
|     AddRelocation(Value, Rel.SectionID, Rel.Offset, RelType); |     addRelocation(Value, Rel.SectionID, Rel.Offset, RelType); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| bool RuntimeDyldMachO::isCompatibleFormat(const MemoryBuffer *InputBuffer) const { | bool RuntimeDyldMachO::isCompatibleFormat( | ||||||
|  |         const MemoryBuffer *InputBuffer) const { | ||||||
|   StringRef Magic = InputBuffer->getBuffer().slice(0, 4); |   StringRef Magic = InputBuffer->getBuffer().slice(0, 4); | ||||||
|   if (Magic == "\xFE\xED\xFA\xCE") return true; |   if (Magic == "\xFE\xED\xFA\xCE") return true; | ||||||
|   if (Magic == "\xCE\xFA\xED\xFE") return true; |   if (Magic == "\xCE\xFA\xED\xFE") return true; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user