I’m compiling tests using clang and glibc, but the linker is reporting an error with ‘R_RISCV_ALIGN’ relocation in ‘crt1.o’ . The source code of the program “test.cpp” is as follows:
#include<stdio.h>
int main(int argc, char *argv[]){
printf("hello\n");
return 0;
}
The compilation parameters are as follows:
clang --target=riscv64-unknown-linux-gnu -march=rv64imafcv \
--sysroot=${path}/glibc64_host/sysroot \
--gcc-toolchain=${path}/glibc64_host \
-g -fuse-ld=lld -O2 test.cpp -o test
The ld.lld output is as follows:
ld.lld: error: ${path}/glibc64_host/sysroot/usr/lib/crt1.o:(.text+0x0): \
relocation R_RISCV_ALIGN requires unimplemented linker relaxation; \
recompile with -mno-relax
I understand that this is related to linker relaxation optimization, so I tried to disable linker relaxation optimization using ‘-mno-relax’. But even though I compiled with ‘-mno-relax’ parameter, the linker still gave me the same error. I also tried using ‘-Wl’ option to pass ‘–no-relax’ directly to the linker, but it didn’t work well.
clang --target=riscv64-unknown-linux-gnu -march=rv64imafcv \
--sysroot=${path}/glibc64_host/sysroot \
--gcc-toolchain=${path}/glibc64_host \
-g -fuse-ld=lld -mno-relax -O2 test.cpp -o test
After looking up some information on the Internet, I realized that this might be due to the clang version as well, so I compiled the program with clang-15, and surprisingly it worked!
Do I have to update the clang version? What should I do if I want to compile with clang-14.0.6? Any suggestions would be helpful, thanks!