[llvm] r192754 - Adding padding to the .eh_frame section in RuntimeDyld
Andrew Kaylor
andrew.kaylor at intel.com
Tue Oct 15 17:32:25 PDT 2013
Author: akaylor
Date: Tue Oct 15 19:32:24 2013
New Revision: 192754
URL: http://llvm.org/viewvc/llvm-project?rev=192754&view=rev
Log:
Adding padding to the .eh_frame section in RuntimeDyld
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=192754&r1=192753&r2=192754&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Tue Oct 15 19:32:24 2013
@@ -258,6 +258,7 @@ unsigned RuntimeDyldImpl::emitSection(Ob
bool IsZeroInit;
bool IsReadOnly;
uint64_t DataSize;
+ unsigned PaddingSize = 0;
StringRef Name;
Check(Section.isRequiredForExecution(IsRequired));
Check(Section.isVirtual(IsVirtual));
@@ -272,6 +273,12 @@ unsigned RuntimeDyldImpl::emitSection(Ob
StubBufSize += StubAlignment - EndAlignment;
}
+ // The .eh_frame section (at least on Linux) needs an extra four bytes padded
+ // with zeroes added at the end. For MachO objects, this section has a
+ // slightly different name, so this won't have any effect for MachO objects.
+ if (Name == ".eh_frame")
+ PaddingSize = 4;
+
unsigned Allocate;
unsigned SectionID = Sections.size();
uint8_t *Addr;
@@ -280,7 +287,7 @@ unsigned RuntimeDyldImpl::emitSection(Ob
// Some sections, such as debug info, don't need to be loaded for execution.
// Leave those where they are.
if (IsRequired) {
- Allocate = DataSize + StubBufSize;
+ Allocate = DataSize + PaddingSize + StubBufSize;
Addr = IsCode
? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID, Name)
: MemMgr->allocateDataSection(Allocate, Alignment, SectionID, Name,
@@ -298,6 +305,13 @@ unsigned RuntimeDyldImpl::emitSection(Ob
else
memcpy(Addr, pData, DataSize);
+ // Fill in any extra bytes we allocated for padding
+ if (PaddingSize != 0) {
+ memset(Addr + DataSize, 0, PaddingSize);
+ // Update the DataSize variable so that the stub offset is set correctly.
+ DataSize += PaddingSize;
+ }
+
DEBUG(dbgs() << "emitSection SectionID: " << SectionID
<< " Name: " << Name
<< " obj addr: " << format("%p", pData)
More information about the llvm-commits
mailing list