[llvm] 1442b18 - [X86] Properly inherit all section flags from parent for basic block sections (#219289)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 19:03:13 PDT 2026


Author: Arthur Eubanks
Date: 2026-08-27T19:03:07-07:00
New Revision: 1442b18697a1b702410a07ad4a3b80d964c0cf89

URL: https://github.com/llvm/llvm-project/commit/1442b18697a1b702410a07ad4a3b80d964c0cf89
DIFF: https://github.com/llvm/llvm-project/commit/1442b18697a1b702410a07ad4a3b80d964c0cf89.diff

LOG: [X86] Properly inherit all section flags from parent for basic block sections (#219289)

Or else we miss flags like SHF_X86_64_LARGE.

Added: 
    

Modified: 
    llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/test/CodeGen/X86/code-model-elf-text-sections.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index f01537488c361..4643ef995afec 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1154,7 +1154,9 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
     UniqueID = NextUniqueID++;
   }
 
-  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
+  unsigned Flags =
+      static_cast<const MCSectionELF *>(MBB.getParent()->getSection())
+          ->getFlags();
   std::string GroupName;
   if (F.hasComdat()) {
     Flags |= ELF::SHF_GROUP;

diff  --git a/llvm/test/CodeGen/X86/code-model-elf-text-sections.ll b/llvm/test/CodeGen/X86/code-model-elf-text-sections.ll
index 66a6fd3767542..26d15da3389c6 100644
--- a/llvm/test/CodeGen/X86/code-model-elf-text-sections.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf-text-sections.ll
@@ -11,6 +11,8 @@
 ; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL-DS
 ; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=large -function-sections -o %t
 ; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE-DS
+; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=large -function-sections -basic-block-sections=all -o %t
+; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE-BB
 
 ; SMALL: .text {{.*}} AX {{.*}}
 ; SMALL: .ltext {{.*}} AXl {{.*}}
@@ -28,6 +30,10 @@
 ; LARGE-DS: .ltext.2 {{.*}} AXl {{.*}}
 ; LARGE-DS: .foo {{.*}} AX {{.*}}
 
+; LARGE-BB: .ltext.func_bb {{.*}} AXl {{.*}}
+; LARGE-BB: .ltext.func_bb {{.*}} AXl {{.*}}
+; LARGE-BB: .ltext.func_bb {{.*}} AXl {{.*}}
+
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64--linux"
 
@@ -46,3 +52,15 @@ define void @ltext2() section ".ltext.2" {
 define void @foo() section ".foo" {
   ret void
 }
+
+define i32 @func_bb(i32 %x) {
+entry:
+  %tobool = icmp ne i32 %x, 0
+  br i1 %tobool, label %if.then, label %if.end
+
+if.then:
+  ret i32 1
+
+if.end:
+  ret i32 0
+}


        


More information about the llvm-commits mailing list