Skip to content

Commit c6f065d

Browse files
authored
[BOLT][RISCV] Recognize mapping syms with encoded ISA (#68964)
RISC-V supports mapping syms for code that encode the exact ISA for which the code is valid. They have the form `$x<ISA>` where `<ISA>` is the textual encoding of an ISA specification. BOLT currently doesn't recognize these mapping symbols causing many binaries compiled with newer versions of GCC (which emits them) to not be properly processed. This patch makes sure BOLT recognizes them as code markers. Note that LLVM does not emit these kinds of mapping symbols yet so the test is based on a binary produced by GCC.
1 parent 2e955c0 commit c6f065d

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,10 @@ MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
18031803
if (*NameOrError == "$x" || NameOrError->startswith("$x."))
18041804
return MarkerSymType::CODE;
18051805

1806+
// $x<ISA>
1807+
if (isRISCV() && NameOrError->startswith("$x"))
1808+
return MarkerSymType::CODE;
1809+
18061810
if (*NameOrError == "$d" || NameOrError->startswith("$d."))
18071811
return MarkerSymType::DATA;
18081812

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_RISCV
7+
Flags: [ EF_RISCV_RVC, EF_RISCV_FLOAT_ABI_DOUBLE ]
8+
Entry: 0x100B0
9+
ProgramHeaders:
10+
- Type: 0x70000003
11+
Flags: [ PF_R ]
12+
FirstSec: .riscv.attributes
13+
LastSec: .riscv.attributes
14+
Offset: 0xB8
15+
- Type: PT_LOAD
16+
Flags: [ PF_X, PF_R ]
17+
FirstSec: .text
18+
LastSec: .text
19+
VAddr: 0x10000
20+
Align: 0x1000
21+
Offset: 0x0
22+
Sections:
23+
- Name: .text
24+
Type: SHT_PROGBITS
25+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
26+
Address: 0x100B0
27+
AddressAlign: 0x2
28+
Content: '0100000000008280'
29+
- Name: .riscv.attributes
30+
Type: SHT_RISCV_ATTRIBUTES
31+
AddressAlign: 0x1
32+
Content: 4144000000726973637600013A0000000572763634693270315F6D3270305F613270315F663270325F643270325F633270305F7A696373723270305F7A6D6D756C31703000
33+
Symbols:
34+
- Name: '_start'
35+
Section: .text
36+
Binding: STB_GLOBAL
37+
Value: 0x100B0
38+
- Name: '$xrv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zmmul1p0'
39+
Section: .text
40+
Value: 0x100B0
41+
- Name: '$d'
42+
Section: .text
43+
Value: 0x100B2
44+
- Name: '$x'
45+
Section: .text
46+
Value: 0x100B6
47+
...

bolt/test/RISCV/mapping-syms-isa.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test that BOLT handles mapping syms that include ISA strings: $x<isa>
2+
3+
RUN: yaml2obj -o %t %p/Inputs/mapping-syms-isa.yaml
4+
RUN: llvm-bolt --print-cfg --print-only=_start -o %t.bolt %t 2>&1 | FileCheck %s
5+
RUN: llvm-objdump -d %t.bolt | FileCheck --check-prefix=CHECK-OBJDUMP %s
6+
7+
CHECK-NOT: BOLT-WARNING
8+
9+
# Check that .word is not disassembled by BOLT
10+
CHECK: 00000000: nop
11+
CHECK: 00000002: ret
12+
13+
# Check .word is still present in output
14+
CHECK-OBJDUMP: <_start>:
15+
CHECK-OBJDUMP-NEXT: nop
16+
CHECK-OBJDUMP-NEXT: unimp
17+
CHECK-OBJDUMP-NEXT: unimp
18+
CHECK-OBJDUMP-NEXT: ret

0 commit comments

Comments
 (0)