Skip to content

Commit 8567269

Browse files
committed
Improve test cases as per jistone's comments
This resolves the issues with linking the runtime of asan to dylibs when it is not required. Additionally, the test cases for sanitizers are cleaned up by this patch.
1 parent 26657bf commit 8567269

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,12 @@ impl<'a> CrateLoader<'a> {
858858
match *ct {
859859
// Link the runtime
860860
config::CrateTypeExecutable => true,
861-
config::CrateTypeDylib => true,
862-
config::CrateTypeCdylib => true,
863-
config::CrateTypeStaticlib => true,
864861
// This crate will be compiled with the required
865862
// instrumentation pass
866863
config::CrateTypeRlib => false,
864+
config::CrateTypeDylib => false,
865+
config::CrateTypeCdylib => false,
866+
config::CrateTypeStaticlib => false,
867867
_ => {
868868
self.sess.err(&format!("Only executables, dylibs and rlibs can be \
869869
compiled with `-Z sanitizer`"));

src/test/run-make/sanitizer-dylib-link/Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
# are compiled with address sanitizer, and we assert that a fault in the dylib
66
# is correctly detected.
77

8-
# Note: currently we have to add -lasan to link, because it's not automatically
9-
# added in the -Z sanitizer=address process.
8+
# NOTE the address sanitizer only supports x86_64 linux and macOS
109

10+
ifeq ($(TARGET),x86_64-apple-darwin)
11+
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
12+
EXTRA_RUSTFLAG=-C rpath
13+
else
1114
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
15+
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
16+
EXTRA_RUSTFLAG=
17+
endif
18+
endif
19+
1220
all:
13-
$(RUSTC) -g -Z sanitizer=address --crate-type dylib --target $(TARGET) -lasan library.rs
14-
$(RUSTC) -g -Z sanitizer=address --crate-type bin --target $(TARGET) -lasan -llibrary program.rs
15-
echo $(RUSTC)
21+
ifeq ($(ASAN_SUPPORT),1)
22+
$(RUSTC) -g -Z sanitizer=address --crate-type dylib --target $(TARGET) library.rs
23+
$(RUSTC) -g -Z sanitizer=address --crate-type bin --target $(TARGET) -llibrary program.rs
1624
LD_LIBRARY_PATH=$(TMPDIR) $(TMPDIR)/program 2>&1 | grep -q stack-buffer-overflow
17-
else
18-
all:
1925
endif
26+
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
-include ../tools.mk
22

3+
# NOTE the address sanitizer only supports x86_64 linux and macOS
4+
5+
ifeq ($(TARGET),x86_64-apple-darwin)
6+
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
7+
EXTRA_RUSTFLAG=-C rpath
8+
else
39
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
10+
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
11+
EXTRA_RUSTFLAG=
12+
endif
13+
endif
14+
415
all:
16+
ifeq ($(ASAN_SUPPORT),1)
517
$(RUSTC) -Z sanitizer=leak --crate-type proc-macro --target $(TARGET) hello.rs 2>&1 | grep -q 'Only executables, dylibs and rlibs can be compiled with `-Z sanitizer`'
6-
else
7-
all:
818
endif

0 commit comments

Comments
 (0)