Skip to content

[llvm] Linker flags for UEFI #137878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/IR/Mangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:";
Expand Down Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/dllexport-x86_64.ll
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/mangle-question-mark.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions llvm/test/CodeGen/X86/win32-preemption.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions llvm/unittests/IR/ManglerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down