[llvm] 0ab3502 - [RISC-V][MC] Fix mapping symbol section tracking on popSection() (#225131)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 26 19:02:03 PDT 2026
Author: Alexander Richardson
Date: 2026-09-26T19:01:58-07:00
New Revision: 0ab3502ec56a5d8330c79849945b9fefd2668f01
URL: https://github.com/llvm/llvm-project/commit/0ab3502ec56a5d8330c79849945b9fefd2668f01
DIFF: https://github.com/llvm/llvm-project/commit/0ab3502ec56a5d8330c79849945b9fefd2668f01.diff
LOG: [RISC-V][MC] Fix mapping symbol section tracking on popSection() (#225131)
Previously, RISCVELFStreamer::changeSection() saved LastEMS and LastEmittedArch
under getPreviousSection().first instead of getCurrentSection().first. When
MCStreamer::popSection() switches back to a previous section,
getPreviousSection() already points to the destination section being restored
rather than the section being exited. This clobbered the destination section's
saved mapping symbol state and caused duplicate `$x<arch>` mapping symbols to
be emitted whenever returning to `.text`.
Use getCurrentSection().first instead, matching AArch64ELFStreamer and
ARMELFStreamer.
This commit was created with the help of AI tools
Pull-Request: https://github.com/llvm/llvm-project/pull/225131
Added:
Modified:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
llvm/test/MC/RISCV/mapping-across-sections.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index 524d0bb79d5f8..10702a836de33 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -218,9 +218,9 @@ void RISCVELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
// default constructor by DenseMap::lookup. The last ISA suffix emitted in
// each section is also preserved so that re-entering a section only emits a
// new "$x<ISA>" symbol when the active ISA has actually changed.
- const MCSection *Prev = getPreviousSection().first;
- LastMappingSymbols[Prev] = LastEMS;
- LastEmittedArchInSection[Prev] = LastEmittedArch;
+ const MCSection *Cur = getCurrentSection().first;
+ LastMappingSymbols[Cur] = LastEMS;
+ LastEmittedArchInSection[Cur] = LastEmittedArch;
LastEMS = LastMappingSymbols.lookup(Section);
auto It = LastEmittedArchInSection.find(Section);
LastEmittedArch = It != LastEmittedArchInSection.end() ? It->second : "";
diff --git a/llvm/test/MC/RISCV/mapping-across-sections.s b/llvm/test/MC/RISCV/mapping-across-sections.s
index 9a741e792a244..54c420085da12 100644
--- a/llvm/test/MC/RISCV/mapping-across-sections.s
+++ b/llvm/test/MC/RISCV/mapping-across-sections.s
@@ -35,10 +35,7 @@
# CHECK: [[#WIBBLE:]]] .wibble
# CHECK: [[#STARTS_DATA:]]] .starts_data
-## TODO: RISCVELFStreamer::changeSection saves mapping symbol state to
-## getPreviousSection() instead of getCurrentSection() on popSection(), causing
-## a duplicate $x mapping symbol at offset 8 in .text.
-# CHECK: Symbol table '.symtab' contains 5 entries:
+# CHECK: Symbol table '.symtab' contains 4 entries:
# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name
# CHECK-NEXT: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND {{$}}
# CHECK-RV32-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT [[#TEXT]] $xrv32i2p1{{$}}
@@ -46,6 +43,4 @@
# CHECK-RV32-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT [[#WIBBLE]] $xrv32i2p1{{$}}
# CHECK-RV64-NEXT: 2: {{0+}} 0 NOTYPE LOCAL DEFAULT [[#WIBBLE]] $xrv64i2p1{{$}}
# CHECK-NEXT: 3: {{0+}} 0 NOTYPE LOCAL DEFAULT [[#STARTS_DATA]] $d{{$}}
-# CHECK-RV32-NEXT: 4: 00000008 0 NOTYPE LOCAL DEFAULT [[#TEXT]] $xrv32i2p1{{$}}
-# CHECK-RV64-NEXT: 4: {{0+}}8 0 NOTYPE LOCAL DEFAULT [[#TEXT]] $xrv64i2p1{{$}}
# CHECK-NOT: {{.}}
More information about the llvm-commits
mailing list