File tree Expand file tree Collapse file tree 5 files changed +43
-0
lines changed Expand file tree Collapse file tree 5 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -174,3 +174,12 @@ pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
174
174
Visibility :: Protected => llvm:: Visibility :: Protected ,
175
175
}
176
176
}
177
+
178
+ pub ( crate ) fn set_variable_sanitizer_attrs ( llval : & Value , attrs : & CodegenFnAttrs ) {
179
+ if attrs. no_sanitize . contains ( SanitizerSet :: ADDRESS ) {
180
+ unsafe { llvm:: LLVMRustSetNoSanitizeAddress ( llval) } ;
181
+ }
182
+ if attrs. no_sanitize . contains ( SanitizerSet :: HWADDRESS ) {
183
+ unsafe { llvm:: LLVMRustSetNoSanitizeHWAddress ( llval) } ;
184
+ }
185
+ }
Original file line number Diff line number Diff line change @@ -533,6 +533,8 @@ impl<'ll> CodegenCx<'ll, '_> {
533
533
base:: set_link_section ( g, attrs) ;
534
534
}
535
535
536
+ base:: set_variable_sanitizer_attrs ( g, attrs) ;
537
+
536
538
if attrs. flags . contains ( CodegenFnAttrFlags :: USED ) {
537
539
// `USED` and `USED_LINKER` can't be used together.
538
540
assert ! ( !attrs. flags. contains( CodegenFnAttrFlags :: USED_LINKER ) ) ;
Original file line number Diff line number Diff line change @@ -2452,4 +2452,7 @@ unsafe extern "C" {
2452
2452
pub fn LLVMRustIs64BitSymbolicFile ( buf_ptr : * const u8 , buf_len : usize ) -> bool ;
2453
2453
2454
2454
pub fn LLVMRustIsECObject ( buf_ptr : * const u8 , buf_len : usize ) -> bool ;
2455
+
2456
+ pub fn LLVMRustSetNoSanitizeAddress ( Global : & Value ) ;
2457
+ pub fn LLVMRustSetNoSanitizeHWAddress ( Global : & Value ) ;
2455
2458
}
Original file line number Diff line number Diff line change @@ -2189,6 +2189,25 @@ extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
2189
2189
return llvm::compression::zstd::isAvailable ();
2190
2190
}
2191
2191
2192
+ extern " C" void LLVMRustSetNoSanitizeAddress (LLVMValueRef Global) {
2193
+ GlobalValue &GV = *unwrap<GlobalValue>(Global);
2194
+ GlobalValue::SanitizerMetadata MD;
2195
+ if (GV.hasSanitizerMetadata ())
2196
+ MD = GV.getSanitizerMetadata ();
2197
+ MD.NoAddress = true ;
2198
+ MD.IsDynInit = false ;
2199
+ GV.setSanitizerMetadata (MD);
2200
+ }
2201
+
2202
+ extern " C" void LLVMRustSetNoSanitizeHWAddress (LLVMValueRef Global) {
2203
+ GlobalValue &GV = *unwrap<GlobalValue>(Global);
2204
+ GlobalValue::SanitizerMetadata MD;
2205
+ if (GV.hasSanitizerMetadata ())
2206
+ MD = GV.getSanitizerMetadata ();
2207
+ MD.NoHWAddress = true ;
2208
+ GV.setSanitizerMetadata (MD);
2209
+ }
2210
+
2192
2211
// Operations on composite constants.
2193
2212
// These are clones of LLVM api functions that will become available in future
2194
2213
// releases. They can be removed once Rust's minimum supported LLVM version
Original file line number Diff line number Diff line change 7
7
#![ crate_type = "lib" ]
8
8
#![ feature( no_sanitize) ]
9
9
10
+ // CHECK: @UNSANITIZED = constant{{.*}} no_sanitize_address
11
+ // CHECK-NOT: @__asan_global_UNSANITIZED
12
+ #[ no_mangle]
13
+ #[ no_sanitize( address) ]
14
+ pub static UNSANITIZED : u32 = 0 ;
15
+
16
+ // CHECK: @__asan_global_SANITIZED
17
+ #[ no_mangle]
18
+ pub static SANITIZED : u32 = 0 ;
19
+
10
20
// CHECK-LABEL: ; no_sanitize::unsanitized
11
21
// CHECK-NEXT: ; Function Attrs:
12
22
// CHECK-NOT: sanitize_address
You can’t perform that action at this time.
0 commit comments