diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2016-11-25 01:47:20 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2016-11-25 01:47:20 +0000 |
commit | 04aa3b87f6d971a8058cd6c27b73f357b52b3d65 (patch) | |
tree | 588ada7889eef697057f681e7d97919cc9a70c17 | |
parent | cdf53e333c9dda94c43cda57b0892f7ec2c16e57 (diff) | |
download | llvm-04aa3b87f6d971a8058cd6c27b73f357b52b3d65.zip llvm-04aa3b87f6d971a8058cd6c27b73f357b52b3d65.tar.gz llvm-04aa3b87f6d971a8058cd6c27b73f357b52b3d65.tar.bz2 |
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
------------------------------------------------------------------------
llvm-svn: 287906
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 8 | ||||
-rw-r--r-- | llvm/test/LTO/X86/Inputs/type-mapping-src.ll | 20 | ||||
-rw-r--r-- | llvm/test/LTO/X86/type-mapping-bug.ll | 50 |
3 files changed, 78 insertions, 0 deletions
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 0c26808..09c67bc 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -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 || diff --git a/llvm/test/LTO/X86/Inputs/type-mapping-src.ll b/llvm/test/LTO/X86/Inputs/type-mapping-src.ll new file mode 100644 index 0000000..3a80560 --- /dev/null +++ b/llvm/test/LTO/X86/Inputs/type-mapping-src.ll @@ -0,0 +1,20 @@ +target triple = "x86_64-pc-windows-msvc18.0.0" + +%SrcType = type { i8 } +@x = external global %SrcType + +%CommonStruct = type opaque +@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} + diff --git a/llvm/test/LTO/X86/type-mapping-bug.ll b/llvm/test/LTO/X86/type-mapping-bug.ll new file mode 100644 index 0000000..3a18912 --- /dev/null +++ b/llvm/test/LTO/X86/type-mapping-bug.ll @@ -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 } +@x = global %DstType zeroinitializer + +; The Src module will re-use our DINode for this type. +%CommonStruct = type { i32 } +@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(). +@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. +@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} |