https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/225131
>From 23139388518e16f0c825506e38a1c683305a427c Mon Sep 17 00:00:00 2001 From: Alex Richardson <[email protected]> Date: Mon, 21 Sep 2026 08:59:32 -0700 Subject: [PATCH] [RISC-V][MC] Fix mapping symbol section tracking on popSection() 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 --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 6 +++--- llvm/test/MC/RISCV/mapping-across-sections.s | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) 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: {{.}} _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
