@@ -2,18 +2,20 @@ use super::super::*;
22use std:: assert_matches:: assert_matches;
33
44// 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 ) ;
77 assert_eq ! ( Target :: from_json( target. to_json( ) ) . map( |( j, _) | j) , Ok ( target) ) ;
88}
99
1010impl Target {
11- fn check_consistency ( & self ) {
11+ fn check_consistency ( & self , triple : & str ) {
1212 assert_eq ! ( self . is_like_osx, self . vendor == "apple" ) ;
1313 assert_eq ! ( self . is_like_solaris, self . os == "solaris" || self . os == "illumos" ) ;
1414 assert_eq ! ( self . is_like_windows, self . os == "windows" || self . os == "uefi" ) ;
1515 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+ }
1719
1820 // Check that default linker flavor and lld flavor are compatible
1921 // with some other key properties.
@@ -94,8 +96,9 @@ impl Target {
9496 check_noncc ( LinkerFlavor :: Ld ) ;
9597 check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Ld ) ) ;
9698 }
99+ LldFlavor :: Ld64 => check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Ld64 ) ) ,
97100 LldFlavor :: Wasm => check_noncc ( LinkerFlavor :: Lld ( LldFlavor :: Wasm ) ) ,
98- LldFlavor :: Ld64 | LldFlavor :: Link => { }
101+ LldFlavor :: Link => { }
99102 } ,
100103 _ => { }
101104 }
@@ -109,20 +112,56 @@ impl Target {
109112 ) ;
110113 }
111114
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+ }
117121
118122 // If your target really needs to deviate from the rules below,
119123 // except it and document the reasons.
120124 // Keep the default "unknown" vendor instead.
121125 assert_ne ! ( self . vendor, "" ) ;
126+ assert_ne ! ( self . os, "" ) ;
122127 if !self . can_use_os_unknown ( ) {
123128 // Keep the default "none" for bare metal targets instead.
124129 assert_ne ! ( self . os, "unknown" ) ;
125130 }
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+ }
126165 }
127166
128167 // Add your target to the whitelist if it has `std` library
0 commit comments