llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.53k forks source link

BOLT could not find corresponding %pcrel_hi on RISC-V #100922

Open renndong opened 1 month ago

renndong commented 1 month ago

I'm trying to optimize a rust program using BOLT on RISC-V, but I get an error <unknown>:0: error: could not find corresponding %pcrel_hi.

This is the command that I execute:

llvm-bolt <executable> -o <output> -data=perf.fdata -reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions -split-all-cold -split-eh -dyno-stats

and the BOLT version and rust compiler version I use are:

$ llvm-bolt --version
LLVM (http://llvm.org/):
  LLVM version 19.0.0git
  Optimized build with assertions.
BOLT revision 3d72c44fedc13ef51d2584b4fe930edb8d2e87ae

  Registered Targets:
    riscv32 - 32-bit RISC-V
    riscv64 - 64-bit RISC-V
$ rustc -v -V
rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: riscv64gc-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6

The output of BOLT is as follows:

Output ``` BOLT-INFO: shared object or position-independent executable detected BOLT-INFO: Target architecture: riscv64 BOLT-INFO: BOLT version: 3d72c44fedc13ef51d2584b4fe930edb8d2e87ae BOLT-INFO: first alloc address is 0x0 BOLT-INFO: creating new program header table at address 0x200000, offset 0x200000 BOLT-WARNING: debug info will be stripped from the binary. Use -update-debug-sections to keep it. BOLT-INFO: enabling relocation mode BOLT-INFO: disabling -align-macro-fusion on non-x86 platform BOLT-WARNING: Failed to analyze 41 relocations BOLT-INFO: pre-processing profile using branch profile reader BOLT-INFO: operating with basic samples profiling data (no LBR). BOLT-INFO: normalizing samples by instruction count. BOLT-INFO: 83 out of 640 functions in the binary (13.0%) have non-empty execution profile BOLT-INFO: basic block reordering modified layout of 38 functions (45.78% of profiled, 5.41% of total) BOLT-INFO: UCE removed 4 blocks and 8 bytes of code BOLT-INFO: 0 Functions were reordered by LoopInversionPass BOLT-INFO: program-wide dynostats after all optimizations before SCTC and FOP: 276799252 : executed forward branches 83592209 : taken forward branches 19175433 : executed backward branches 1975284 : taken backward branches 230588915 : executed unconditional branches 217290399 : all function calls 217290399 : indirect calls 0 : PLT calls 5363549217 : executed instructions 1360261461 : executed load instructions 1652341608 : executed store instructions 0 : taken jump table branches 0 : taken unknown indirect branches 526563600 : total branches 316156408 : taken branches 210407192 : non-taken conditional branches 85567493 : taken conditional branches 295974685 : all conditional branches 286282669 : executed forward branches (+3.4%) 6522058 : taken forward branches (-92.2%) 9692016 : executed backward branches (-49.5%) 6625161 : taken backward branches (+235.4%) 11381856 : executed unconditional branches (-95.1%) 217290399 : all function calls (=) 1324278 : indirect calls (-99.4%) 0 : PLT calls (=) 4735678411 : executed instructions (-11.7%) 1360261461 : executed load instructions (=) 1652341608 : executed store instructions (=) 0 : taken jump table branches (=) 0 : taken unknown indirect branches (=) 307356541 : total branches (-41.6%) 24529075 : taken branches (-92.2%) 282827466 : non-taken conditional branches (+34.4%) 13147219 : taken conditional branches (-84.6%) 295974685 : all conditional branches (=) :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi :0: error: could not find corresponding %pcrel_hi BOLT-ERROR: Emission failed. ```
LiqinWeng commented 3 weeks ago

perf2bolt information:

perf2bolt -p riscv-static.data -o riscv-static.fdata  ./coremark_llvm.exe -nl -print-unknown
PERF2BOLT: Starting data aggregation job for riscv-static.data
PERF2BOLT: spawning perf job to read events without LBR
PERF2BOLT: spawning perf job to read mem events
PERF2BOLT: spawning perf job to read process events
PERF2BOLT: spawning perf job to read task events
BOLT-INFO: Target architecture: riscv64
BOLT-INFO: BOLT version: 5a19e8c17bb66bb8c474618f161a8b731fb972bd
BOLT-INFO: first alloc address is 0x10000
BOLT-INFO: creating new program header table at address 0x210000, offset 0x200000
BOLT-INFO: enabling relocation mode
BOLT-INFO: static input executable detected
BOLT-INFO: enabling strict relocation mode for aggregation purposes
BOLT-WARNING: Failed to analyze 151 relocations
BOLT-INFO: pre-processing profile using perf data aggregator
BOLT-WARNING: build-id will not be checked because we could not read one from input binary
PERF2BOLT: waiting for perf mmap events collection to finish...
PERF2BOLT: parsing perf-script mmap events output
PERF2BOLT: waiting for perf task events collection to finish...
PERF2BOLT: parsing perf-script task events output
PERF2BOLT: input binary is associated with 1 PID(s)
PERF2BOLT: waiting for perf events collection to finish...
PERF2BOLT: parsing basic events (without LBR)...
PERF2BOLT: waiting for perf mem events collection to finish...
PERF2BOLT: processing basic events (without LBR)...
PERF2BOLT: read 4519 samples
PERF2BOLT: out of range samples recorded in unknown regions: 0 (0.0%)
PERF2BOLT: wrote 597 objects and 0 memory objects to riscv-static.fdata
function with unknown control flow: printf_positional/1(*2)
function with unknown control flow: __printf_buffer
function with unknown control flow: __printf_buffer_flush/1(*2)
function with unknown control flow: __parse_one_specmb/1(*2)
function with unknown control flow: read_encoded_value/1(*2)
function with unknown control flow: execute_stack_op/1(*2)
function with unknown control flow: uw_update_context_1/1(*2)
function with unknown control flow: execute_cfa_program_specialized/1(*2)
function with unknown control flow: execute_cfa_program_generic/1(*2)
function with unknown control flow: uw_frame_state_for/1(*2)
function with unknown control flow: read_encoded_value_with_base/1(*2)
function with unknown control flow: read_encoded_value_with_base/2(*2)
function with unknown control flow: _IO_file_fopen/1(*3)
function with unknown control flow: __libc_mallopt/1(*4)
function with unknown control flow: plural_eval/1(*2)
function with unknown control flow: _nl_load_domain/1(*2)
function with unknown control flow: __gettextparse/1(*2)
function with unknown control flow: _nl_intern_locale_data/1(*2)
function with unknown control flow: _wordcopy_fwd_aligned/1(*2)
function with unknown control flow: _wordcopy_bwd_aligned/1(*2)
function with unknown control flow: __sysconf/1(*3)
function with unknown control flow: _dl_relocate_object/1(*2)
function with unknown control flow: dlinfo_doit/1(*2)
BOLT-INFO: 28 out of 930 functions in the binary (3.0%) have non-empty execution profile
BOLT-INFO: 23 functions have instructions with unknown control flow
LiqinWeng commented 3 weeks ago

The same problem was encountered when using bolt to optimize coremark on RISCV. My exe and dataFile: [Uploading coremark-riscv.tar.gz…]()

@mtvec
Sorry, I don't know much about bolt. I want to know how to get which section currently causing the problem. Can you give some debugging methods or debugging information in a little more detail? I tried debugging it, but didn't get any useful information. image