[lld] r366095 - Reland "[COFF] Add null check in case of symbols defined in LTO blobs"

Diana Picus via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 01:22:32 PDT 2019


Seems reasonable, thanks!

On Wed, 17 Jul 2019 at 00:02, Reid Kleckner <rnk at google.com> wrote:
>
> I added some REQUIRES lines in r366273 and r366245.
>
> On Tue, Jul 16, 2019 at 1:48 AM Diana Picus <diana.picus at linaro.org> wrote:
>>
>> Hi Reid,
>>
>> I think this doesn't work on AArch64:
>> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/6931
>>
>> You probably missed it because the bot was already red with some other breakage.
>> Could you please have a look?
>>
>> Thanks,
>> Diana
>>
>> On Mon, 15 Jul 2019 at 19:50, Reid Kleckner via llvm-commits
>> <llvm-commits at lists.llvm.org> wrote:
>> >
>> > Author: rnk
>> > Date: Mon Jul 15 10:51:02 2019
>> > New Revision: 366095
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=366095&view=rev
>> > Log:
>> > Reland "[COFF] Add null check in case of symbols defined in LTO blobs"
>> >
>> > This reverts r365990 (git commit 1a6053ebc61cb0b8146f5ca27b74859a9a91e0a3)
>> >
>> > The test no longer depends on the Visual C++ libraries. I confirmed that
>> > the crash still reproduces with the new test case if I remove the null
>> > check.
>> >
>> > Added:
>> >     lld/trunk/test/COFF/Inputs/undefined-symbol-lto-a.ll
>> >     lld/trunk/test/COFF/Inputs/undefined-symbol-lto-b.ll
>> >     lld/trunk/test/COFF/undefined-symbol-lto.test
>> > Modified:
>> >     lld/trunk/COFF/SymbolTable.cpp
>> >
>> > Modified: lld/trunk/COFF/SymbolTable.cpp
>> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=366095&r1=366094&r2=366095&view=diff
>> > ==============================================================================
>> > --- lld/trunk/COFF/SymbolTable.cpp (original)
>> > +++ lld/trunk/COFF/SymbolTable.cpp Mon Jul 15 10:51:02 2019
>> > @@ -69,7 +69,7 @@ static Symbol *getSymbol(SectionChunk *s
>> >
>> >    for (Symbol *s : sc->file->getSymbols()) {
>> >      auto *d = dyn_cast_or_null<DefinedRegular>(s);
>> > -    if (!d || d->getChunk() != sc || d->getValue() > addr ||
>> > +    if (!d || !d->data || d->getChunk() != sc || d->getValue() > addr ||
>> >          (candidate && d->getValue() < candidate->getValue()))
>> >        continue;
>> >
>> >
>> > Added: lld/trunk/test/COFF/Inputs/undefined-symbol-lto-a.ll
>> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/undefined-symbol-lto-a.ll?rev=366095&view=auto
>> > ==============================================================================
>> > --- lld/trunk/test/COFF/Inputs/undefined-symbol-lto-a.ll (added)
>> > +++ lld/trunk/test/COFF/Inputs/undefined-symbol-lto-a.ll Mon Jul 15 10:51:02 2019
>> > @@ -0,0 +1,82 @@
>> > +; ModuleID = 't.obj'
>> > +source_filename = "t.cpp"
>> > +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
>> > +target triple = "x86_64-pc-windows-msvc19.21.27702"
>> > +
>> > +%struct.Init = type { %struct.S }
>> > +%struct.S = type { i32 (...)** }
>> > +%rtti.CompleteObjectLocator = type { i32, i32, i32, i32, i32, i32 }
>> > +%rtti.TypeDescriptor7 = type { i8**, i8*, [8 x i8] }
>> > +%rtti.ClassHierarchyDescriptor = type { i32, i32, i32, i32 }
>> > +%rtti.BaseClassDescriptor = type { i32, i32, i32, i32, i32, i32, i32 }
>> > +
>> > +$"??_SS@@6B@" = comdat largest
>> > +
>> > +$"??_R4S@@6B@" = comdat any
>> > +
>> > +$"??_R0?AUS@@@8" = comdat any
>> > +
>> > +$"??_R3S@@8" = comdat any
>> > +
>> > +$"??_R2S@@8" = comdat any
>> > +
>> > +$"??_R1A@?0A at EA@S@@8" = comdat any
>> > +
>> > +@"?d@@3UInit@@A" = dso_local local_unnamed_addr global %struct.Init zeroinitializer, align 8
>> > + at anon.bcb2691509de99310dddb690fcdb4cdc.0 = private unnamed_addr constant { [2 x i8*] } { [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4S@@6B@" to i8*), i8* bitcast (void (%struct.S*)* @"?foo at S@@UEAAXXZ" to i8*)] }, comdat($"??_SS@@6B@"), !type !0
>> > +@"??_R4S@@6B@" = linkonce_odr constant %rtti.CompleteObjectLocator { i32 1, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor7* @"??_R0?AUS@@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.ClassHierarchyDescriptor* @"??_R3S@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.CompleteObjectLocator* @"??_R4S@@6B@" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, comdat
>> > +@"??_7type_info@@6B@" = external constant i8*
>> > +@"??_R0?AUS@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUS@@\00" }, comdat
>> > + at __ImageBase = external dso_local constant i8
>> > +@"??_R3S@@8" = linkonce_odr constant %rtti.ClassHierarchyDescriptor { i32 0, i32 0, i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint ([2 x i32]* @"??_R2S@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, comdat
>> > +@"??_R2S@@8" = linkonce_odr constant [2 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.BaseClassDescriptor* @"??_R1A@?0A at EA@S@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0], comdat
>> > +@"??_R1A@?0A at EA@S@@8" = linkonce_odr constant %rtti.BaseClassDescriptor { i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor7* @"??_R0?AUS@@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 0, i32 -1, i32 0, i32 64, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.ClassHierarchyDescriptor* @"??_R3S@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, comdat
>> > + at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_t.cpp, i8* null }]
>> > +
>> > +@"??_SS@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @anon.bcb2691509de99310dddb690fcdb4cdc.0, i32 0, i32 0, i32 1)
>> > +
>> > +declare dso_local void @"?undefined_ref@@YAXXZ"() local_unnamed_addr #0
>> > +
>> > +declare dllimport void @"?foo at S@@UEAAXXZ"(%struct.S*) unnamed_addr #0
>> > +
>> > +; Function Attrs: nounwind sspstrong uwtable
>> > +define internal void @_GLOBAL__sub_I_t.cpp() #1 {
>> > +entry:
>> > +  store i32 (...)** bitcast (i8** @"??_SS@@6B@" to i32 (...)**), i32 (...)*** getelementptr inbounds (%struct.Init, %struct.Init* @"?d@@3UInit@@A", i64 0, i32 0, i32 0), align 8
>> > +  tail call void @"?undefined_ref@@YAXXZ"() #2
>> > +  ret void
>> > +}
>> > +
>> > +attributes #0 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
>> > +attributes #1 = { nounwind sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
>> > +attributes #2 = { nounwind }
>> > +
>> > +!llvm.linker.options = !{!1, !2}
>> > +!llvm.module.flags = !{!3, !4, !5, !6}
>> > +!llvm.ident = !{!7}
>> > +
>> > +!0 = !{i64 8, !"?AUS@@"}
>> > +!1 = !{!"/DEFAULTLIB:libcmt.lib"}
>> > +!2 = !{!"/DEFAULTLIB:oldnames.lib"}
>> > +!3 = !{i32 1, !"wchar_size", i32 2}
>> > +!4 = !{i32 7, !"PIC Level", i32 2}
>> > +!5 = !{i32 1, !"ThinLTO", i32 0}
>> > +!6 = !{i32 1, !"EnableSplitLTOUnit", i32 0}
>> > +!7 = !{!"clang version 9.0.0 (git at github.com:llvm/llvm-project.git 1a285c27fdf6407ceed3398e015d00559f5f533d)"}
>> > +
>> > +^0 = module: (path: "t.obj", hash: (0, 0, 0, 0, 0))
>> > +^1 = gv: (name: "__ImageBase") ; guid = 434928772013489304
>> > +^2 = gv: (name: "??_R2S@@8", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^1, ^6)))) ; guid = 2160898732728284029
>> > +^3 = gv: (name: "llvm.global_ctors", summaries: (variable: (module: ^0, flags: (linkage: appending, notEligibleToImport: 1, live: 1, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^14)))) ; guid = 2412314959268824392
>> > +^4 = gv: (name: "?foo at S@@UEAAXXZ") ; guid = 6578172636330484861
>> > +^5 = gv: (name: "??_SS@@6B@", summaries: (alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), aliasee: ^10))) ; guid = 8774897714842691026
>> > +^6 = gv: (name: "??_R1A@?0A at EA@S@@8", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^11, ^1, ^8)))) ; guid = 9397802696236423453
>> > +^7 = gv: (name: "?undefined_ref@@YAXXZ") ; guid = 9774674600202276560
>> > +^8 = gv: (name: "??_R3S@@8", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^1, ^2)))) ; guid = 10685958509605791599
>> > +^9 = gv: (name: "??_7type_info@@6B@") ; guid = 10826752452437539368
>> > +^10 = gv: (name: "anon.bcb2691509de99310dddb690fcdb4cdc.0", summaries: (variable: (module: ^0, flags: (linkage: private, notEligibleToImport: 1, live: 0, dsoLocal: 1, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), vTableFuncs: ((virtFunc: ^4, offset: 8)), refs: (^13, ^4)))) ; guid = 11510395461204283992
>> > +^11 = gv: (name: "??_R0?AUS@@@8", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^9)))) ; guid = 12346607659584231960
>> > +^12 = gv: (name: "?d@@3UInit@@A", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1, canAutoHide: 0), varFlags: (readonly: 1, writeonly: 1)))) ; guid = 14563354643524156382
>> > +^13 = gv: (name: "??_R4S@@6B@", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 1, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), refs: (^13, ^11, ^1, ^8)))) ; guid = 14703528065171087394
>> > +^14 = gv: (name: "_GLOBAL__sub_I_t.cpp", summaries: (function: (module: ^0, flags: (linkage: internal, notEligibleToImport: 1, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 3, calls: ((callee: ^7)), refs: (^12, ^5)))) ; guid = 15085897428757412588
>> > +^15 = typeidCompatibleVTable: (name: "?AUS@@", summary: ((offset: 8, ^10))) ; guid = 13986515119763165370
>> >
>> > Added: lld/trunk/test/COFF/Inputs/undefined-symbol-lto-b.ll
>> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/undefined-symbol-lto-b.ll?rev=366095&view=auto
>> > ==============================================================================
>> > --- lld/trunk/test/COFF/Inputs/undefined-symbol-lto-b.ll (added)
>> > +++ lld/trunk/test/COFF/Inputs/undefined-symbol-lto-b.ll Mon Jul 15 10:51:02 2019
>> > @@ -0,0 +1,29 @@
>> > +; ModuleID = 'b.obj'
>> > +source_filename = "b.cpp"
>> > +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
>> > +target triple = "x86_64-pc-windows-msvc19.21.27702"
>> > +
>> > +%struct.S = type { i32 (...)** }
>> > +
>> > +; Function Attrs: norecurse nounwind readnone sspstrong uwtable
>> > +define dso_local void @"?foo at S@@UEAAXXZ"(%struct.S* nocapture %this) unnamed_addr #0 align 2 {
>> > +entry:
>> > +  ret void
>> > +}
>> > +
>> > +attributes #0 = { norecurse nounwind readnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
>> > +
>> > +!llvm.linker.options = !{!0, !1}
>> > +!llvm.module.flags = !{!2, !3, !4, !5}
>> > +!llvm.ident = !{!6}
>> > +
>> > +!0 = !{!"/DEFAULTLIB:libcmt.lib"}
>> > +!1 = !{!"/DEFAULTLIB:oldnames.lib"}
>> > +!2 = !{i32 1, !"wchar_size", i32 2}
>> > +!3 = !{i32 7, !"PIC Level", i32 2}
>> > +!4 = !{i32 1, !"ThinLTO", i32 0}
>> > +!5 = !{i32 1, !"EnableSplitLTOUnit", i32 0}
>> > +!6 = !{!"clang version 9.0.0 (git at github.com:llvm/llvm-project.git 1a285c27fdf6407ceed3398e015d00559f5f533d)"}
>> > +
>> > +^0 = module: (path: "b.obj", hash: (0, 0, 0, 0, 0))
>> > +^1 = gv: (name: "?foo at S@@UEAAXXZ", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 1, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0)))) ; guid = 6578172636330484861
>> >
>> > Added: lld/trunk/test/COFF/undefined-symbol-lto.test
>> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/undefined-symbol-lto.test?rev=366095&view=auto
>> > ==============================================================================
>> > --- lld/trunk/test/COFF/undefined-symbol-lto.test (added)
>> > +++ lld/trunk/test/COFF/undefined-symbol-lto.test Mon Jul 15 10:51:02 2019
>> > @@ -0,0 +1,29 @@
>> > +RUN: rm -rf %t && mkdir -p %t && cd %t
>> > +RUN: llvm-as %S/Inputs/undefined-symbol-lto-a.ll -o t.obj
>> > +RUN: llvm-as %S/Inputs/undefined-symbol-lto-b.ll -o b.obj
>> > +RUN: llvm-lib b.obj -out:b.lib
>> > +RUN: not lld-link -entry:main -nodefaultlib t.obj b.lib -subsystem:console 2>&1 | FileCheck %s
>> > +
>> > +CHECK: undefined symbol: main
>> > +CHECK: undefined symbol: void __cdecl undefined_ref(void)
>> > +CHECK: referenced by
>> > +
>> > +Originally reported as PR42536.
>> > +
>> > +a.ll corresponds to this C++:
>> > +
>> > +struct __declspec(dllimport) S {
>> > +  virtual void foo();
>> > +};
>> > +void undefined_ref();
>> > +struct Init {
>> > +  Init() { undefined_ref(); }
>> > +  S c;
>> > +} d;
>> > +
>> > +b.ll is from this C++:
>> > +
>> > +struct S {
>> > +  virtual void foo();
>> > +};
>> > +void S::foo() {}
>> >
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at lists.llvm.org
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list