Skip to content

Commit 1272c06

Browse files
samitolvanenmemfrob
authored andcommitted
ThinLTO: Fix inline assembly references to static functions with CFI
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. This version uses module inline assembly to avoid issues with LowerTypeTestsModule. Link: ClangBuiltLinux/linux#1354 Reviewed By: nickdesaulniers, pcc Differential Revision: https://reviews.llvm.org/D104058
1 parent 59cee32 commit 1272c06

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
5555
}
5656
}
5757

58+
std::string OldName = Name.str();
5859
std::string NewName = (Name + ModuleId).str();
5960

6061
if (const auto *C = ExportGV.getComdat())
@@ -69,6 +70,13 @@ void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
6970
ImportGV->setName(NewName);
7071
ImportGV->setVisibility(GlobalValue::HiddenVisibility);
7172
}
73+
74+
if (Function *F = dyn_cast<Function>(&ExportGV)) {
75+
// Create a local alias with the original name to avoid breaking
76+
// references from inline assembly.
77+
std::string Alias = ".set " + OldName + "," + NewName + "\n";
78+
ExportM.appendModuleInlineAsm(Alias);
79+
}
7280
}
7381

7482
if (!RenamedComdats.empty())

llvm/test/ThinLTO/X86/devirt2.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@
131131
; RUN: -r=%t1.o,_ZN1D1mEi, \
132132
; RUN: -r=%t1.o,test2, \
133133
; RUN: -r=%t2.o,_ZN1A1nEi,p \
134+
; RUN: -r=%t2.o,_ZN1A1nEi, \
134135
; RUN: -r=%t2.o,_ZN1B1fEi,p \
135136
; RUN: -r=%t2.o,_ZN1C1fEi,p \
136137
; RUN: -r=%t2.o,_ZN1D1mEi,p \
137138
; RUN: -r=%t2.o,_ZN1E1mEi,p \
139+
; RUN: -r=%t2.o,_ZN1E1mEi, \
138140
; RUN: -r=%t2.o,_ZTV1B, \
139141
; RUN: -r=%t2.o,_ZTV1C, \
140142
; RUN: -r=%t2.o,_ZTV1D, \
@@ -167,10 +169,12 @@
167169
; RUN: -r=%t1.o,_ZN1D1mEi, \
168170
; RUN: -r=%t1.o,test2, \
169171
; RUN: -r=%t2.o,_ZN1A1nEi,p \
172+
; RUN: -r=%t2.o,_ZN1A1nEi, \
170173
; RUN: -r=%t2.o,_ZN1B1fEi,p \
171174
; RUN: -r=%t2.o,_ZN1C1fEi,p \
172175
; RUN: -r=%t2.o,_ZN1D1mEi,p \
173176
; RUN: -r=%t2.o,_ZN1E1mEi,p \
177+
; RUN: -r=%t2.o,_ZN1E1mEi, \
174178
; RUN: -r=%t2.o,_ZTV1B, \
175179
; RUN: -r=%t2.o,_ZTV1C, \
176180
; RUN: -r=%t2.o,_ZTV1D, \
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o - %s | llvm-modextract -b -n 0 -o - | llvm-dis | FileCheck %s
2+
3+
target triple = "x86_64-unknown-linux-gnu"
4+
5+
; CHECK: module asm ".set a,a.[[HASH:[0-9a-f]+]]"
6+
7+
define void @b() {
8+
%f = alloca void ()*, align 8
9+
; CHECK: store{{.*}} @a.[[HASH]],{{.*}} %f
10+
store void ()* @a, void ()** %f, align 8
11+
; CHECK: %1 = call void ()* asm sideeffect "leaq a(%rip)
12+
%1 = call void ()* asm sideeffect "leaq a(%rip), $0\0A\09", "=r,~{dirflag},~{fpsr},~{flags}"()
13+
ret void
14+
}
15+
16+
; CHECK: define{{.*}} @a.[[HASH]](){{.*}} !type
17+
define internal void @a() !type !0 {
18+
ret void
19+
}
20+
21+
!0 = !{i64 0, !"typeid1"}

llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
; RUN: llvm-bcanalyzer -dump %t0 | FileCheck --check-prefix=BCA0 %s
88
; RUN: llvm-bcanalyzer -dump %t1 | FileCheck --check-prefix=BCA1 %s
99

10+
target triple = "x86_64-unknown-linux-gnu"
11+
1012
; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s)
1113

1214
; BCA0: <GLOBALVAL_SUMMARY_BLOCK

llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
33
; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
44

5+
target triple = "x86_64-unknown-linux-gnu"
6+
57
define [1 x i8*]* @source() {
68
ret [1 x i8*]* @g
79
}

0 commit comments

Comments
 (0)