<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140996>140996</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
RISC-V Architecture Mismatch Error During BOLT Instrumentation: "linking object with arch x86_64 into context with arch riscv64"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JunGaos
</td>
</tr>
</table>
<pre>
When attempting to instrument a RISC-V binary using LLVM-BOLT, the process fails with an architecture mismatch error during the linking phase. BOLT correctly identifies the target as RISC-V but fails when trying to link what appears to be an x86_64 object file.
Environment:
LLVM-BOLT Version: 569b6f6dade6a1a1b758d982bcd9d91abafb787f
Target Architecture: riscv64
Host Architecture: x86_64
Toolchain: riscv-gnu-toolchain with clang
OS: Ubuntu (ThinkCentre)
File: loop_test.c
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 0; i < 100; i++) {
sum += i;
}
printf("Sum: %d\n", sum);
return 0;
}
```
Steps to Reproduce:
Compile a simple C program for RISC-V:
`/home/simon/diskWD/riscv-gnu-toolchain/install/bin/clang loop_test.c -Wl,--emit-relocs -o loop_test_rv_llvm`
Attempt to instrument the binary with BOLT:
`/home/simon/diskWD/riscv-gnu-toolchain/install/bin/llvm-bolt loop_test_rv_llvm -instrument -o instrumented_loop_test_rv_llvm -instrumentation-file=without_pgo_loop_test_rv_llvm.fdata`
BOLT fails with the following error:
```
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: riscv64
BOLT-INFO: BOLT version: 569b6f6dade6a1a1b758d982bcd9d91abafb787f
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0x200000, offset 0x200000
BOLT-INFO: enabling relocation mode
BOLT-INFO: forcing -jump-tables=move for instrumentation
BOLT-INFO: 0 out of 8 functions in the binary (0.0%) have non-empty execution profile
BOLT-INSTRUMENTER: Number of indirect call site descriptors: 1
BOLT-INSTRUMENTER: Number of indirect call target descriptors: 5
BOLT-INSTRUMENTER: Number of function descriptors: 5
BOLT-INSTRUMENTER: Number of branch counters: 2
BOLT-INSTRUMENTER: Number of ST leaf node counters: 8
BOLT-INSTRUMENTER: Number of direct call counters: 0
BOLT-INSTRUMENTER: Total number of counters: 10
BOLT-INSTRUMENTER: Total size of counters: 80 bytes (static alloc memory)
BOLT-INSTRUMENTER: Total size of string table emitted: 60 bytes in file
BOLT-INSTRUMENTER: Total size of descriptors: 592 bytes in file
BOLT-INSTRUMENTER: Profile will be saved to file without_pgo_loop_test_rv_llvm.fdata
BOLT-INFO: UCE removed 1 blocks and 40 bytes of code
BOLT-INFO: padding code to 0x600000 to accommodate hot text
BOLT-ERROR: linking object with arch x86_64 into context with arch riscv64
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVlFz4jgS_jXipcuUERjMAw-EhLu5mplcJZmZx5QstbE2suSSZJLcr79qGQght5u9vUtRFVvu_tTd6u9TixD0ziKuWHHFiuuR6GPj_Oofvf2bcGFUOfW6-tWgBREjtl3UdgfRgbYh-r5FG0HA3Zf7TfYTKm2Ff4U-kM3Xrz-_ZVe3Xx8Y30BsEDrvJIYAtdAmwLOODQgLwstGR5Sx9witDq2IsgH03nlQvU-7NQhG2yd67hoRcAyEC9J5jzKaV9AKbdS1xpCMo_A7jCDCKbA-HrelTKJ_PWRBsPDciAii61D4QIsVUmAv5fxxPgNX_YYyQq0Njlm-Zvn6xu61d5ZSZ1NaOGUKP9EH7SybrqGYL6t5PVdC4VxMxKRaFKValrySaqmWE1GJulqUi5rl64ch3PVZJQjB6yD38xnL13934ePnIT5yd87IRmh7csp2ts_icXkotTTC7li-vr0nsx9Vb2MPjJcPjbZPG7TRI-PLIcOtNmkL41z3GDHEsaQP83z4pRc-1VaaXiGw6SZEpd24YdMblq-1jdBSOLxkfAlsccXyNdBq6Ftg02vI2TStAcDhX-08BUNG-mSSHjcwyYcXxq_S7wR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