Closed leelingrui closed 1 year ago
Your linker script has some problems. For one, blatantly wrong erodata
, etext
, edata
, and ebss
.
More relevantly, that offset is 0x0000_7fff_ffef_e000
, which tells me that either the code or data isn't getting properly shifted up to high addresses.
@riking maybe this linker script has problem because I copy it from a tutorial. but I'm sure the code and date shifted up to correct address. I changed my BASE_ADDRESS to 0x100000 it works properly if BASE_ADDRESS is 0x500000 all section has been move to correct position I checked symbol table HANDLER_TABLE correctly been placed at 0x50000 by the way address 0x0000_7fff_ffef_e000 also occur same error
error only occur if I use inline assmbly directly access symbol address. this situation won't occur same error if my code and data section has some problem I guess it will occur again
Code
.cargo/config.toml
src/linker.ld
Meta
rustc --version --verbose
:Error output
Backtrace
``` root@DESKTOP-77O23BF:~/test_rust# RUST_BACKTRACE=1 cargo build Compiling test_rust v0.1.0 (/root/test_rust) error: linking with `rust-lld` failed: exit status: 1 | = note: LC_ALL="C" PATH="/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/root/.cargo/bin:/root/.vscode-server/bin/74f6148eb9ea00507ec113ec51c489d6ffb4b771/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/bin:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/libnvvp:/mnt/c/Python311/Scripts/:/mnt/c/Python311/:/mnt/c/Program Files (x86)/Common Files/MVS/Runtime/Win32_i86:/mnt/c/Program Files (x86)/Common Files/MVS/Runtime/Win64_x64:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/Scripts:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin:/mnt/d/opencv/build/x64/vc15/lib:/mnt/d/opencv/build/x64/vc15/bin:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/d/MinGW/bin:/mnt/c/Qt/Tools/CMake_64/bin:/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/Git/mingw64/bin:/mnt/d/IDEA/IntelliJ IDEA Community Edition 2020.3.3/jbr/bin:/mnt/c/Program Files/dotnet:/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64:/mnt/c/Program Files/nodejs/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/NVIDIA Corporation/Nsight Compute 2023.1.0/:/mnt/f/llvm-project-llvmorg-15.0.7/build:/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja:/mnt/d/Graphviz/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Users/lingruilee/.cargo/bin:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/extras/CUPTI/lib64:/mnt/c/Program Files (x86)/Common Files/MVS/Runtime/Win32_i86:/mnt/c/Program Files (x86)/Common Files/MVS/Runtime/Win64_x64:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/bin:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/libnvvp:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/Scripts:/mnt/c/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64:/mnt/c/Program Files/NVIDIA Corporation/Nsight Compute 2022.1.1/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v:/mnt/c/Users/lingruilee/AppData/Roaming/npm:/mnt/c/Users/lingruilee/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/lingruilee/.dotnet/tools:/root/qemu-8.0.0/build" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/tmp/rustcQTz282/symbols.o" "/root/test_rust/./build/x86_64-unknown-none/debug/deps/test_rust-f16dd41437df1e78.1q363ytq95j1e9xg.rcgu.o" "--as-needed" "-L" "/root/test_rust/./build/x86_64-unknown-none/debug/deps" "-L" "/root/test_rust/./build/debug/deps" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib" "-Bstatic" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib/librustc_std_workspace_core-2d0ea67b4f17a921.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib/libcore-8d771b431f12fe2c.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib/libcompiler_builtins-53d2f51eb0e48bb6.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib" "-o" "/root/test_rust/./build/x86_64-unknown-none/debug/deps/test_rust-f16dd41437df1e78" "--gc-sections" "-pie" "-z" "relro" "-z" "now" "-Tsrc/linker.ld" = note: rust-lld: error: /root/test_rust/./build/x86_64-unknown-none/debug/deps/test_rust-f16dd41437df1e78.1q363ytq95j1e9xg.rcgu.o:(function _start: .text._start+0x7): relocation R_X86_64_32S out of range: -140737487298560 is not in [-2147483648, 2147483647]; references HANDLER_TABLE >>> referenced by main.rs:15 (src/main.rs:15) >>> defined in /root/test_rust/./build/x86_64-unknown-none/debug/deps/test_rust-f16dd41437df1e78.1q363ytq95j1e9xg.rcgu.o error: could not compile `test_rust` (bin "test_rust") due to previous error ```