From: Frederic Riss Date: Fri, 11 Dec 2015 17:50:37 +0000 (+0000) Subject: [dsymutil] Ignore absolute symbols in the debug map X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ba16151251acbfd2aec59343aca6c1e6c6a0c97c;p=oota-llvm.git [dsymutil] Ignore absolute symbols in the debug map Quoting from the comment added to the code: // Objective-C on i386 uses artificial absolute symbols to // perform some link time checks. Those symbols have a fixed 0 // address that might conflict with real symbols in the object // file. As I cannot see a way for absolute symbols to find // their way into the debug information, let's just ignore those. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255350 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/dsymutil/Inputs/absolute_sym.macho.i386 b/test/tools/dsymutil/Inputs/absolute_sym.macho.i386 new file mode 100755 index 00000000000..5ca0f2d6868 Binary files /dev/null and b/test/tools/dsymutil/Inputs/absolute_sym.macho.i386 differ diff --git a/test/tools/dsymutil/Inputs/absolute_sym.macho.i386.o b/test/tools/dsymutil/Inputs/absolute_sym.macho.i386.o new file mode 100644 index 00000000000..445e32271cf Binary files /dev/null and b/test/tools/dsymutil/Inputs/absolute_sym.macho.i386.o differ diff --git a/test/tools/dsymutil/absolute_symbol.test b/test/tools/dsymutil/absolute_symbol.test new file mode 100644 index 00000000000..cdd6ae83213 --- /dev/null +++ b/test/tools/dsymutil/absolute_symbol.test @@ -0,0 +1,16 @@ +RUN: llvm-dsymutil -dump-debug-map -oso-prepend-path %p %p/Inputs/absolute_sym.macho.i386 | FileCheck %s + +The tested object file has been created by the dummy Objective-C code: +@interface Foo +@end + +@implementation Foo +@end + +int main() { return 0; } + +compiled for i386. This create an absolute symbol .objc_class_name_Foo +We must not consider this symbol for debug info linking as its address +might conflict with other real symbols in the same file. + +CHECK-NOT: objc_class_name_Foo diff --git a/tools/dsymutil/MachODebugMapParser.cpp b/tools/dsymutil/MachODebugMapParser.cpp index 0eb242d321f..4412db25426 100644 --- a/tools/dsymutil/MachODebugMapParser.cpp +++ b/tools/dsymutil/MachODebugMapParser.cpp @@ -10,6 +10,7 @@ #include "BinaryHolder.h" #include "DebugMap.h" #include "dsymutil.h" +#include "llvm/ADT/Optional.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" @@ -53,7 +54,7 @@ private: /// Owns the MemoryBuffer for the currently handled object file. BinaryHolder CurrentObjectHolder; /// Map of the currently processed object file symbol addresses. - StringMap CurrentObjectAddresses; + StringMap> CurrentObjectAddresses; /// Element of the debug map corresponfing to the current object file. DebugMapObject *CurrentDebugMapObject; @@ -388,7 +389,9 @@ void MachODebugMapParser::handleStabSymbolTableEntry(uint32_t StringIndex, if (ObjectSymIt == CurrentObjectAddresses.end()) return Warning("could not find object file symbol for symbol " + Twine(Name)); - if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value, + if (!ObjectSymIt->getValue()) + return; + if (!CurrentDebugMapObject->addSymbol(Name, *ObjectSymIt->getValue(), Value, Size)) return Warning(Twine("failed to insert symbol '") + Name + "' in the debug map."); @@ -404,7 +407,15 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols( ErrorOr Name = Sym.getName(); if (!Name) continue; - CurrentObjectAddresses[*Name] = Addr; + // Objective-C on i386 uses artificial absolute symbols to + // perform some link time checks. Those symbols have a fixed 0 + // address that might conflict with real symbols in the object + // file. As I cannot see a way for absolute symbols to find + // their way into the debug information, let's just ignore those. + if (Sym.getFlags() & SymbolRef::SF_Absolute) + CurrentObjectAddresses[*Name] = None; + else + CurrentObjectAddresses[*Name] = Addr; } }