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

Enable combining +crt-static and relocation-model=pic on x86_64-unknown-linux-gnu #86374

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub fn target() -> Target {
base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string());
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
base.stack_probes = StackProbeType::Call;
base.static_position_independent_executables = true;
base.supported_sanitizers = SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::LEAK
Expand Down
25 changes: 14 additions & 11 deletions src/test/run-make/static-pie/Makefile
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
20 changes: 20 additions & 0 deletions src/test/run-make/static-pie/check_clang_version.sh
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
20 changes: 20 additions & 0 deletions src/test/run-make/static-pie/check_gcc_version.sh
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