You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[loongarch*-linux] -Crelocation-model=static should not access external data directly #118053
thread 'main' panicked at t.rs:12:16:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x28ee81ef1c000aef
stack backtrace:
0: rust_begin_unwind
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
1: core::panicking::panic_nounwind_fmt
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:106:14
2: core::panicking::panic_misaligned_pointer_dereference
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:193:5
3: t::main
at ./t.rs:12:16
4: core::ops::function::FnOnce::call_once
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
This is the same issue as llvm/llvm-project#71645. For the linux kernel, we need to access external data directly when the relocation model is static to avoid GOT. It would better to add the -Cdirect-access-external-data argument to tune this behavior like clang.
static - non-relocatable code, machine instructions may use absolute addressing modes.
So in the kernel it just should not be used for arch/loongarch: at least when CONFIG_RELOCATABLE=y we expect vmlinux to be a PIE, so non-relocatable code should not be allowed.
static - non-relocatable code, machine instructions may use absolute addressing modes.
So in the kernel it just should not be used for arch/loongarch: at least when CONFIG_RELOCATABLE=y we expect vmlinux to be a PIE, so non-relocatable code should not be allowed.
arch/um already has:
KBUILD_RUSTFLAGS += -Crelocation-model=pie
Can we have the same?
Oops, it will create GOT in vmlinux because we don't have -Cdirect-access-external-data. I think we should add -Cdirect-access-external-data, or make a new relocation model static-pie which is suitable for static PIEs like vmlinux.
Oops, it will create GOT in vmlinux because we don't have -Cdirect-access-external-data. I think we should add -Cdirect-access-external-data, or make a new relocation model static-pie which is suitable for static PIEs like vmlinux.
Another issue is we don't have a differentiate between KBUILD_RUSTFLAGS_MODULE and KBUILD_RUSTFLAGS_KERNEL yet. With either -Cdirect-access-external-data or -Crelocation-model=static-pie we still need such a differentiate.
Oops, it will create GOT in vmlinux because we don't have -Cdirect-access-external-data. I think we should add -Cdirect-access-external-data, or make a new relocation model static-pie which is suitable for static PIEs like vmlinux.
Another issue is we don't have a differentiate between KBUILD_RUSTFLAGS_MODULE and KBUILD_RUSTFLAGS_KERNEL yet. With either -Cdirect-access-external-data or -Crelocation-model=static-pie we still need such a differentiate.
static - non-relocatable code, machine instructions may use absolute addressing modes.
So in the kernel it just should not be used for arch/loongarch: at least when CONFIG_RELOCATABLE=y we expect vmlinux to be a PIE, so non-relocatable code should not be allowed.
static - non-relocatable code, machine instructions may use absolute addressing modes.
So in the kernel it just should not be used for arch/loongarch: at least when CONFIG_RELOCATABLE=y we expect vmlinux to be a PIE, so non-relocatable code should not be allowed.
arch/um already has:
KBUILD_RUSTFLAGS += -Crelocation-model=pie
Can we have the same?
Oops, it will create GOT in vmlinux because we don't have -Cdirect-access-external-data. I think we should add -Cdirect-access-external-data, or make a new relocation model static-pie which is suitable for static PIEs like vmlinux.
In clang, -fdirect-access-external-data only works with no-pic. Therefore, even when using -fdirect-access-external-data with -fPIE, there are still GOT entries. I just noticed that is different from GCC.
Update: Function doesn't support direct access in PIE mode.
Activity
heiher commentedon Nov 19, 2023
@rustbot label O-loongarch
heiher commentedon Nov 19, 2023
This is the same issue as llvm/llvm-project#71645. For the linux kernel, we need to access external data directly when the relocation model is static to avoid GOT. It would better to add the
-Cdirect-access-external-dataargument to tune this behavior like clang.xry111 commentedon Nov 20, 2023
From https://doc.rust-lang.org/rustc/codegen-options/index.html:
So in the kernel it just should not be used for arch/loongarch: at least when CONFIG_RELOCATABLE=y we expect vmlinux to be a PIE, so non-relocatable code should not be allowed.
arch/um already has:
Can we have the same?
xry111 commentedon Nov 20, 2023
Oops, it will create GOT in vmlinux because we don't have
-Cdirect-access-external-data. I think we should add-Cdirect-access-external-data, or make a new relocation modelstatic-piewhich is suitable for static PIEs like vmlinux.xry111 commentedon Nov 20, 2023
Another issue is we don't have a differentiate between KBUILD_RUSTFLAGS_MODULE and KBUILD_RUSTFLAGS_KERNEL yet. With either
-Cdirect-access-external-dataor-Crelocation-model=static-piewe still need such a differentiate.heiher commentedon Nov 20, 2023
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Makefile?h=next-20231120#n568
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Makefile?h=next-20231120#n571
heiher commentedon Nov 20, 2023
Updated: heiher/linux@a590c2f#diff-0e1f2cb4db0de17a95f13ee71d503167892fb028b00507977fcf9568066b33ecR88
heiher commentedon Nov 20, 2023
In clang,
-fdirect-access-external-dataonly works withno-pic. Therefore, even when using-fdirect-access-external-datawith-fPIE, there are still GOT entries. I just noticed that is different from GCC.Update: Function doesn't support direct access in PIE mode.
llvm/llvm-project@e2e82c9#diff-e724febedab9c1a2832bf2056d208ff02ddcb2e6f90b5a653afc9b19ac78a5d7L991-L995
Rollup merge of rust-lang#119162 - heiher:direct-access-external-data…
Rollup merge of rust-lang#119162 - heiher:direct-access-external-data…
Rollup merge of rust-lang#119162 - heiher:direct-access-external-data…
Unrolled build for rust-lang#119162
Setting up indirect access to external data for loongarch64-linux-{mu…
Setting up indirect access to external data for loongarch64-linux-{mu…
Rollup merge of rust-lang#131583 - heiher:loong-issue-118053, r=jieyouxu
Unrolled build for rust-lang#131583