[llvm] Linker flags for UEFI (#137878)

Use appropriate linker flag format to match PE spec for UEFI.
This commit is contained in:
Prabhu Rajasekaran
2025-04-30 12:14:58 -07:00
committed by GitHub
parent ea0e6e3383
commit 1531dfcb3a
5 changed files with 32 additions and 2 deletions

View File

@@ -215,7 +215,7 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
const Triple &TT, Mangler &Mangler) {
if (GV->hasDLLExportStorageClass() && !GV->isDeclaration()) {
if (TT.isWindowsMSVCEnvironment())
if (TT.isWindowsMSVCEnvironment() || TT.isUEFI())
OS << " /EXPORT:";
else
OS << " -export:";
@@ -249,7 +249,7 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
OS << "\"";
if (!GV->getValueType()->isFunctionTy()) {
if (TT.isWindowsMSVCEnvironment())
if (TT.isWindowsMSVCEnvironment() || TT.isUEFI())
OS << ",DATA";
else
OS << ",data";

View File

@@ -1,4 +1,5 @@
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
; RUN: llc -mtriple x86_64-pc-uefi < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck -check-prefix=CHECK -check-prefix=MINGW %s
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck -check-prefix=NOTEXPORTED %s
; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck -check-prefix=NOTEXPORTED %s

View File

@@ -2,6 +2,7 @@
; RUN: llc -mtriple i686-pc-win32 < %s | FileCheck %s --check-prefix=COFF
; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck %s --check-prefix=COFF64
; RUN: llc -mtriple x86_64-uefi < %s | FileCheck %s --check-prefix=COFF64
; RUN: llc -mtriple i686-linux-gnu < %s | FileCheck %s --check-prefix=ELF
; RUN: llc -mtriple i686-apple-darwin < %s | FileCheck %s --check-prefix=MACHO

View File

@@ -5,6 +5,13 @@
; RUN: llc -mtriple x86_64-pc-win32 \
; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s
; RUN: llc -mtriple x86_64-uefi \
; RUN: -relocation-model=static < %s | FileCheck --check-prefix=COFF_S %s
; RUN: llc -mtriple x86_64-uefi \
; RUN: -relocation-model=pic < %s | FileCheck --check-prefix=COFF %s
; RUN: llc -mtriple x86_64-uefi \
; RUN: -relocation-model=dynamic-no-pic < %s | FileCheck --check-prefix=COFF %s
; 32 bits

View File

@@ -134,6 +134,27 @@ TEST(ManglerTest, WindowsX64) {
"?vectorcall");
}
TEST(ManglerTest, UEFIX64) {
LLVMContext Ctx;
DataLayout DL("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
"i64:64-i128:128-f80:128-n8:16:32:64-S128"); // uefi X86_64
Module Mod("test", Ctx);
Mod.setDataLayout(DL);
Mangler Mang;
EXPECT_EQ(mangleStr("foo", Mang, DL), "foo");
EXPECT_EQ(mangleStr("\01foo", Mang, DL), "foo");
EXPECT_EQ(mangleStr("?foo", Mang, DL), "?foo");
EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::ExternalLinkage,
llvm::CallingConv::C, Mod, Mang),
"foo");
EXPECT_EQ(mangleFunc("?foo", llvm::GlobalValue::ExternalLinkage,
llvm::CallingConv::C, Mod, Mang),
"?foo");
EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::PrivateLinkage,
llvm::CallingConv::C, Mod, Mang),
".Lfoo");
}
TEST(ManglerTest, XCOFF) {
LLVMContext Ctx;
DataLayout DL("m:a"); // XCOFF/AIX