Skip to content

Commit 1531dfc

Browse files
authored
[llvm] Linker flags for UEFI (llvm#137878)
Use appropriate linker flag format to match PE spec for UEFI.
1 parent ea0e6e3 commit 1531dfc

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

llvm/lib/IR/Mangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
215215
const Triple &TT, Mangler &Mangler) {
216216
if (GV->hasDLLExportStorageClass() && !GV->isDeclaration()) {
217217

218-
if (TT.isWindowsMSVCEnvironment())
218+
if (TT.isWindowsMSVCEnvironment() || TT.isUEFI())
219219
OS << " /EXPORT:";
220220
else
221221
OS << " -export:";
@@ -249,7 +249,7 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
249249
OS << "\"";
250250

251251
if (!GV->getValueType()->isFunctionTy()) {
252-
if (TT.isWindowsMSVCEnvironment())
252+
if (TT.isWindowsMSVCEnvironment() || TT.isUEFI())
253253
OS << ",DATA";
254254
else
255255
OS << ",data";

llvm/test/CodeGen/X86/dllexport-x86_64.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
2+
; RUN: llc -mtriple x86_64-pc-uefi < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
23
; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck -check-prefix=CHECK -check-prefix=MINGW %s
34
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck -check-prefix=NOTEXPORTED %s
45
; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck -check-prefix=NOTEXPORTED %s

llvm/test/CodeGen/X86/mangle-question-mark.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
; RUN: llc -mtriple i686-pc-win32 < %s | FileCheck %s --check-prefix=COFF
44
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck %s --check-prefix=COFF64
5+
; RUN: llc -mtriple x86_64-uefi < %s | FileCheck %s --check-prefix=COFF64
56
; RUN: llc -mtriple i686-linux-gnu < %s | FileCheck %s --check-prefix=ELF
67
; RUN: llc -mtriple i686-apple-darwin < %s | FileCheck %s --check-prefix=MACHO
78

llvm/test/CodeGen/X86/win32-preemption.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
; RUN: llc -mtriple x86_64-pc-win32 \
66
; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s
77

8+
; RUN: llc -mtriple x86_64-uefi \
9+
; RUN: -relocation-model=static < %s | FileCheck --check-prefix=COFF_S %s
10+
; RUN: llc -mtriple x86_64-uefi \
11+
; RUN: -relocation-model=pic < %s | FileCheck --check-prefix=COFF %s
12+
; RUN: llc -mtriple x86_64-uefi \
13+
; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s
14+
815

916
; 32 bits
1017

llvm/unittests/IR/ManglerTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ TEST(ManglerTest, WindowsX64) {
134134
"?vectorcall");
135135
}
136136

137+
TEST(ManglerTest, UEFIX64) {
138+
LLVMContext Ctx;
139+
DataLayout DL("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
140+
"i64:64-i128:128-f80:128-n8:16:32:64-S128"); // uefi X86_64
141+
Module Mod("test", Ctx);
142+
Mod.setDataLayout(DL);
143+
Mangler Mang;
144+
EXPECT_EQ(mangleStr("foo", Mang, DL), "foo");
145+
EXPECT_EQ(mangleStr("\01foo", Mang, DL), "foo");
146+
EXPECT_EQ(mangleStr("?foo", Mang, DL), "?foo");
147+
EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::ExternalLinkage,
148+
llvm::CallingConv::C, Mod, Mang),
149+
"foo");
150+
EXPECT_EQ(mangleFunc("?foo", llvm::GlobalValue::ExternalLinkage,
151+
llvm::CallingConv::C, Mod, Mang),
152+
"?foo");
153+
EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::PrivateLinkage,
154+
llvm::CallingConv::C, Mod, Mang),
155+
".Lfoo");
156+
}
157+
137158
TEST(ManglerTest, XCOFF) {
138159
LLVMContext Ctx;
139160
DataLayout DL("m:a"); // XCOFF/AIX

0 commit comments

Comments
 (0)