Skip to content

RISC-V Architecture Mismatch Error During BOLT Instrumentation: "linking object with arch x86_64 into context with arch riscv64" #140996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JunGaos opened this issue May 22, 2025 · 1 comment
Labels

Comments

@JunGaos
Copy link

JunGaos commented May 22, 2025

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: 569b6f6
Target Architecture: riscv64
Host Architecture: x86_64
Toolchain: riscv-gnu-toolchain with clang
OS: Ubuntu (ThinkCentre)

File: loop_test.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
@llvmbot llvmbot added the BOLT label May 22, 2025
@llvmbot
Copy link
Member

llvmbot commented May 22, 2025

@llvm/issue-subscribers-bolt

Author: None (JunGaos)

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: 569b6f6
Target Architecture: riscv64
Host Architecture: x86_64
Toolchain: riscv-gnu-toolchain with clang
OS: Ubuntu (ThinkCentre)

File: loop_test.c

#include &lt;stdio.h&gt;
int main() {
    int sum = 0;
    
    for (int i = 0; i &lt; 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants