You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(build): Disable LTO on riscv64 to fix linker error (#458)
### Description
This PR fixes a build failure encountered when cross-compiling for the
`riscv64` architecture.
When LTO is enabled (via `-flto=auto`), the build fails during the final
linking stage with the following error:
```
/data/hebo/toolchain/gcc-15.1/lib/gcc/riscv64-unknown-linux-gnu/15.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: ... hidden symbol \`\_ZN8nanobind11chain\_errorENS\_6handleEPKcz' isn't defined
/data/hebo/toolchain/gcc-15.1/lib/gcc/riscv64-unknown-linux-gnu/15.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: final link failed: bad value
```
This appears to be caused by the RISC-V toolchain's LTO implementation
incorrectly discarding the `nanobind::chain_error` symbol, which is
required by the bindings.
This patch resolves the issue by modifying the CMake build logic to
conditionally add the `-flto=auto` flag to `CMAKE_CXX_FLAGS` *only* when
the target architecture (`CMAKE_SYSTEM_PROCESSOR`) is not `riscv64`.
### How This Was Tested
The fix has been successfully tested in the following environments:
1. RISC-V 64-bit (Problem Environment):
* Platform: SG2044
* Toolchain: GCC 15.1
* Python: 3.11
* Result: Build SUCCESS, previously FAILED
2. x86_64:
* Platform: x86_64
* Toolchain: GCC 14
* Python: 3.12
* Result: Build SUCCESS, LTO remains enabled and functional
Signed-off-by: lyd1992 <[email protected]>
Signed-off-by: ihb2032 <[email protected]>
Co-authored-by: Yixin Dong <[email protected]>
0 commit comments