[llvm] 1531dfc - [llvm] Linker flags for UEFI (#137878)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 12:15:01 PDT 2025


Author: Prabhu Rajasekaran
Date: 2025-04-30T12:14:58-07:00
New Revision: 1531dfcb3a953b7b3187bca7e58e4e18def58d7d

URL: https://github.com/llvm/llvm-project/commit/1531dfcb3a953b7b3187bca7e58e4e18def58d7d
DIFF: https://github.com/llvm/llvm-project/commit/1531dfcb3a953b7b3187bca7e58e4e18def58d7d.diff

LOG: [llvm] Linker flags for UEFI (#137878)

Use appropriate linker flag format to match PE spec for UEFI.

Added: 
    

Modified: 
    llvm/lib/IR/Mangler.cpp
    llvm/test/CodeGen/X86/dllexport-x86_64.ll
    llvm/test/CodeGen/X86/mangle-question-mark.ll
    llvm/test/CodeGen/X86/win32-preemption.ll
    llvm/unittests/IR/ManglerTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp
index 3b9c00cf993f3..010bd15e256dc 100644
--- a/llvm/lib/IR/Mangler.cpp
+++ b/llvm/lib/IR/Mangler.cpp
@@ -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";

diff  --git a/llvm/test/CodeGen/X86/dllexport-x86_64.ll b/llvm/test/CodeGen/X86/dllexport-x86_64.ll
index e6a6aa7567835..76add98314f5c 100644
--- a/llvm/test/CodeGen/X86/dllexport-x86_64.ll
+++ b/llvm/test/CodeGen/X86/dllexport-x86_64.ll
@@ -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

diff  --git a/llvm/test/CodeGen/X86/mangle-question-mark.ll b/llvm/test/CodeGen/X86/mangle-question-mark.ll
index fea62ecad97c9..67b2a50988d0a 100644
--- a/llvm/test/CodeGen/X86/mangle-question-mark.ll
+++ b/llvm/test/CodeGen/X86/mangle-question-mark.ll
@@ -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
 

diff  --git a/llvm/test/CodeGen/X86/win32-preemption.ll b/llvm/test/CodeGen/X86/win32-preemption.ll
index 77dcfa7280daf..24f4b34acacca 100644
--- a/llvm/test/CodeGen/X86/win32-preemption.ll
+++ b/llvm/test/CodeGen/X86/win32-preemption.ll
@@ -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
 

diff  --git a/llvm/unittests/IR/ManglerTest.cpp b/llvm/unittests/IR/ManglerTest.cpp
index a2b4e81690310..bced6ff10b45d 100644
--- a/llvm/unittests/IR/ManglerTest.cpp
+++ b/llvm/unittests/IR/ManglerTest.cpp
@@ -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


        


More information about the llvm-commits mailing list