[llvm] [MC] Remove unused pre-created .llvm.callgraph section (PR #224369)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 19:53:23 PDT 2026
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/224369
>From ba1d3d6c93df9896fbeac385aaa42365fc651d5d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 17 Sep 2026 10:10:30 -0700
Subject: [PATCH 1/3] [MC] Remove unused pre-created .llvm.callgraph section
getCallGraphSection always creates a per-function SHF_LINK_ORDER
section, so the pre-created one is unused. Its only effect is that
hand-written `.section .llvm.callgraph` silently gets
`SHT_LLVM_CALL_GRAPH`, while the same directive within a group (e.g.
`.pushsection .llvm.callgraph,"?"` after a group member) gets
SHT_PROGBITS.
Remove it so that an omitted type gives SHT_PROGBITS in both cases, like
GNU assembler. Specify `%llvm_call_graph` to get SHT_LLVM_CALL_GRAPH.
---
llvm/include/llvm/MC/MCObjectFileInfo.h | 3 ---
llvm/lib/MC/MCObjectFileInfo.cpp | 5 +---
llvm/test/MC/ELF/section-callgraph.s | 35 +++++++++++++++++++++++++
3 files changed, 36 insertions(+), 7 deletions(-)
create mode 100644 llvm/test/MC/ELF/section-callgraph.s
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index d10411b56517d..feb90cd376194 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -69,9 +69,6 @@ class LLVM_ABI MCObjectFileInfo {
/// Language Specific Data Area information is emitted to.
MCSection *LSDASection = nullptr;
- /// Section containing call graph metadata.
- MCSection *CallGraphSection = nullptr;
-
/// If exception handling is supported by the target and the target can
/// support a compact representation of the CIE and FDE, this is the section
/// to emit them into.
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 65534186edbac..5dd5a63fda9cf 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -563,9 +563,6 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
SFrameSection =
Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
- CallGraphSection =
- Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 0);
-
StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
@@ -1257,7 +1254,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
MCSection *
MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const {
if (Ctx->getObjectFileType() != MCContext::IsELF)
- return CallGraphSection;
+ return nullptr;
const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
unsigned Flags = ELF::SHF_LINK_ORDER;
diff --git a/llvm/test/MC/ELF/section-callgraph.s b/llvm/test/MC/ELF/section-callgraph.s
new file mode 100644
index 0000000000000..67928c6cb2374
--- /dev/null
+++ b/llvm/test/MC/ELF/section-callgraph.s
@@ -0,0 +1,35 @@
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: llvm-readelf -S a.o | FileCheck %s --check-prefix=PROGBITS
+# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
+# RUN: llvm-readelf -S b.o | FileCheck %s --check-prefix=TYPED
+
+## Like GNU assembler, .llvm.callgraph without a type is SHT_PROGBITS, whether or
+## not "?" inherits a group. Specify %llvm_call_graph for SHT_LLVM_CALL_GRAPH.
+# PROGBITS: .llvm.callgraph PROGBITS 0000000000000000 {{.*}} 000001 00 0 0 1
+# PROGBITS: .llvm.callgraph PROGBITS 0000000000000000 {{.*}} 000001 00 G 0 0 1
+
+# TYPED: .llvm.callgraph LLVM_CALL_GRAPH 0000000000000000 {{.*}} 000001 00 0 0 1
+# TYPED: .llvm.callgraph LLVM_CALL_GRAPH 0000000000000000 {{.*}} 000001 00 G 0 0 1
+
+#--- a.s
+.section .text,"ax",%progbits
+.pushsection .llvm.callgraph,"?"
+.byte 0
+.popsection
+
+.section .text.g,"axG",%progbits,g
+.pushsection .llvm.callgraph,"?"
+.byte 0
+.popsection
+
+#--- b.s
+.section .text,"ax",%progbits
+.pushsection .llvm.callgraph,"?",%llvm_call_graph
+.byte 0
+.popsection
+
+.section .text.g,"axG",%progbits,g
+.pushsection .llvm.callgraph,"?",%llvm_call_graph
+.byte 0
+.popsection
>From 18a3da94672c6c459d18d62fe33def5a8f8bfe65 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 17 Sep 2026 19:52:24 -0700
Subject: [PATCH 2/3] improve test
---
llvm/test/MC/ELF/section-callgraph.s | 29 ++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/llvm/test/MC/ELF/section-callgraph.s b/llvm/test/MC/ELF/section-callgraph.s
index 67928c6cb2374..e9cfbfa0d5209 100644
--- a/llvm/test/MC/ELF/section-callgraph.s
+++ b/llvm/test/MC/ELF/section-callgraph.s
@@ -2,7 +2,9 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
# RUN: llvm-readelf -S a.o | FileCheck %s --check-prefix=PROGBITS
# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
-# RUN: llvm-readelf -S b.o | FileCheck %s --check-prefix=TYPED
+# RUN: llvm-readelf -S b.o | FileCheck %s --check-prefix=PROGBITS
+# RUN: llvm-mc -filetype=obj -triple=x86_64 c.s -o c.o
+# RUN: llvm-readelf -S c.o | FileCheck %s --check-prefix=TYPED
## Like GNU assembler, .llvm.callgraph without a type is SHT_PROGBITS, whether or
## not "?" inherits a group. Specify %llvm_call_graph for SHT_LLVM_CALL_GRAPH.
@@ -13,23 +15,38 @@
# TYPED: .llvm.callgraph LLVM_CALL_GRAPH 0000000000000000 {{.*}} 000001 00 G 0 0 1
#--- a.s
+.pushsection .llvm.callgraph,""
+ .byte 0
+.popsection
+
+.section .text.g,"axG",%progbits,g
+g:
+.pushsection .llvm.callgraph,"?"
+ .byte 0
+.popsection
+
+#--- b.s
.section .text,"ax",%progbits
+ ret
+
.pushsection .llvm.callgraph,"?"
-.byte 0
+ .byte 0
.popsection
.section .text.g,"axG",%progbits,g
+g:
.pushsection .llvm.callgraph,"?"
-.byte 0
+ .byte 0
.popsection
-#--- b.s
+#--- c.s
.section .text,"ax",%progbits
.pushsection .llvm.callgraph,"?",%llvm_call_graph
-.byte 0
+ .byte 0
.popsection
.section .text.g,"axG",%progbits,g
+g:
.pushsection .llvm.callgraph,"?",%llvm_call_graph
-.byte 0
+ .byte 0
.popsection
>From d3c2a2cf4e99dd2f265888e170194d8a8a46c1ae Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 17 Sep 2026 19:53:11 -0700
Subject: [PATCH 3/3] improve test, add @ nuance
---
llvm/test/MC/ELF/section-callgraph.s | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/MC/ELF/section-callgraph.s b/llvm/test/MC/ELF/section-callgraph.s
index e9cfbfa0d5209..d43e14b77bb44 100644
--- a/llvm/test/MC/ELF/section-callgraph.s
+++ b/llvm/test/MC/ELF/section-callgraph.s
@@ -47,6 +47,6 @@ g:
.section .text.g,"axG",%progbits,g
g:
-.pushsection .llvm.callgraph,"?",%llvm_call_graph
+.pushsection .llvm.callgraph,"?", at llvm_call_graph
.byte 0
.popsection
More information about the llvm-commits
mailing list