File tree Expand file tree Collapse file tree 7 files changed +63
-9
lines changed
sanitizer-invalid-cratetype Expand file tree Collapse file tree 7 files changed +63
-9
lines changed Original file line number Diff line number Diff line change @@ -858,11 +858,14 @@ 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 ,
861
864
// This crate will be compiled with the required
862
865
// instrumentation pass
863
866
config:: CrateTypeRlib => false ,
864
867
_ => {
865
- self . sess . err ( & format ! ( "Only executables and rlibs can be \
868
+ self . sess . err ( & format ! ( "Only executables, dylibs and rlibs can be \
866
869
compiled with `-Z sanitizer`") ) ;
867
870
false
868
871
}
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ # This test builds a shared object, then an executable that links it as a native
4
+ # rust library (constrast to an rlib). The shared library and executable both
5
+ # are compiled with address sanitizer, and we assert that a fault in the dylib
6
+ # is correctly detected.
7
+
8
+ # Note: currently we have to add -lasan to link, because it's not automatically
9
+ # added in the -Z sanitizer=address process.
10
+
11
+ ifeq ($(TARGET ) ,x86_64-unknown-linux-gnu)
12
+ 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 )
16
+ LD_LIBRARY_PATH=$(TMPDIR ) $(TMPDIR ) /program 2>&1 | grep -q stack-buffer-overflow
17
+ else
18
+ all :
19
+ endif
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #[ no_mangle]
12
+ pub extern fn overflow ( ) {
13
+ let xs = [ 0 , 1 , 2 , 3 ] ;
14
+ let y = unsafe { * xs. as_ptr ( ) . offset ( 4 ) } ;
15
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ extern {
12
+ fn overflow ( ) ;
13
+ }
14
+
15
+ fn main ( ) {
16
+ unsafe { overflow ( ) }
17
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ ifeq ($(TARGET ) ,x86_64-unknown-linux-gnu)
4
+ all :
5
+ $(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
+ endif
File renamed without changes.
You can’t perform that action at this time.
0 commit comments