forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#86374 - bossmc:enable-static-pie-for-gnu, r…
…=nagisa Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu` Modern `gcc` versions support `-static-pie`, and `rustc` will already fall-back to `-static` if the local `gcc` is too old (and hence this change is optimistic rather than absolute). This brings the `-musl` and `-gnu` targets to feature compatibility (albeit with different default settings). Of note a `-static` or `-static-pie` binary based on glibc that uses NSS-backed functions (`gethostbyname` or `getpwuid` etc.) need to have access to the `libnss_X.so.2` libraries and any of their dynamic dependencies. I wasn't sure about the `# only`/`# ignore` changes (I've not got a `gnux32` toolchain to test with hence not also enabling `-static-pie` there).
- Loading branch information
Showing
4 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
# only-x86_64-unknown-linux-musl | ||
# only-x86_64 | ||
# only-linux | ||
# ignore-gnux32 | ||
|
||
# How to manually run this | ||
# $ ./x.py test --target x86_64-unknown-linux-musl src/test/run-make/static-pie | ||
|
||
all: | ||
$(RUSTC) --target $(TARGET) -C target-feature=+crt-static test-aslr.rs | ||
# Check that no dynamic interpreter is set | ||
! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP | ||
# Check that we have a dynamic executable | ||
readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC | ||
# Check for address space layout randomization | ||
$(call RUN,test-aslr) --test-aslr | ||
# $ ./x.py test --target x86_64-unknown-linux-[musl,gnu] src/test/run-make/static-pie | ||
|
||
all: test-clang test-gcc | ||
|
||
test-%: | ||
if ./check_$*_version.sh; then\ | ||
${RUSTC} -Clinker=$* -Clinker-flavor=gcc --target ${TARGET} -C target-feature=+crt-static test-aslr.rs; \ | ||
! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP; \ | ||
readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC; \ | ||
$(call RUN,test-aslr) --test-aslr; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if command -v clang > /dev/null | ||
then | ||
CLANG_VERSION=$(echo __clang_major__ | clang -E -x c - | grep -v -e '^#' ) | ||
echo "clang version $CLANG_VERSION detected" | ||
if (( $CLANG_VERSION >= 9 )) | ||
then | ||
echo "clang supports -static-pie" | ||
exit 0 | ||
else | ||
echo "clang too old to support -static-pie, skipping test" | ||
exit 1 | ||
fi | ||
else | ||
echo "No clang version detected" | ||
exit 2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if command -v gcc > /dev/null | ||
then | ||
GCC_VERSION=$(echo __GNUC__ | gcc -E -x c - | grep -v -e '^#' ) | ||
echo "gcc version $GCC_VERSION detected" | ||
if (( $GCC_VERSION >= 8 )) | ||
then | ||
echo "gcc supports -static-pie" | ||
exit 0 | ||
else | ||
echo "gcc too old to support -static-pie, skipping test" | ||
exit 1 | ||
fi | ||
else | ||
echo "No gcc version detected" | ||
exit 2 | ||
fi |