[lld] r219959 - [mach-o] update __eh_frame handling for Nick's suggestions
Tim Northover
tnorthover at apple.com
Thu Oct 16 13:52:18 PDT 2014
Author: tnorthover
Date: Thu Oct 16 15:52:18 2014
New Revision: 219959
URL: http://llvm.org/viewvc/llvm-project?rev=219959&view=rev
Log:
[mach-o] update __eh_frame handling for Nick's suggestions
First, add a comment to support more variation in FDE formats. Second, refactor
fde -> function handling into a separate function living in the ArchHandler.
Modified:
lld/trunk/lib/ReaderWriter/MachO/ArchHandler.cpp
lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h
lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler.cpp?rev=219959&r1=219958&r2=219959&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler.cpp Thu Oct 16 15:52:18 2014
@@ -153,6 +153,18 @@ bool ArchHandler::isDwarfCIE(bool swap,
return read32(swap, *(uint32_t *)(atom->rawContent().data() + idOffset)) == 0;
}
+const Atom *ArchHandler::fdeTargetFunction(const DefinedAtom *fde) {
+ for (auto ref : *fde) {
+ if (ref->kindNamespace() == Reference::KindNamespace::mach_o &&
+ ref->kindValue() == unwindRefToFunctionKind()) {
+ assert(ref->kindArch() == kindArch() && "unexpected Reference arch");
+ return ref->target();
+ }
+ }
+
+ return nullptr;
+}
+
} // namespace mach_o
} // namespace lld
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h?rev=219959&r1=219958&r2=219959&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h Thu Oct 16 15:52:18 2014
@@ -88,6 +88,8 @@ public:
/// __eh_frame.
virtual Reference::KindValue unwindRefToEhFrameKind() = 0;
+ virtual const Atom *fdeTargetFunction(const DefinedAtom *fde);
+
/// Used by normalizedFromAtoms() to know where to generated rebasing and
/// binding info in final executables.
virtual bool isPointer(const Reference &) = 0;
Modified: lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp?rev=219959&r1=219958&r2=219959&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp Thu Oct 16 15:52:18 2014
@@ -411,18 +411,13 @@ private:
collectDwarfFrameEntries(std::unique_ptr<MutableFile> &mergedFile,
std::map<const Atom *, const Atom *> &dwarfFrames) {
for (const DefinedAtom *ehFrameAtom : mergedFile->defined()) {
- if (ehFrameAtom->contentType() != DefinedAtom::typeCFI ||
- ArchHandler::isDwarfCIE(_swap, ehFrameAtom))
+ if (ehFrameAtom->contentType() != DefinedAtom::typeCFI)
+ continue;
+ if (ArchHandler::isDwarfCIE(_swap, ehFrameAtom))
continue;
- DefinedAtom::reference_iterator ref = ehFrameAtom->begin();
- for (; ref != ehFrameAtom->end(); ++ref)
- if (ref->kindNamespace() == Reference::KindNamespace::mach_o &&
- ref->kindArch() == _archHandler.kindArch() &&
- ref->kindValue() == _archHandler.unwindRefToFunctionKind()) {
- dwarfFrames.insert(std::make_pair(ref->target(), ehFrameAtom));
- break;
- }
+ if (const Atom *function = _archHandler.fdeTargetFunction(ehFrameAtom))
+ dwarfFrames[function] = ehFrameAtom;
}
}
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=219959&r1=219958&r2=219959&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Thu Oct 16 15:52:18 2014
@@ -677,7 +677,9 @@ std::error_code addEHFrameReferences(con
addend, handler.kindArch());
// Linker needs to fixup reference from the FDE to the function it's
- // describing.
+ // describing. FIXME: there are actually different ways to do this, and the
+ // particular method used is specified in the CIE's augmentation fields
+ // (hopefully)
uint64_t rangeFieldInFDE = cieFieldInFDE + sizeof(uint32_t);
int64_t functionFromFDE = readSPtr(is64, swap, frameData + rangeFieldInFDE);
More information about the llvm-commits
mailing list