[LLVMdev] [llvm] r188726 - Adding PIC support for ELF on x86_64 platforms (original) (raw)

Kaylor, Andrew andrew.kaylor at intel.com
Mon Jan 26 13:59:15 PST 2015


Hi Lang,

Yeah, I remember this case. Basically what’s happening is that there are relocations for ELF on x86 that use a value that is present in the object image as part of the calculation for the final value that goes in the same location. If you ever find yourself applying relocations for a second time (for instance, because the loaded object location is remapped for out-of-proc execution) the original value is no longer in the loaded object.

You could probably figure out a way to combine the placeholder value with the addend field, either while the relocation records are being built (though I’m not sure if the relevant sections have been loaded yet at that point) or the first time the relocation is applied (though it might be a bit cumbersome to know whether or not any given application was the first).

-Andy

From: Lang Hames [mailto:lhames at gmail.com] Sent: Monday, January 26, 2015 1:14 PM To: Kaylor, Andrew Cc: Commit Messages and Patches for LLVM Subject: Re: [llvm] r188726 - Adding PIC support for ELF on x86_64 platforms

Hi Andy,

In the following snippet, do you recall what made it necessary to read the value from the object file via Placeholder, rather than from the copied section?

I''d like to make my new JIT APIs more aggressive about freeing the ObjectFile instances (ideally we'd be able to free immediately after a call to loadObject), but at the moment I have to hold it at least until resolveRelocations is called.

I had a quick chat with Tim Northover about this and our guess was that it had something to do with relocations being applied more than once?

Cheers, Lang.

On Mon, Aug 19, 2013 at 4:27 PM, Andrew Kaylor <andrew.kaylor at intel.com<mailto:andrew.kaylor at intel.com>> wrote: Author: akaylor Date: Mon Aug 19 18:27:43 2013 New Revision: 188726

URL: http://llvm.org/viewvc/llvm-project?rev=188726&view=rev Log: Adding PIC support for ELF on x86_64 platforms

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=188726&r1=188725&r2=188726&view=diff

--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Aug 19 18:27:43 2013 @@ -169,6 +169,9 @@ ObjectImage *RuntimeDyldImpl::loadObject } }

@@ -424,6 +427,10 @@ uint8_t *RuntimeDyldImpl::createStubFunc writeInt16BE(Addr+6, 0x07F1); // brc 15,%r1 // 8-byte address stored at Addr + 8 return Addr;

} return Addr; } @@ -473,6 +480,7 @@ void RuntimeDyldImpl::resolveExternalSym // MemoryManager. uint8_t Addr = (uint8_t) MemMgr->getPointerToNamedFunction(Name.data(), true);

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=188726&r1=188725&r2=188726&view=diff

--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Mon Aug 19 18:27:43 2013 @@ -202,7 +202,8 @@ void RuntimeDyldELF::resolveX86_64Reloca uint64_t Offset, uint64_t Value, uint32_t Type,

@@ -584,7 +610,7 @@ void RuntimeDyldELF::findOPDEntrySection // Finally compares the Symbol value and the target symbol offset // to check if this .opd entry refers to the symbol the relocation // points to.

@@ -757,17 +783,19 @@ void RuntimeDyldELF::resolveSystemZReloc void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE, uint64_t Value) { const SectionEntry &Section = Sections[RE.SectionID];

}

void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section, uint64_t Offset, uint64_t Value, uint32_t Type,

@@ -860,6 +890,7 @@ void RuntimeDyldELF::processRelocationRe Value.Addend = Addend; break; }

@@ -1150,8 +1181,67 @@ void RuntimeDyldELF::processRelocationRe ELF::R_390_PC32DBL, Addend); else resolveRelocation(Section, Offset, StubAddress, RelType, Addend);

} else {

+void RuntimeDyldELF::updateGOTEntries(StringRef Name, uint64_t Addr) {

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h?rev=188726&r1=188725&r2=188726&view=diff

--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h (original) +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h Mon Aug 19 18:27:43 2013 @@ -35,13 +35,15 @@ class RuntimeDyldELF : public RuntimeDyl uint64_t Offset, uint64_t Value, uint32_t Type,

@@ -84,8 +86,18 @@ class RuntimeDyldELF : public RuntimeDyl ObjSectionToIDMap &LocalSections, RelocationValueRef &Rel);

@@ -97,6 +109,7 @@ public: virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const; virtual ObjectImage *createObjectImage(ObjectBuffer *InputBuffer); virtual StringRef getEHFrameSection();

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=188726&r1=188725&r2=188726&view=diff

--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (original) +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h Mon Aug 19 18:27:43 2013 @@ -80,14 +80,18 @@ public: unsigned SectionID;

/// Offset - offset into the section.

@@ -97,20 +101,26 @@ public:

RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend) : SectionID(id), Offset(offset), RelType(type), Addend(addend),

};

class RelocationValueRef { public: unsigned SectionID;

@@ -175,7 +185,7 @@ protected: else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le) return 44; else if (Arch == Triple::x86_64)

} // end namespace llvm


llvm-commits mailing list llvm-commits at cs.uiuc.edu<mailto:llvm-commits at cs.uiuc.edu> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150126/ee11bc95/attachment.html>



More information about the llvm-dev mailing list