riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
579 stars 306 forks source link

machine: manually perform assembler relaxation #244

Closed compnerd closed 3 years ago

compnerd commented 3 years ago

This is an equivalent rewrite of the existing code. When building with gas, the bltu would implicitly get relaxed to the bgeu + j. This relaxation is required as the init_other_hart is not guaranteed to be addressable in 12-bits. When building with the LLVM IAS instead of gas we fail to link as the branch is not relaxed. This change enables LLVM to build and link this code with the LLVM IAS and lld.

aswaterman commented 3 years ago

I don't have a problem with this patch, but I also don't think this is the end of the story. LLVM's assembler seems deficient in this respect. It won't be able to assemble code emitted by GCC unless it fixes this limitation.

compnerd commented 3 years ago

I'm afraid that you are correct about that. The LLVM assembler does need to be enhanced to support this relocation. In general, use of LLVM currently requires that you build your code with -mno-relax, which has no impact on assembly though.

jrtc27 commented 3 years ago

I'd argue GNU as is wrong here. If I write bltu I should get bltu not bgeu+j. RISC-V GNU as is the outlier here, on other architectures this kind of code is not accepted.