How to link emitted IR into executables in aarch64 linux

Hi, thanks for your time.

I'm trying to emit the IR from Rustc and link these IR back into executables. I can do it in x86_64 but when I deployed my script in aarch64-linux, it failed with

/usr/bin/ld: /tmp/main-0632d7.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /tmp/main-0632d7.o(.text+0x45980c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `stderr@@GLIBC_2.17'
/usr/bin/ld: final link failed: bad value

My build pipeline is like

cargo clean && RUSTFLAGS="--emit=llvm-bc"  cargo build --release --bin $1
$LLVM_BIN/llvm-link target/release/deps/*.bc -o main.bc
clang-15 -v -Bstatic ~/.rustup/toolchains/nightly-2022-08-31-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-302d2116e4cef5d4.rlib  -m64 main.bc -L ~/.rustup/toolchains/nightly-2022-08-31-aarch64-unknown-linux-gnu/lib/ -lstd-eb176fb856288d24 -lrustc_driver-716ddf2b7a210c45 -lm -lpthread
mv a.out base.$1.out

Thanks for your help!

Oh, somehow I need to add "-no-pie" explicitly to disable the link to use pie option!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.