summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-07-19 18:18:19 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-07-19 18:18:19 +0000
commite776dd9ca2f8ce20fb50b8e179cc563826f3892d (patch)
treed25ca0fc36658757e283f78e8fe6372a746dd9f2
parent5fc5d0a4069e304597b04adb0ecc79a009684b75 (diff)
downloadbcm5719-llvm-e776dd9ca2f8ce20fb50b8e179cc563826f3892d.tar.gz
bcm5719-llvm-e776dd9ca2f8ce20fb50b8e179cc563826f3892d.zip
LTO: Export functions referenced by the CFI jump table.
If the LowerTypeTests pass decides to add a function to a jump table for CFI, it will add its name to the set cfiFunctionDefs, which among other things will cause the function to be renamed in the ThinLTO backend. One other thing that we must do with such functions is to not internalize them, because the jump table in the full LTO object will contain a reference to the actual function body in the ThinLTO object. This patch handles that by ensuring that we export any functions whose names appear in the cfiFunctionDefs set. Fixes PR33831. Differential Revision: https://reviews.llvm.org/D35605 llvm-svn: 308504
-rw-r--r--llvm/lib/LTO/LTO.cpp6
-rw-r--r--llvm/test/LTO/Resolution/X86/export-jumptable.ll32
2 files changed, 38 insertions, 0 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 19973946ac5..958151ad91b 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1072,6 +1072,12 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
ExportedGUIDs.insert(GUID);
}
+ // Any functions referenced by the jump table in the regular LTO object must
+ // be exported.
+ for (auto &Def : ThinLTO.CombinedIndex.cfiFunctionDefs())
+ ExportedGUIDs.insert(
+ GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Def)));
+
auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
const auto &ExportList = ExportLists.find(ModuleIdentifier);
return (ExportList != ExportLists.end() &&
diff --git a/llvm/test/LTO/Resolution/X86/export-jumptable.ll b/llvm/test/LTO/Resolution/X86/export-jumptable.ll
new file mode 100644
index 00000000000..1ab8c065014
--- /dev/null
+++ b/llvm/test/LTO/Resolution/X86/export-jumptable.ll
@@ -0,0 +1,32 @@
+; Test that we do not internalize functions that appear in the CFI jump table in
+; the full LTO object file; any such functions will be referenced by the jump
+; table.
+
+; RUN: opt -thinlto-bc -o %t %s
+; RUN: llvm-lto2 run -o %t2 -r %t,f1,p -r %t,f2,p -r %t,_start,px %t -save-temps
+; RUN: llvm-dis %t2.1.2.internalize.bc -o - | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: define void @f1()
+define void @f1() !type !0 {
+ ret void
+}
+
+; CHECK: define internal void @f2()
+define void @f2() !type !1 {
+ ret void
+}
+
+define i1 @_start(i8* %p) {
+ %1 = call i1 @llvm.type.test(i8* %p, metadata !"typeid1")
+ call void @f1()
+ call void @f2()
+ ret i1 %1
+}
+
+declare i1 @llvm.type.test(i8*, metadata)
+
+!0 = !{i64 0, !"typeid1"}
+!1 = !{i64 0, !"typeid2"}
OpenPOWER on IntegriCloud