[llvm-branch-commits] [llvm-branch] r287906 - Merging r287353:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 24 17:47:20 PST 2016


Author: tstellar
Date: Thu Nov 24 19:47:20 2016
New Revision: 287906

URL: http://llvm.org/viewvc/llvm-project?rev=287906&view=rev
Log:
Merging r287353:

------------------------------------------------------------------------
r287353 | hans | 2016-11-18 09:33:05 -0800 (Fri, 18 Nov 2016) | 12 lines

IRMover: Avoid accidentally mapping types from the destination module (PR30799)

During Module linking, it's possible for SrcM->getIdentifiedStructTypes();
to return types that are actually defined in the destination module
(DstM). Depending on how the bitcode file was read,
getIdentifiedStructTypes() might do a walk over all values, including
metadata nodes, looking for types. In my case, a debug info metadata
node was shared between the two modules, and it referred to a type
defined in the destination module (see test case).

Differential Revision: https://reviews.llvm.org/D26212

------------------------------------------------------------------------

Added:
    llvm/branches/release_39/test/LTO/X86/Inputs/type-mapping-src.ll
    llvm/branches/release_39/test/LTO/X86/type-mapping-bug.ll
Modified:
    llvm/branches/release_39/lib/Linker/IRMover.cpp

Modified: llvm/branches/release_39/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Linker/IRMover.cpp?rev=287906&r1=287905&r2=287906&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Linker/IRMover.cpp (original)
+++ llvm/branches/release_39/lib/Linker/IRMover.cpp Thu Nov 24 19:47:20 2016
@@ -694,6 +694,14 @@ void IRLinker::computeTypeMapping() {
     if (!ST->hasName())
       continue;
 
+    if (TypeMap.DstStructTypesSet.hasType(ST)) {
+      // This is actually a type from the destination module.
+      // getIdentifiedStructTypes() can have found it by walking debug info
+      // metadata nodes, some of which get linked by name when ODR Type Uniquing
+      // is enabled on the Context, from the source to the destination module.
+      continue;
+    }
+
     // Check to see if there is a dot in the name followed by a digit.
     size_t DotPos = ST->getName().rfind('.');
     if (DotPos == 0 || DotPos == StringRef::npos ||

Added: llvm/branches/release_39/test/LTO/X86/Inputs/type-mapping-src.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/LTO/X86/Inputs/type-mapping-src.ll?rev=287906&view=auto
==============================================================================
--- llvm/branches/release_39/test/LTO/X86/Inputs/type-mapping-src.ll (added)
+++ llvm/branches/release_39/test/LTO/X86/Inputs/type-mapping-src.ll Thu Nov 24 19:47:20 2016
@@ -0,0 +1,20 @@
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+%SrcType = type { i8 }
+ at x = external global %SrcType
+
+%CommonStruct = type opaque
+ at bar = internal global %CommonStruct* null, !dbg !0
+
+
+!llvm.dbg.cu = !{!1}
+!llvm.module.flags = !{!12}
+!0 = distinct !DIGlobalVariable(name: "bar", linkageName: "bar", scope: !1, file: !2, line: 2, type: !5, isLocal: false, isDefinition: true)
+!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
+!2 = !DIFile(filename: "b", directory: "/")
+!3 = !{}
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
+!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !2, line: 1, flags: DIFlagFwdDecl, identifier: ".?AUS@@")
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+

Added: llvm/branches/release_39/test/LTO/X86/type-mapping-bug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/LTO/X86/type-mapping-bug.ll?rev=287906&view=auto
==============================================================================
--- llvm/branches/release_39/test/LTO/X86/type-mapping-bug.ll (added)
+++ llvm/branches/release_39/test/LTO/X86/type-mapping-bug.ll Thu Nov 24 19:47:20 2016
@@ -0,0 +1,50 @@
+; RUN: llvm-as -o %t.dst.bc %s
+; RUN: llvm-as -o %t.src.bc %S/Inputs/type-mapping-src.ll
+; RUN: llvm-lto %t.dst.bc %t.src.bc -o=/dev/null
+
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+; @x in Src will be linked with this @x, causing SrcType in Src to be mapped
+; to %DstType.
+%DstType = type { i8 }
+ at x = global %DstType zeroinitializer
+
+; The Src module will re-use our DINode for this type.
+%CommonStruct = type { i32 }
+ at foo = internal global %CommonStruct zeroinitializer, !dbg !5
+
+; That DINode will refer to this value, casted to %Tricky.1* (!11),
+; which will then show up in Src's getIdentifiedStructTypes().
+ at templateValueParam = global i8 zeroinitializer
+
+; Because of the names, we would try to map %Tricky.1 to %Tricky --
+; mapping a Dst type to another Dst type! This would assert when
+; getting a mapping from %DstType, which has previously used as
+; a destination type. Since these types are not in the source module,
+; there should be no attempt to create a mapping involving them;
+; both types should be left as they are.
+%Tricky = type opaque
+%Tricky.1 = type { %DstType* }
+
+
+; Mark %Tricky used.
+ at use = global %Tricky* zeroinitializer
+
+!llvm.dbg.cu = !{!1}
+!llvm.module.flags = !{!19}
+!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
+!2 = !DIFile(filename: "a", directory: "/")
+!3 = !{}
+!4 = !{!5}
+!5 = distinct !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1, file: !2, line: 5, type: !6, isLocal: false, isDefinition: true)
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !2, line: 5, size: 8, elements: !7, identifier: ".?AUS@@")
+!7 = !{!8}
+!8 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !6, baseType: !9)
+!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Template<&x>", file: !2, line: 3, size: 8, elements: !3, templateParams: !10, identifier: ".?AU?$Template@$1?x@@3UX@@A@@")
+!10 = !{!11}
+
+!11 = !DITemplateValueParameter(type: !12, value: %Tricky.1* bitcast (i8* @templateValueParam to %Tricky.1*))
+
+!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
+!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", file: !2, line: 1, size: 8, elements: !3, identifier: ".?AUX@@")
+!19 = !{i32 2, !"Debug Info Version", i32 3}




More information about the llvm-branch-commits mailing list