File tree 3 files changed +29
-12
lines changed
sanitizer-invalid-cratetype
3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -858,12 +858,12 @@ impl<'a> CrateLoader<'a> {
858
858
match * ct {
859
859
// Link the runtime
860
860
config:: CrateTypeExecutable => true ,
861
- config:: CrateTypeDylib => true ,
862
- config:: CrateTypeCdylib => true ,
863
- config:: CrateTypeStaticlib => true ,
864
861
// This crate will be compiled with the required
865
862
// instrumentation pass
866
863
config:: CrateTypeRlib => false ,
864
+ config:: CrateTypeDylib => false ,
865
+ config:: CrateTypeCdylib => false ,
866
+ config:: CrateTypeStaticlib => false ,
867
867
_ => {
868
868
self . sess . err ( & format ! ( "Only executables, dylibs and rlibs can be \
869
869
compiled with `-Z sanitizer`") ) ;
Original file line number Diff line number Diff line change 5
5
# are compiled with address sanitizer, and we assert that a fault in the dylib
6
6
# is correctly detected.
7
7
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
10
9
10
+ ifeq ($(TARGET ) ,x86_64-apple-darwin)
11
+ ASAN_SUPPORT =$(SANITIZER_SUPPORT )
12
+ EXTRA_RUSTFLAG =-C rpath
13
+ else
11
14
ifeq ($(TARGET ) ,x86_64-unknown-linux-gnu)
15
+ ASAN_SUPPORT =$(SANITIZER_SUPPORT )
16
+ EXTRA_RUSTFLAG =
17
+ endif
18
+ endif
19
+
12
20
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
16
24
LD_LIBRARY_PATH=$(TMPDIR) $(TMPDIR)/program 2>&1 | grep -q stack-buffer-overflow
17
- else
18
- all :
19
25
endif
26
+
Original file line number Diff line number Diff line change 1
1
-include ../tools.mk
2
2
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
3
9
ifeq ($(TARGET ) ,x86_64-unknown-linux-gnu)
10
+ ASAN_SUPPORT =$(SANITIZER_SUPPORT )
11
+ EXTRA_RUSTFLAG =
12
+ endif
13
+ endif
14
+
4
15
all :
16
+ ifeq ($(ASAN_SUPPORT ) ,1)
5
17
$(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 :
8
18
endif
You can’t perform that action at this time.
0 commit comments