[llvm] r314198 - [dsymutil] Better support for symbol aliases
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 26 01:17:29 PDT 2017
Author: jdevlieghere
Date: Tue Sep 26 01:17:28 2017
New Revision: 314198
URL: http://llvm.org/viewvc/llvm-project?rev=314198&view=rev
Log:
[dsymutil] Better support for symbol aliases
This patch adds logic to follow a symbol's aliases when the symbol name
cannot be found in the current object file. It checks the main binary
for the symbol's address and queries the current object for its aliases
(symbols with the same address) before printing out a warning.
Differential revision: https://reviews.llvm.org/D38230
Added:
llvm/trunk/test/tools/dsymutil/Inputs/alias/
llvm/trunk/test/tools/dsymutil/Inputs/alias/bar.o
llvm/trunk/test/tools/dsymutil/Inputs/alias/foo.o
llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar (with props)
llvm/trunk/test/tools/dsymutil/X86/alias.test
Modified:
llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
Added: llvm/trunk/test/tools/dsymutil/Inputs/alias/bar.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/alias/bar.o?rev=314198&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/alias/bar.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/alias/bar.o Tue Sep 26 01:17:28 2017 differ
Added: llvm/trunk/test/tools/dsymutil/Inputs/alias/foo.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/alias/foo.o?rev=314198&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/alias/foo.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/alias/foo.o Tue Sep 26 01:17:28 2017 differ
Added: llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar?rev=314198&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar (added) and llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar Tue Sep 26 01:17:28 2017 differ
Propchange: llvm/trunk/test/tools/dsymutil/Inputs/alias/foobar
------------------------------------------------------------------------------
svn:executable = *
Added: llvm/trunk/test/tools/dsymutil/X86/alias.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/alias.test?rev=314198&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/alias.test (added)
+++ llvm/trunk/test/tools/dsymutil/X86/alias.test Tue Sep 26 01:17:28 2017
@@ -0,0 +1,19 @@
+# RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/alias \
+# RUN: %p/../Inputs/alias/foobar -o - 2>&1 | llvm-dwarfdump - | FileCheck %s
+# CHECK-NOT: could not find object file symbol for symbol
+# CHECK: DW_AT_name ("foo.c")
+# CHECK: DW_AT_name ("bar.c")
+
+# Source:
+# $ cat foo.c
+# int foo = 1;
+# $ cat bar.c
+# extern int bar;
+# int main() {
+# return bar;
+# }
+
+# Compile with:
+# $ clang -g -O0 bar.c -c -o bar.o
+# $ clang -g -O0 foo.c -c -o foo.o
+# $ ld -arch x86_64 -macosx_version_min 10.13.0 foo.o bar.o -lSystem -alias _foo _bar -o foobar
Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=314198&r1=314197&r2=314198&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Tue Sep 26 01:17:28 2017
@@ -70,6 +70,7 @@ private:
sys::TimePoint<std::chrono::seconds> Timestamp);
void resetParserState();
uint64_t getMainBinarySymbolAddress(StringRef Name);
+ std::vector<StringRef> getMainBinarySymbolNames(uint64_t Value);
void loadMainBinarySymbols(const MachOObjectFile &MainBinary);
void loadCurrentObjectFileSymbols(const object::MachOObjectFile &Obj);
void handleStabSymbolTableEntry(uint32_t StringIndex, uint8_t Type,
@@ -382,9 +383,21 @@ void MachODebugMapParser::handleStabSymb
}
auto ObjectSymIt = CurrentObjectAddresses.find(Name);
+
+ // If the name of a (non-static) symbol is not in the current object, we
+ // check all its aliases from the main binary.
+ if (ObjectSymIt == CurrentObjectAddresses.end() && Type != MachO::N_STSYM) {
+ for (const auto &Alias : getMainBinarySymbolNames(Value)) {
+ ObjectSymIt = CurrentObjectAddresses.find(Alias);
+ if (ObjectSymIt != CurrentObjectAddresses.end())
+ break;
+ }
+ }
+
if (ObjectSymIt == CurrentObjectAddresses.end())
return Warning("could not find object file symbol for symbol " +
Twine(Name));
+
if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value,
Size))
return Warning(Twine("failed to insert symbol '") + Name +
@@ -429,6 +442,17 @@ uint64_t MachODebugMapParser::getMainBin
return Sym->second;
}
+/// Get all symbol names in the main binary for the given value.
+std::vector<StringRef>
+MachODebugMapParser::getMainBinarySymbolNames(uint64_t Value) {
+ std::vector<StringRef> Names;
+ for (const auto &Entry : MainBinarySymbolAddresses) {
+ if (Entry.second == Value)
+ Names.push_back(Entry.first());
+ }
+ return Names;
+}
+
/// Load the interesting main binary symbols' addresses into
/// MainBinarySymbolAddresses.
void MachODebugMapParser::loadMainBinarySymbols(
More information about the llvm-commits
mailing list