forked from OSchip/llvm-project
Adding padding to the .eh_frame section in RuntimeDyld
llvm-svn: 192754
This commit is contained in:
parent
c442a76c60
commit
877b931a41
|
@ -258,6 +258,7 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
||||||
bool IsZeroInit;
|
bool IsZeroInit;
|
||||||
bool IsReadOnly;
|
bool IsReadOnly;
|
||||||
uint64_t DataSize;
|
uint64_t DataSize;
|
||||||
|
unsigned PaddingSize = 0;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
Check(Section.isRequiredForExecution(IsRequired));
|
Check(Section.isRequiredForExecution(IsRequired));
|
||||||
Check(Section.isVirtual(IsVirtual));
|
Check(Section.isVirtual(IsVirtual));
|
||||||
|
@ -272,6 +273,12 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
||||||
StubBufSize += StubAlignment - EndAlignment;
|
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 Allocate;
|
||||||
unsigned SectionID = Sections.size();
|
unsigned SectionID = Sections.size();
|
||||||
uint8_t *Addr;
|
uint8_t *Addr;
|
||||||
|
@ -280,7 +287,7 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
||||||
// Some sections, such as debug info, don't need to be loaded for execution.
|
// Some sections, such as debug info, don't need to be loaded for execution.
|
||||||
// Leave those where they are.
|
// Leave those where they are.
|
||||||
if (IsRequired) {
|
if (IsRequired) {
|
||||||
Allocate = DataSize + StubBufSize;
|
Allocate = DataSize + PaddingSize + StubBufSize;
|
||||||
Addr = IsCode
|
Addr = IsCode
|
||||||
? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID, Name)
|
? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID, Name)
|
||||||
: MemMgr->allocateDataSection(Allocate, Alignment, SectionID, Name,
|
: MemMgr->allocateDataSection(Allocate, Alignment, SectionID, Name,
|
||||||
|
@ -298,6 +305,13 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
||||||
else
|
else
|
||||||
memcpy(Addr, pData, DataSize);
|
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
|
DEBUG(dbgs() << "emitSection SectionID: " << SectionID
|
||||||
<< " Name: " << Name
|
<< " Name: " << Name
|
||||||
<< " obj addr: " << format("%p", pData)
|
<< " obj addr: " << format("%p", pData)
|
||||||
|
|
Loading…
Reference in New Issue