[llvm] [llvm][ELF] Correctly set the .llvm.lto section type (PR #92820)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 13:58:58 PDT 2024


https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/92820

Support for the SHT_LLVM_LTO section type was added in
https://github.com/llvm/llvm-project/commit/a484e020d75d398049e1fcbeb0157d57011714b3,
but the `.llvm.lto` section type was never set. This patch sets the ELF
section type to SHT_LLVM_LTO for sections with a `.llvm.lto` prefix, which
should only be emitted when using FatLTO.


>From 6fd78a3386cd36a8df10ac3b995a9168667a6e27 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 20 May 2024 13:58:46 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 3 +++
 llvm/test/CodeGen/X86/fat-lto-section.ll          | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3e1897ce670a6..567e9443759f1 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -527,6 +527,9 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
   if (K.isBSS() || K.isThreadBSS())
     return ELF::SHT_NOBITS;
 
+  if(hasPrefix(Name, ".llvm.lto"))
+    return ELF::SHT_LLVM_LTO;
+
   return ELF::SHT_PROGBITS;
 }
 
diff --git a/llvm/test/CodeGen/X86/fat-lto-section.ll b/llvm/test/CodeGen/X86/fat-lto-section.ll
index 30c56229a0e2a..f3ca8436affb4 100644
--- a/llvm/test/CodeGen/X86/fat-lto-section.ll
+++ b/llvm/test/CodeGen/X86/fat-lto-section.ll
@@ -5,6 +5,6 @@
 ; RUN:   | FileCheck %s --check-prefix=EXCLUDE
 
 ; EXCLUDE: Name               Type     {{.*}} ES Flg Lk Inf Al
-; EXCLUDE: .llvm.lto          PROGBITS {{.*}} 00   E  0   0  1
+; EXCLUDE: .llvm.lto          LLVM_LTO {{.*}} 00   E  0   0  1
 
 @a = global i32 1



More information about the llvm-commits mailing list