Skip to content

Commit a01f355

Browse files
committed
[RuntimeDyld] Make sure we emit MachO __eh_frame and __gcc_except_tab sections,
even if there are no references to them in the code. This allows exceptions thrown from JIT'd code to be caught by the JIT itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234975 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c0a57ae commit a01f355

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,30 @@ bool RuntimeDyldMachO::isCompatibleFile(const object::ObjectFile &Obj) const {
178178
}
179179

180180
template <typename Impl>
181-
void RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &ObjImg,
181+
void RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &Obj,
182182
ObjSectionToIDMap &SectionMap) {
183183
unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
184184
unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
185185
unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
186-
ObjSectionToIDMap::iterator i, e;
187186

188-
for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
189-
const SectionRef &Section = i->first;
187+
for (const auto &Section : Obj.sections()) {
190188
StringRef Name;
191189
Section.getName(Name);
192-
if (Name == "__eh_frame")
193-
EHFrameSID = i->second;
194-
else if (Name == "__text")
195-
TextSID = i->second;
190+
191+
// Force emission of the __text, __eh_frame, and __gcc_except_tab sections
192+
// if they're present. Otherwise call down to the impl to handle other
193+
// sections that have already been emitted.
194+
if (Name == "__text")
195+
TextSID = findOrEmitSection(Obj, Section, true, SectionMap);
196+
else if (Name == "__eh_frame")
197+
EHFrameSID = findOrEmitSection(Obj, Section, false, SectionMap);
196198
else if (Name == "__gcc_except_tab")
197-
ExceptTabSID = i->second;
198-
else
199-
impl().finalizeSection(ObjImg, i->second, Section);
199+
ExceptTabSID = findOrEmitSection(Obj, Section, true, SectionMap);
200+
else {
201+
auto I = SectionMap.find(Section);
202+
if (I != SectionMap.end())
203+
impl().finalizeSection(Obj, I->second, Section);
204+
}
200205
}
201206
UnregisteredEHFrameSections.push_back(
202207
EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));

test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ insn3:
3131
movl $0, %eax
3232
retq
3333

34+
# Test processing of the __eh_frame section.
35+
# rtdyld-check: *{8}(section_addr(test_x86-64.o, __eh_frame) + 0x20) = eh_frame_test - (section_addr(test_x86-64.o, __eh_frame) + 0x20)
36+
eh_frame_test:
37+
.cfi_startproc
38+
retq
39+
.cfi_endproc
40+
3441
.comm y,4,2
3542

3643
.section __DATA,__data

0 commit comments

Comments
 (0)