Build: Fix RISC-V ISA detection dead code and sanitize -march against modern kernel/toolchain mismatch#14530
Build: Fix RISC-V ISA detection dead code and sanitize -march against modern kernel/toolchain mismatch#14530fengpengboa wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Hi @fengpengboa! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Hi @archang19 , I have a CLA-related question for this PR.Our company has previously signed the Meta Corporate CLA for other open source projects. When I tried to sign again for RocksDB, the system indicated that our company is already registered and prevented me from signing a new one.However, I do not know who the original signer was, and I am unable to locate that person internally to be added to the authorized contributor list. |
… kernel/toolchain mismatch
6c6276d to
311feb7
Compare
Background:
In
build_tools/build_detect_platform, there is a section intended to optimize RocksDB for RISC-V natively by parsing/proc/cpuinfoto populate the-marchflag.However, it contained a typo: it assigned the result to
RISC_ISAbut checkedif [ -n "${RISCV_ISA}" ]. Due to this typo, the RISC-V specific hardware optimization was effectively dead code and never executed.If one simply fixes the typo (
RISC_ISA->RISCV_ISA), the build immediately breaks on modern RISC-V hardware due to a mismatch between bleeding-edge Linux kernels and the GNU toolchain.Crash 1: GCC rejects privileged extensions
Modern RISC-V Linux kernels report Supervisor-level (
_s*), Hypervisor-level (_h*), and Custom (_x*) extensions in/proc/cpuinfo(e.g.,sscofpmf_sstc_svinval).Passing this raw string to GCC when compiling user-space code like RocksDB causes a fatal error:
Crash 2: Binutils (Assembler) truncates the ISA string and loses
zbb/zbsEven if we strip the privileged
_s*extensions, the kernel also exposes newly ratified user-space extensions (likezicntrorzihpm). Older versions of Binutils (as) do not recognize these newzi*extensions.When the assembler encounters an unknown extension like
zicntr, it throws:The Solution: Whitelisting & Compiler Probing
To make the build script robust against future kernel updates and lagging toolchains, this PR introduces:
rv64imafdcv) and strictly append only safe, performance-enhancing extensions that RocksDB actually benefits from:_zb*(Bitmanip),_zv*(Vector), and_zk*(Crypto).echo "int main(){}" | $CXX ...). Before trusting the synthesized-marchstring, we test if the local host compiler can actually parse it. If it fails (e.g., severely outdated GCC), it gracefully falls back to the compiler's default.Test Plan
Tested natively on a modern RISC-V (rv64) SG2044 environment