Skip to content

Commit

Permalink
[BOLT][RISCV] Recognize mapping symbols
Browse files Browse the repository at this point in the history
The RISC-V psABI [1] defines them similarly to AArch64.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#mapping-symbol

Reviewed By: yota9, Amir

Differential Revision: https://reviews.llvm.org/D153277
  • Loading branch information
mtvec committed Jul 29, 2023
1 parent a9ab845 commit fc39588
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 4 additions & 4 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,10 +1760,10 @@ void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
}

MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
// For aarch64, the ABI defines mapping symbols so we identify data in the
// code section (see IHI0056B). $x identifies a symbol starting code or the
// end of a data chunk inside code, $d indentifies start of data.
if (!isAArch64() || ELFSymbolRef(Symbol).getSize())
// For aarch64 and riscv, the ABI defines mapping symbols so we identify data
// in the code section (see IHI0056B). $x identifies a symbol starting code or
// the end of a data chunk inside code, $d indentifies start of data.
if ((!isAArch64() && !isRISCV()) || ELFSymbolRef(Symbol).getSize())
return MarkerSymType::NONE;

Expected<StringRef> NameOrError = Symbol.getName();
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ void RewriteInstance::discoverFileObjects() {
}
};

if (BC->isAArch64()) {
if (BC->isAArch64() || BC->isRISCV()) {
addExtraDataMarkerPerSymbol(SortedFileSymbols, SortedMarkerSymbols);
LastSymbol = std::stable_partition(
SortedFileSymbols.begin(), SortedFileSymbols.end(),
Expand Down
27 changes: 27 additions & 0 deletions bolt/test/RISCV/mapping-syms.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// FIXME llvm-mc is used instead of clang because we need a recent change in
/// the RISC-V MC layer (D153260). Once that one is released, we can switch to
/// clang. (Note that the pre-merge check buildbots use the system's clang).
// RUN: llvm-mc -triple riscv64 -mattr=+c -filetype obj -o %t.o %s
// RUN: ld.lld -o %t %t.o
// RUN: llvm-bolt --print-cfg --print-only=_start -o %t.bolt %t 2>&1 | FileCheck %s
// RUN: llvm-objdump -d %t.bolt | FileCheck --check-prefix=CHECK-OBJDUMP %s

// CHECK-NOT: BOLT-WARNING

/// Check that .word is not disassembled by BOLT
// CHECK: 00000000: nop
// CHECK: 00000002: ret

/// Check .word is still present in output
// CHECK-OBJDUMP: <_start>:
// CHECK-OBJDUMP-NEXT: nop
// CHECK-OBJDUMP-NEXT: unimp
// CHECK-OBJDUMP-NEXT: unimp
// CHECK-OBJDUMP-NEXT: ret
.text
.globl _start
.p2align 1
_start:
nop
.word 0x0
ret

0 comments on commit fc39588

Please sign in to comment.