@@ -2,18 +2,20 @@ use super::super::*;
2
2
use std:: assert_matches:: assert_matches;
3
3
4
4
// Test target self-consistency and JSON encoding/decoding roundtrip.
5
- pub ( super ) fn test_target ( target : Target ) {
6
- target. check_consistency ( ) ;
5
+ pub ( super ) fn test_target ( target : Target , triple : & str ) {
6
+ target. check_consistency ( triple ) ;
7
7
assert_eq ! ( Target :: from_json( target. to_json( ) ) . map( |( j, _) | j) , Ok ( target) ) ;
8
8
}
9
9
10
10
impl Target {
11
- fn check_consistency ( & self ) {
11
+ fn check_consistency ( & self , triple : & str ) {
12
12
assert_eq ! ( self . is_like_osx, self . vendor == "apple" ) ;
13
13
assert_eq ! ( self . is_like_solaris, self . os == "solaris" || self . os == "illumos" ) ;
14
14
assert_eq ! ( self . is_like_windows, self . os == "windows" || self . os == "uefi" ) ;
15
15
assert_eq ! ( self . is_like_wasm, self . arch == "wasm32" || self . arch == "wasm64" ) ;
16
- assert ! ( self . is_like_windows || !self . is_like_msvc) ;
16
+ if self . is_like_msvc {
17
+ assert ! ( self . is_like_windows) ;
18
+ }
17
19
18
20
// Check that default linker flavor and lld flavor are compatible
19
21
// with some other key properties.
@@ -94,8 +96,9 @@ impl Target {
94
96
check_noncc ( LinkerFlavor :: Ld ) ;
95
97
check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Ld ) ) ;
96
98
}
99
+ LldFlavor :: Ld64 => check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Ld64 ) ) ,
97
100
LldFlavor :: Wasm => check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Wasm ) ) ,
98
- LldFlavor :: Ld64 | LldFlavor :: Link => { }
101
+ LldFlavor :: Link => { }
99
102
} ,
100
103
_ => { }
101
104
}
@@ -109,20 +112,56 @@ impl Target {
109
112
) ;
110
113
}
111
114
112
- assert ! (
113
- ( self . pre_link_objects_self_contained. is_empty( )
114
- && self . post_link_objects_self_contained. is_empty( ) )
115
- || self . link_self_contained != LinkSelfContainedDefault :: False
116
- ) ;
115
+ if self . link_self_contained == LinkSelfContainedDefault :: False {
116
+ assert ! (
117
+ self . pre_link_objects_self_contained. is_empty( )
118
+ && self . post_link_objects_self_contained. is_empty( )
119
+ ) ;
120
+ }
117
121
118
122
// If your target really needs to deviate from the rules below,
119
123
// except it and document the reasons.
120
124
// Keep the default "unknown" vendor instead.
121
125
assert_ne ! ( self . vendor, "" ) ;
126
+ assert_ne ! ( self . os, "" ) ;
122
127
if !self . can_use_os_unknown ( ) {
123
128
// Keep the default "none" for bare metal targets instead.
124
129
assert_ne ! ( self . os, "unknown" ) ;
125
130
}
131
+
132
+ // Check dynamic linking stuff
133
+ // BPF: when targeting user space vms (like rbpf), those can load dynamic libraries.
134
+ if self . os == "none" && self . arch != "bpf" {
135
+ assert ! ( !self . dynamic_linking) ;
136
+ }
137
+ if self . only_cdylib
138
+ || self . crt_static_allows_dylibs
139
+ || !self . late_link_args_dynamic . is_empty ( )
140
+ {
141
+ assert ! ( self . dynamic_linking) ;
142
+ }
143
+ // Apparently PIC was slow on wasm at some point, see comments in wasm_base.rs
144
+ if self . dynamic_linking && !( self . is_like_wasm && self . os != "emscripten" ) {
145
+ assert_eq ! ( self . relocation_model, RelocModel :: Pic ) ;
146
+ }
147
+ // PIEs are supported but not enabled by default with linuxkernel target.
148
+ if self . position_independent_executables && !triple. ends_with ( "-linuxkernel" ) {
149
+ assert_eq ! ( self . relocation_model, RelocModel :: Pic ) ;
150
+ }
151
+ if self . relocation_model == RelocModel :: Pic {
152
+ assert ! ( self . dynamic_linking || self . position_independent_executables) ;
153
+ }
154
+ if self . static_position_independent_executables {
155
+ assert ! ( self . position_independent_executables) ;
156
+ }
157
+ if self . position_independent_executables {
158
+ assert ! ( self . executables) ;
159
+ }
160
+
161
+ // Check crt static stuff
162
+ if self . crt_static_default || self . crt_static_allows_dylibs {
163
+ assert ! ( self . crt_static_respected) ;
164
+ }
126
165
}
127
166
128
167
// Add your target to the whitelist if it has `std` library
0 commit comments