diff options
author | Frederic Riss <friss@apple.com> | 2015-07-24 06:41:11 +0000 |
---|---|---|
committer | Frederic Riss <friss@apple.com> | 2015-07-24 06:41:11 +0000 |
commit | eb85c8fb099ec65b47467d15b9ea1018ca201f6b (patch) | |
tree | cb3f6944d5153d5eedfc710456ea8d7dc30b0fc2 /llvm/tools/dsymutil/MachODebugMapParser.cpp | |
parent | 65f0abf275ccc1eb249bb12ce4ac826c9df37986 (diff) | |
download | bcm5719-llvm-eb85c8fb099ec65b47467d15b9ea1018ca201f6b.tar.gz bcm5719-llvm-eb85c8fb099ec65b47467d15b9ea1018ca201f6b.zip |
[dsymutil] Implement support for universal mach-o object files.
This patch allows llvm-dsymutil to read universal (aka fat) macho object
files and archives. The patch touches nearly everything in the BinaryHolder,
but it is fairly mechinical: the methods that returned MemoryBufferRefs or
ObjectFiles now return a vector of those, and the high-level access function
takes a triple argument to select the architecture.
There is no support yet for handling fat executables and thus no support for
writing fat object files.
llvm-svn: 243096
Diffstat (limited to 'llvm/tools/dsymutil/MachODebugMapParser.cpp')
-rw-r--r-- | llvm/tools/dsymutil/MachODebugMapParser.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp index cda43494b9b..33554f12122 100644 --- a/llvm/tools/dsymutil/MachODebugMapParser.cpp +++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp @@ -58,8 +58,8 @@ private: void switchToNewDebugMapObject(StringRef Filename, sys::TimeValue Timestamp); void resetParserState(); uint64_t getMainBinarySymbolAddress(StringRef Name); - void loadMainBinarySymbols(); - void loadCurrentObjectFileSymbols(); + void loadMainBinarySymbols(const MachOObjectFile &MainBinary); + void loadCurrentObjectFileSymbols(const object::MachOObjectFile &Obj); void handleStabSymbolTableEntry(uint32_t StringIndex, uint8_t Type, uint8_t SectionIndex, uint16_t Flags, uint64_t Value); @@ -92,27 +92,38 @@ void MachODebugMapParser::switchToNewDebugMapObject(StringRef Filename, sys::path::append(Path, Filename); auto MachOOrError = - CurrentObjectHolder.GetFileAs<MachOObjectFile>(Path, Timestamp); + CurrentObjectHolder.GetFilesAs<MachOObjectFile>(Path, Timestamp); if (auto Error = MachOOrError.getError()) { Warning(Twine("cannot open debug object \"") + Path.str() + "\": " + Error.message() + "\n"); return; } - loadCurrentObjectFileSymbols(); + auto ErrOrAchObj = + CurrentObjectHolder.GetAs<MachOObjectFile>(Result->getTriple()); + if (auto Err = ErrOrAchObj.getError()) { + return Warning(Twine("cannot open debug object \"") + Path.str() + "\": " + + Err.message() + "\n"); + } + CurrentDebugMapObject = &Result->addDebugMapObject(Path, Timestamp); + loadCurrentObjectFileSymbols(*ErrOrAchObj); } /// This main parsing routine tries to open the main binary and if /// successful iterates over the STAB entries. The real parsing is /// done in handleStabSymbolTableEntry. ErrorOr<std::unique_ptr<DebugMap>> MachODebugMapParser::parse() { - auto MainBinOrError = MainBinaryHolder.GetFileAs<MachOObjectFile>(BinaryPath); + auto MainBinOrError = + MainBinaryHolder.GetFilesAs<MachOObjectFile>(BinaryPath); if (auto Error = MainBinOrError.getError()) return Error; - const MachOObjectFile &MainBinary = *MainBinOrError; - loadMainBinarySymbols(); + if (MainBinOrError->size() != 1) + return make_error_code(object::object_error::invalid_file_type); + + const MachOObjectFile &MainBinary = *MainBinOrError->front(); + loadMainBinarySymbols(MainBinary); Result = make_unique<DebugMap>(BinaryHolder::getTriple(MainBinary)); MainBinaryStrings = MainBinary.getStringTableData(); for (const SymbolRef &Symbol : MainBinary.symbols()) { @@ -189,10 +200,11 @@ void MachODebugMapParser::handleStabSymbolTableEntry(uint32_t StringIndex, } /// Load the current object file symbols into CurrentObjectAddresses. -void MachODebugMapParser::loadCurrentObjectFileSymbols() { +void MachODebugMapParser::loadCurrentObjectFileSymbols( + const object::MachOObjectFile &Obj) { CurrentObjectAddresses.clear(); - for (auto Sym : CurrentObjectHolder.Get().symbols()) { + for (auto Sym : Obj.symbols()) { uint64_t Addr = Sym.getValue(); ErrorOr<StringRef> Name = Sym.getName(); if (!Name) @@ -213,9 +225,10 @@ uint64_t MachODebugMapParser::getMainBinarySymbolAddress(StringRef Name) { /// Load the interesting main binary symbols' addresses into /// MainBinarySymbolAddresses. -void MachODebugMapParser::loadMainBinarySymbols() { - const MachOObjectFile &MainBinary = MainBinaryHolder.GetAs<MachOObjectFile>(); +void MachODebugMapParser::loadMainBinarySymbols( + const MachOObjectFile &MainBinary) { section_iterator Section = MainBinary.section_end(); + MainBinarySymbolAddresses.clear(); for (const auto &Sym : MainBinary.symbols()) { SymbolRef::Type Type = Sym.getType(); // Skip undefined and STAB entries. |