[PATCH] D63076: [ELF][RISCV] Support PLT, GOT, copy and relative relocations
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 08:03:24 PDT 2019
MaskRay added a comment.
musl is about to add support for riscv64 (there is a draft at https://github.com/riscv/riscv-musl).
Get a riscv cross gcc (clang is still lacking many stuff, and you'll need libgcc anyway even if use clang), say, ~/.local/opt/riscv-none-gcc
qemu-riscv64-static (in the package "qemu-user-static" in several distros)
# clone musl
mkdir riscv64; cd riscv64
../configure --target riscv64 CROSS_COMPILE=~/.local/opt/riscv-none-gcc/bin/riscv-none-embed- CFLAGS='-march=rv64g -mabi=lp64d'
make
# hack obj/musl-gcc
exec ~/.local/opt/riscv-none/gcc/bin/riscv-none-embed-gcc "$@" -specs $HOME/musl/riscv64/lib/musl-gcc.specs
# hack lib/musl-gcc.specs
*cpp_options:
-nostdinc -isystem /path/to/musl/arch/riscv64 -isystem /path/to/musl/arch/generic -isystem /path/to/musl/include -isystem /path/to/musl/riscv64/obj/include -isystem include%s %(old_cpp_options)
*cc1:
%(cc1_cpu) -nostdinc -isystem /path/to/musl/arch/riscv64 -isystem /path/to/musl/arch/generic -isystem /path/to/musl/include -isystem /path/to/musl/riscv64/obj/include -isystem include%s
*link:
-nostdlib %{shared:-shared} %{static:-static ;:-dynamic-linker /path/to/musl/riscv64/lib/libc.so} %{rdynamic:-export-dynamic}
gcc<9 doesn't support -fuse-ld=lld. So I did another horrible hack... I placed a script ld.gold in `~/.local/opt/riscv-none-gcc/bin` and made it call `/path/to/lld -flavor gnu "$@"`. Then:
/path/to/musl/riscv64/obj/musl-gcc -fuse-ld=gold -march=rv64g -mabi=lp64d a.c -o a
./a # /usr/bin/qemu-riscv64-static has been registered to binfmt. this can be directly executed
glibc is a pain... https://wiki.qemu.org/Documentation/Platforms/RISCV Fedora has a prebuilt riscv64 image, however, gdb is not available. So it is not better than qemu-riscv64-static.
I manually downloaded https://packages.debian.org/sid/gcc-8-riscv64-linux-gnu and its dependencies (libgcc1-riscv64-cross libgcc-8-dev-riscv64-cross libc6_2.28-10_riscv64 cpp-8-riscv64-linux-gnu etc), extracted these .deb files under `~/.local/opt/riscv64-linux-gnu-gcc`, then I run:
`LD_LIBRARY_PATH=~/.local/opt/riscv64-linux-gnu-gcc/usr/lib/x86_64-linux-gnu ~/.local/opt/riscv64-linux-gnu-gcc/usr/bin/riscv64-linux-gnu-gcc -fuse-ld=gold a.c -o a`
Unpack a riscv64 libc6 somewhere, say, `/tmp/debian-riscv64`, then run `qemu-riscv64-static -L /tmp/debian-riscv64 ./a`
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63076/new/
https://reviews.llvm.org/D63076
More information about the llvm-commits
mailing list