Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relocation R_X86_64_32S out of range #70992

Closed
ghost opened this issue Apr 10, 2020 · 7 comments
Closed

Relocation R_X86_64_32S out of range #70992

ghost opened this issue Apr 10, 2020 · 7 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Apr 10, 2020

I tried to link some code to large address using custom linker script but it says 'relocation R_X86_64_32S out of range'

linker script:

SECTIONS
{
  . = 0xffff800000000000;
  .text : { *(.text) }
  .data : { *(.data) }
  .bss : { *(.bss) }
}

command: rustc main.rs -C link-arg='--script=link.ld' -C code-model=large

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (1edd389cc 2020-03-23)
Backtrace

<backtrace>

@ghost ghost added the C-bug Category: This is a bug. label Apr 10, 2020
@Alexendoo Alexendoo added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-linkage Area: linking into static, shared libraries and binaries labels Apr 15, 2020
@ghost
Copy link
Author

ghost commented Apr 18, 2020

I figured it out! The core crate i'm linking with is built with different code-model and relocation-model. After re-build them with same code-model and relocation-model, everything works.

@ghost ghost closed this as completed Apr 18, 2020
@polyproline
Copy link

I figured it out! The core crate i'm linking with is built with different code-model and relocation-model. After re-build them with same code-model and relocation-model, everything works.

Can you share about your resolution step?I have the same question with you.

@ghost
Copy link
Author

ghost commented Nov 24, 2020

You must use the same code-model and relocation-model when you building your core crate. The step to building core crate with custom target is quite hard and I still not figure it out, I just copy sysroot from some others project.

@polyproline
Copy link

You must use the same code-model and relocation-model when you building your core crate. The step to building core crate with custom target is quite hard and I still not figure it out, I just copy sysroot from some others project.

Thanke you for your response.
I used cargo-xbuild ,set env RUSTFLAGS to make crates in the same code-model and relocation-model then build fail with the same question
But when I used .cargo/config.toml ,set build-std and env RUSTFLAGS then it did well
Is cargo-xbuild question? what are you build command?

@ghost
Copy link
Author

ghost commented Nov 24, 2020

About the custom core crate, I can't remember anymore since it too long ago. As i said, I use cargo-xbuild to build the core crate for me and I just copy sysroot folder for private use after that.

# prepare some build tool and files
rustup component add rust-src
cargo install cargo-xbuild

cp /path/to/your/rust-toolchain .
cp /path/to/your/custom_target_file.json .
cp /path/to/your/placeholder_main.rs src/main.rs

# build the place holder project to get sysroot
cargo xbuild --target custom_target_file
cp -r target/sysroot/  /where/do/you/want/to/save/it

After that, use it as follow:

rustc main.rs -o main.elf -g --edition 2018 --target custom_target_file --sysroot /where/do/you/want/to/save/it -C link-args='--script=link.ld'

@polyproline
Copy link

About the custom core crate, I can't remember anymore since it too long ago. As i said, I use cargo-xbuild to build the core crate for me and I just copy sysroot folder for private use after that.

# prepare some build tool and files
rustup component add rust-src
cargo install cargo-xbuild

cp /path/to/your/rust-toolchain .
cp /path/to/your/custom_target_file.json .
cp /path/to/your/placeholder_main.rs src/main.rs

# build the place holder project to get sysroot
cargo xbuild --target custom_target_file
cp -r target/sysroot/  /where/do/you/want/to/save/it

After that, use it as follow:

rustc main.rs -o main.elf -g --edition 2018 --target custom_target_file --sysroot /where/do/you/want/to/save/it -C link-args='--script=link.ld'

Thank you

@ghost
Copy link
Author

ghost commented Nov 24, 2020

@polyproline, as some note, you should back up your sysroot folder if it works because this is just a work around and cargo-xbuild project can change their way of doing thing anytime and it may break everything. This happened to me once until I found out what they had changed and find my way to work around that.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants