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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 13:56:44 PDT 2026


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/219289

Or else we miss flags like SHF_X86_64_LARGE.

>From 36e299ae5724e54f718ad47c3ecfdc670ce8d382 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 16 Jun 2026 22:56:40 +0000
Subject: [PATCH] [X86] Properly inherit all section flags from parent for
 basic block sections

Or else we miss flags like SHF_X86_64_LARGE.
---
 .../CodeGen/TargetLoweringObjectFileImpl.cpp   |  4 +++-
 .../X86/code-model-elf-text-sections.ll        | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

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