From ba16151251acbfd2aec59343aca6c1e6c6a0c97c Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Fri, 11 Dec 2015 17:50:37 +0000 Subject: [PATCH] [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 --- .../dsymutil/Inputs/absolute_sym.macho.i386 | Bin 0 -> 8592 bytes .../dsymutil/Inputs/absolute_sym.macho.i386.o | Bin 0 -> 2472 bytes test/tools/dsymutil/absolute_symbol.test | 16 ++++++++++++++++ tools/dsymutil/MachODebugMapParser.cpp | 17 ++++++++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100755 test/tools/dsymutil/Inputs/absolute_sym.macho.i386 create mode 100644 test/tools/dsymutil/Inputs/absolute_sym.macho.i386.o create mode 100644 test/tools/dsymutil/absolute_symbol.test 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 0000000000000000000000000000000000000000..5ca0f2d6868ad4958ea86dcd900762d8bf429b44 GIT binary patch literal 8592 zcmeHNOKTHR6uxO9*7|65CAQ#Dil~bu#bOJ(&}!7Gw4qilKDeDE({{={VrPQwE+{I3 z3zxbp{sO5W-B<(#!G(XpRhQznh=|`ek0xoF;KtoO^vpfy-1E5in+eRF({I0i{Mjvp zNP;`S-Qekz5Kn}bNI)I|OPN1^Id>;FIRPc6o>*ue8JEIE%BkG+RNXvd;y8?~y9>

j^{`WUIZ9Sj9$G^H={w0afmSB{<$WSl(ymPvS{g^ z7wXONSxz8!TWw|y2pGiSk=~dis|mpz*|s^nWxL>7!6M)*Wn+#RwmEFKRI!X2 zj*U6WQI2xk9Hy<$ZKY^hM-@3bv5sn+9K09db9{Yl{95kfSo}<8F@ZRt3Got6d>-i= zQ$Nzuh4XZ4MLk;hJn()T2H%6eALAy*R~Yw#^I+1Rhhapb$_9 zChapb$_9CdM3>UBubn|2Ee#juGi9o;r0zd4-4lszwv zC8JpJ4LNV&1CDZJruAopyx`_PirVI~vi`Z^A9i!KSVB{7OL< K@c#yYQ~U+ToYW2g literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..445e32271cf5a63da5f450bee66e0b6caec17cac GIT binary patch literal 2472 zcmb7F&ubJ(6t14>Nn$#-(UB#v!VYX?v!LU|gK;;qPF!`P&SLQQMT(x-8AfKhhnbEj z2oYr2toR2kdohAHFXGvQ;KF+H?7^!Z{BiT7;`)8n)tyfFDDlDTSM^@KufD2!RsH1M zn~#G+h&TyyA?&V-LNy<})&YfEAv$X}P@{?{; zT#LF=UU2J+4cYV-eEOt3cy{K*;V7)~kE8ce^LsWFa)&Dy4T>N3`VQzxs0ZH+=Z_Sy{<7nfCu*xlELT&T@^@Uyn=TQ`e;2o{Q15Z(|Xb(4`Quk zcyt}F;r6m?Ss%tcmeKSYdXDtj5`#yQ<`I)XOv<(!IC8$_^uU7s;|GrZ%2p^wZg-07@ET1sI(0vc?z(23(W`kG6kd zvE@dEn#Q=NF_tyPj=nsaZKn}KWOzIT2FgnO4UEr;luoAu8lKbU(E?-beR&Lweekbn zjD4#-;-iT${Q5;zWN8c&BgcX9EXyNK<+p< z1yaLW_-;Wm7GIHXB=jkt>SV zOCx#PvVOLvtrtsJR=zA4s}ARF`i>O$kKnk*Mc)3!vbb!PWln786vlgdBfbXNKn>y4 zdwy#%a3yYPxeYI*pjI(fu!kS#3K%`Z!Y|coXMQhTa=X2z@0F&?m2#ytfhWRi?3}7p z%9G`(J>|(C(|Eg%c%8+dCl33*Xgf_$G`&D|MD!L$mUC9r^!-0owSm}6ZMEq?IN{|u zzE!+Ztdsp{uOyOZPtMG;8!7fqN!Sm67#ElRxym|J=L0(#4iU**y3)D-L%wDV_kg;U zU=S9FAqHRzxPLs#kZ0xEvekU`r&UG&B($dewOsRZj?QvXAR&a^G-!mBlLK z_=FI5-f|T}+}7{wom;9n#cjS(dlA2x=<}YF4^!0Tg8c@%DZ~(>%$GO(v8jh#vM!}6 F%umi!4tW3o literal 0 HcmV?d00001 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; } } -- 2.34.1