[llvm-dev] ThinLTO Bug ?

via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 30 06:52:05 PDT 2018



> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Xin
> Tong via llvm-dev
> Sent: Friday, July 27, 2018 9:33 PM
> To: llvm-dev
> Subject: [llvm-dev] ThinLTO Bug ?
> 
> Hi
> 
> I have encountered a module verification failure when running 2 files
> with thin-lto (I hit this bug in the link step in LTO on a really
> large program and I reduced to this test case).
> 
> 
> ~/llvmfb/build-debug/bin/llvm-lto2 run -o c a.o  b.o -r a.o,c,px  -r
> b.o,a,px -r b.o,b,px  -r a.o,gv -r b.o,gv
> Called function is not the same type as the call!
> %2 = call i1 bitcast (i1 (%struct.TA*)* @b to i1 (%0*)*)(%struct.TA* %0)
> in function a
> LLVM ERROR: Broken function found, compilation aborted!
> 
> 
> My understanding why this is happening is roughly as follow. I would
> like to check with people whether this is a real bug. And also would
> like to help fixing it with other people’s help if it’s a real bug. I
> am quite new to this part of LLVM.
> 
> 1. DICompositeType “SHARED” in a.ll is ODRed with the one in b.ll at load
> time.

I know relatively little about LTO but I see that in a.ll, "SHARED" is
described as a DW_TAG_class_type while in b.ll it is DW_TAG_array_type.
This suggests that you have an ODR violation in your source code.

ODR violations in LTO tend to exhibit as a "broken module" or "broken
function" at link time.  It would be nice to diagnose these better,
admittedly.
--paulr

> 2. %struct.TA.0 (renamed from %struct.TA at load time) = type opaque
> and i1 (%struct.TA.0*)* @b  in b.ll gets pulled into the destination
> module when we are merging in a.ll.
> 3. We only found out that %struct.TA.0 maps to %struct.TA when we link
> in b.ll because of the @gv global variable.
> 4. Then we have a problem, because declare i1 @b(%struct.TA.0*) in
> a.ll should have been remapped due to what we found in #3, but was
> not.  This eventually leads to the IR verifier failure.
> 
> Thanks
> -Xin
> 
> 
> Commands to reproduce with ToT LLVM:
> ===============================
> 
> ~/llvm/build-debug/bin/opt -module-summary -o a.o a.ll
> ~/llvm/build-debug/bin/opt -module-summary -o b.o b.ll
> ~/llvm/build-debug/bin/llvm-lto2 run -o c a.o b.o -r a.o,c,px -r
> b.o,a,px -r b.o,b,px -r a.o,gv -r b.o,gv
> 
> 
> 
> [~/thinltobug]$ cat a.ll
> 
> target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> 
> target triple = "x86_64-unknown-linux-gnu"
> 
> %struct.TA = type {}
> 
> 
> 
> @gv = dso_local global %struct.TA * zeroinitializer
> 
> define i32 @c() !dbg !6 {
> 
>   bitcast %struct.TA ** @gv to i8*
> 
>   unreachable
> 
> }
> 
> 
> 
> 
> 
> !llvm.module.flags = !{!0, !1}
> 
> !llvm.dbg.cu = !{!2}
> 
> !0 = !{i32 2, !"Debug Info Version", i32 3}
> 
> !1 = !{i32 1, !"ThinLTO", i32 0}
> 
> !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,
> retainedTypes: !4)
> 
> !3 = !DIFile(filename: "f2", directory: "")
> 
> !4 = !{!5}
> 
> !5 = !DICompositeType(tag: DW_TAG_class_type, file: !3, flags:
> DIFlagFwdDecl, identifier: "SHARED")
> 
> !6 = distinct !DISubprogram(unit: !2)
> 
> 
> 
> [~/thinltobug]$ cat b.ll
> 
> target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> 
> target triple = "x86_64-unknown-linux-gnu"
> 
> 
> 
> %struct.TA = type opaque
> 
> 
> 
> @gv = external dso_local global %struct.TA *
> 
> 
> 
> define i1 @b(%struct.TA*) {
> 
>   unreachable
> 
> }
> 
> 
> 
> define i1 @a(%struct.TA* %a) {
> 
>   call i1 @b(%struct.TA* %a)
> 
>   unreachable
> 
> }
> 
> 
> 
> !llvm.module.flags = !{!0, !1}
> 
> !llvm.dbg.cu = !{!2}
> 
> !0 = !{i32 2, !"Debug Info Version", i32 3}
> 
> !1 = !{i32 1, !"ThinLTO", i32 0}
> 
> !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,
> retainedTypes: !4)
> 
> !3 = !DIFile(filename: "f1", directory: "")
> 
> !4 = !{!5, !9}
> 
> !5 = !DICompositeType(tag: DW_TAG_class_type, file: !3,
> templateParams: !6, scope: !8)
> 
> !6 = !{!7}
> 
> 
> 
> ; The reference to @b and struct.TA.0 (renamed)  that will be loaded in
> %a.o
> 
> 
> 
> !7 = !DITemplateValueParameter(value: i1 (%struct.TA*)* @b)
> 
> !8 = distinct !DISubprogram(unit: !2)
> 
> 
> 
> !9 = !DICompositeType(tag: DW_TAG_array_type, identifier: "SHARED", scope:
> !8)
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list