From f9fb9da36c34d2745b74dc30e6c26f7d3f48466c Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 14 Oct 2020 20:10:55 -0700 Subject: [PATCH] [dsymutil] Fix handling of aliases to private external symbols dsymutil was incorrectly ignoring aliases to private extern symbols in the MachODebugMapParser. This resulted in spurious warnings about not being able to find symbols. rdar://49652389 Differential revision: https://reviews.llvm.org/D89444 --- .../tools/dsymutil/ARM/private-extern-alias.test | 29 +++++++++++++++++++++ .../Inputs/private/tmp/private_extern/main.o | Bin 0 -> 1904 bytes .../private/tmp/private_extern/private_extern.o | Bin 0 -> 2160 bytes .../private/tmp/private_extern/private_extern.out | Bin 0 -> 33536 bytes llvm/tools/dsymutil/MachODebugMapParser.cpp | 4 ++- 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 llvm/test/tools/dsymutil/ARM/private-extern-alias.test create mode 100644 llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/main.o create mode 100644 llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.o create mode 100755 llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.out diff --git a/llvm/test/tools/dsymutil/ARM/private-extern-alias.test b/llvm/test/tools/dsymutil/ARM/private-extern-alias.test new file mode 100644 index 0000000..99301fe --- /dev/null +++ b/llvm/test/tools/dsymutil/ARM/private-extern-alias.test @@ -0,0 +1,29 @@ +$ cat private_extern.c +__attribute__((visibility("hidden"))) +int* foo() { + int i = 10; + volatile int* j = &i; + return j; +} + +int* bar() { + return foo(); +} + +$ cat main.c +int* bar(); +int main() { + return *bar(); +} + +$ cat alias_list +_foo _baz + +$ xcrun --sdk iphoneos clang -g private_extern.c -c -o private_extern.o -target arm64-apple-ios14.0 +$ xcrun --sdk iphoneos clang -g main.c -c -o main.o -target arm64-apple-ios14.0 +$ xcrun --sdk iphoneos clang private_extern.o main.o -target arm64-apple-ios14.0 -o private_extern.out -Xlinker -alias_list -Xlinker alias_list + +RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/private_extern/private_extern.out -o %t.dSYM --verbose 2>&1 | FileCheck %s +CHECK-NOT: could not find object file symbol for symbol _baz +CHECK: { sym: _foo, objAddr: 0x0000000000000000, binAddr: 0x0000000100007F58, size: 0x00000020 } +CHECK: { sym: _baz, objAddr: 0x0000000000000000, binAddr: 0x0000000100007F58, size: 0x00000000 } diff --git a/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/main.o b/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/main.o new file mode 100644 index 0000000000000000000000000000000000000000..d9cf74ee64403d5f7049e7b6038f52715d78a55d GIT binary patch literal 1904 zcmb7E%}>-&5Pzk+E3jDkFcCG;J)qGD+gKP*4%f=sd>z$mb?+qZtc9{P+m0QCl$yB1sN?;CO25PVV;g?IS+UFw67;UO*UgFYDuJM#;oX5brK4 zE-+tWc$>hF0qu!bacs9Di1&iwaBk-b**K7&Y*{*$47p4zP#eU1$#AYP+}B~Y*l_`V z9-gTzsCXoZ_l@ECef)JuJeQv(t3kX@_H-Zb6!a}1d-8K0T6?~4mYu%AKt>M4Q_V8) za->D$zGf69=~lk+`89?YW64#(!?ACMA!e-z@bl(R*9?j!!S{W}PWume&iJ+OgVzrj z-Jo8X04r24#(X!_g}~2($2bZ)4T^#_sK^sJGrq7oylg!tAL>iodVP$ny?J-`6;wVU zWOSpxlv{_rwYR+ViR<9b30+}cc(g2hUlH0*oEAE`PI$4VIKjneH!loFFGp{7U4`EU z-$Qs|BpOAgQ=rHm`stEuBiJ+@^dlxgK6}o!Jz!b;2*H3WZ=!9Q1k2aKghNEtWn(T@ zrFKO#jaafjo`@%67v?l)6m))3iNk#l>w2{;qUp12bAhT(95!PqC6!Xr$!sD$Fqke4 zB~t2uno(1O*=(jbkSWSTsiIOEOk^&SvaA_#m54d`_B2&?;87KERyB(>4xf)WW*QDP zoQjyIRjQj7wZ&;&c1osQu87+7ylK#>Lfm4hhEs+7G7;t{n%bZM_uD~%U0(`3BqHaT2j|9@nC}EHxD~kLbx3F-q{iT} bzsDN(aoG^U4?&S_BH;iL9j-Cy+64IrZ{+iW literal 0 HcmV?d00001 diff --git a/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.o b/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.o new file mode 100644 index 0000000000000000000000000000000000000000..b7f1a6a8e8472cb517572cea3a73dd37af650148 GIT binary patch literal 2160 zcmb7F&2Jk;6o2dWI<6fyUr40lz#alBhuThUCvJ2TKIXmO&dhr= z`@^3%{~je$2*g7ce4t`5z@U@hEw=xIew1^0P6WmF2z2HGJ3*!yI+wyokL-(2Z(KaG zW346?#>+sz0T8jcEbYcIEKRfRw01U4tJMmeA=^tYFI;#g35juh>3Kq~FA0d?6Enth zy^csp<9#9{KbGJyb&S5k8*uA}+Pnq-{&%YR)8XZBKR;AyADCAUFMt0T`;-agQGH5N^>^OVf4`!S zKlHFZp-iF>nG&WZbH7|U*_>AObH($;m8qxjlBhMxBo6GSL>zWJMjNA*DWcpAsrr+} zBKA2_7aqEbZ%5n9ixV6rK6%`I`WejhTO`ED4?uFl1`Nf|AWg}<4PDLbkLqlx??)Dm zvz7f27G(_{K@WnJUXEw-oTYJat^ixhY9B!#VF%e=%iA=DPB3tN&zL<^s+20msZBR* zg12^BC3N1oZgj+xt!srHKj;n0?%I~`IWMl4`qFhr)cVruQNU~syBM@zr#K^Vl*3-Xe0(+3@qKDp z0l8jCE^X8D`oc0!DQQalU<9#GAvB1PL|?zQSNveGS8Tvu28*MH+yXO+fX4%O#%yr^sM?{HWvNY2k+u;9;#uN^;T6kX7Xq^+m4k-|6H#Hvq>b5$uHlhTk9Ld@5toPgvT5)&VWeu5}|CwXcNgCPUBsE^zcPbN2n$(_+f K$IObcLi7)Y5)&-| literal 0 HcmV?d00001 diff --git a/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.out b/llvm/test/tools/dsymutil/Inputs/private/tmp/private_extern/private_extern.out new file mode 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il/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp index 617b708..3323a05 100644 --- a/llvm/tools/dsymutil/MachODebugMapParser.cpp +++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp @@ -562,7 +562,9 @@ void MachODebugMapParser::loadMainBinarySymbols( continue; } Section = *SectionOrErr; - if (Section == MainBinary.section_end() || Section->isText()) + if ((Section == MainBinary.section_end() || Section->isText()) && + !(SymType & + MachO::N_PEXT)) // Alias to non-external (was a private external) continue; uint64_t Addr = cantFail(Sym.getValue()); Expected NameOrErr = Sym.getName(); -- 2.7.4