5
5
//! To configure a target from scratch, a JSON-encoded file has to be passed
6
6
//! to `rustc` (introduced in [RFC 131]). These options and the file itself are
7
7
//! unstable. Eventually, `rustc` should provide a way to do this in a stable
8
- //! manner. For instance, via command-line arguments.
8
+ //! manner. For instance, via command-line arguments. Therefore, this file
9
+ //! should avoid using keys which can be set via `-C` or `-Z` options.
9
10
//!
10
11
//! [RFC 131]: https://rust-lang.github.io/rfcs/0131-target-specification.html
11
12
@@ -19,38 +20,26 @@ enum Value {
19
20
Boolean ( bool ) ,
20
21
Number ( i32 ) ,
21
22
String ( String ) ,
22
- Array ( Array ) ,
23
23
Object ( Object ) ,
24
24
}
25
25
26
- type Array = Vec < Value > ;
27
26
type Object = Vec < ( String , Value ) > ;
28
27
29
- /// Minimal "almost JSON" generator (e.g. no `null`s, no escaping), enough
30
- /// for this purpose.
28
+ /// Minimal "almost JSON" generator (e.g. no `null`s, no arrays, no escaping),
29
+ /// enough for this purpose.
31
30
impl Display for Value {
32
31
fn fmt ( & self , formatter : & mut Formatter < ' _ > ) -> Result {
33
32
match self {
34
33
Value :: Boolean ( boolean) => write ! ( formatter, "{}" , boolean) ,
35
34
Value :: Number ( number) => write ! ( formatter, "{}" , number) ,
36
35
Value :: String ( string) => write ! ( formatter, "\" {}\" " , string) ,
37
- Value :: Array ( array) => {
38
- formatter. write_str ( "[" ) ?;
39
- if let [ ref rest @ .., ref last] = array[ ..] {
40
- for value in rest {
41
- write ! ( formatter, "{}," , value) ?;
42
- }
43
- write ! ( formatter, "{}" , last) ?;
44
- }
45
- formatter. write_str ( "]" )
46
- }
47
36
Value :: Object ( object) => {
48
37
formatter. write_str ( "{" ) ?;
49
38
if let [ ref rest @ .., ref last] = object[ ..] {
50
39
for ( key, value) in rest {
51
- write ! ( formatter, "\" {}\" :{}," , key, value) ?;
40
+ write ! ( formatter, "\" {}\" : {}," , key, value) ?;
52
41
}
53
- write ! ( formatter, "\" {}\" :{}" , last. 0 , last. 1 ) ?;
42
+ write ! ( formatter, "\" {}\" : {}" , last. 0 , last. 1 ) ?;
54
43
}
55
44
formatter. write_str ( "}" )
56
45
}
@@ -106,9 +95,9 @@ impl Display for TargetSpec {
106
95
formatter. write_str ( "{\n " ) ?;
107
96
if let [ ref rest @ .., ref last] = self . 0 [ ..] {
108
97
for ( key, value) in rest {
109
- write ! ( formatter, "\" {}\" :{},\n " , key, value) ?;
98
+ write ! ( formatter, " \" {}\" : {},\n " , key, value) ?;
110
99
}
111
- write ! ( formatter, "\" {}\" :{}\n " , last. 0 , last. 1 ) ?;
100
+ write ! ( formatter, " \" {}\" : {}\n " , last. 0 , last. 1 ) ?;
112
101
}
113
102
formatter. write_str ( "}" )
114
103
}
@@ -147,7 +136,7 @@ impl KernelConfig {
147
136
///
148
137
/// The argument must be passed without the `CONFIG_` prefix.
149
138
/// This avoids repetition and it also avoids `fixdep` making us
150
- /// depending on it.
139
+ /// depend on it.
151
140
fn has ( & self , option : & str ) -> bool {
152
141
let option = "CONFIG_" . to_owned ( ) + option;
153
142
self . 0 . contains_key ( & option)
@@ -158,50 +147,15 @@ fn main() {
158
147
let cfg = KernelConfig :: from_stdin ( ) ;
159
148
let mut ts = TargetSpec :: new ( ) ;
160
149
161
- let pre_link_args = vec ! [ (
162
- "gcc" . to_string( ) ,
163
- Value :: Array ( vec![
164
- Value :: String ( "-Wl,--as-needed" . to_string( ) ) ,
165
- Value :: String ( "-Wl,-z,noexecstack" . to_string( ) ) ,
166
- ] ) ,
167
- ) ] ;
168
-
169
- let pre_link_args_32 = vec ! [ (
170
- "gcc" . to_string( ) ,
171
- Value :: Array ( vec![
172
- Value :: String ( "-Wl,--as-needed" . to_string( ) ) ,
173
- Value :: String ( "-Wl,-z,noexecstack" . to_string( ) ) ,
174
- Value :: String ( "-m32" . to_string( ) ) ,
175
- ] ) ,
176
- ) ] ;
177
-
178
- let pre_link_args_64 = vec ! [ (
179
- "gcc" . to_string( ) ,
180
- Value :: Array ( vec![
181
- Value :: String ( "-Wl,--as-needed" . to_string( ) ) ,
182
- Value :: String ( "-Wl,-z,noexecstack" . to_string( ) ) ,
183
- Value :: String ( "-m64" . to_string( ) ) ,
184
- ] ) ,
185
- ) ] ;
186
-
187
- let stack_probes = vec ! [ ( "kind" . to_string( ) , Value :: String ( "none" . to_string( ) ) ) ] ;
188
-
189
150
if cfg. has ( "ARM" ) {
190
151
ts. push ( "arch" , "arm" ) ;
191
152
ts. push (
192
153
"data-layout" ,
193
154
"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" ,
194
155
) ;
195
- ts. push ( "dynamic-linking" , true ) ;
196
- ts. push ( "crt-static-respected" , true ) ;
197
- ts. push ( "executables" , true ) ;
198
156
ts. push ( "features" , "+strict-align,+v6" ) ;
199
- ts. push ( "has-elf-tls" , true ) ;
200
- ts. push ( "has-rpath" , true ) ;
201
- ts. push ( "llvm-target" , "arm-unknown-linux-gnueabi" ) ;
157
+ ts. push ( "llvm-target" , "arm-linux-gnueabi" ) ;
202
158
ts. push ( "max-atomic-width" , 64 ) ;
203
- ts. push ( "pre-link-args" , pre_link_args) ;
204
- ts. push ( "target-family" , "unix" ) ;
205
159
ts. push ( "target-mcount" , "\\ u0001__gnu_mcount_nc" ) ;
206
160
ts. push ( "target-pointer-width" , "32" ) ;
207
161
} else if cfg. has ( "ARM64" ) {
@@ -211,106 +165,61 @@ fn main() {
211
165
"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" ,
212
166
) ;
213
167
ts. push ( "disable-redzone" , true ) ;
214
- ts. push ( "emit-debug-gdb-scripts" , false ) ;
215
- ts. push ( "features" , "+strict-align,+neon,+fp-armv8" ) ;
216
- ts. push ( "frame-pointer" , "always" ) ;
217
- ts. push ( "llvm-target" , "aarch64-unknown-none" ) ;
168
+ ts. push ( "features" , "+strict-align,-neon,-fp-armv8" ) ;
169
+ ts. push ( "llvm-target" , "aarch64-linux-gnu" ) ;
218
170
ts. push ( "max-atomic-width" , 128 ) ;
219
- ts. push ( "needs-plt" , true ) ;
220
- ts. push ( "pre-link-args" , pre_link_args_64) ;
221
- ts. push ( "stack-probes" , stack_probes) ;
222
- ts. push ( "target-c-int-width" , "32" ) ;
223
171
ts. push ( "target-pointer-width" , "64" ) ;
224
- ts. push ( "vendor" , "" ) ;
225
172
} else if cfg. has ( "PPC" ) {
226
173
ts. push ( "arch" , "powerpc64" ) ;
227
174
ts. push ( "code-model" , "large" ) ;
228
- ts. push ( "cpu" , "ppc64le" ) ;
229
175
ts. push ( "data-layout" , "e-m:e-i64:64-n32:64" ) ;
230
176
ts. push ( "features" , "-altivec,-vsx,-hard-float" ) ;
231
- ts. push ( "llvm-target" , "powerpc64le-elf " ) ;
177
+ ts. push ( "llvm-target" , "powerpc64le-linux-gnu " ) ;
232
178
ts. push ( "max-atomic-width" , 64 ) ;
233
- ts. push ( "pre-link-args" , pre_link_args_64) ;
234
- ts. push ( "target-family" , "unix" ) ;
235
179
ts. push ( "target-mcount" , "_mcount" ) ;
236
180
ts. push ( "target-pointer-width" , "64" ) ;
237
181
} else if cfg. has ( "RISCV" ) {
238
182
if cfg. has ( "64BIT" ) {
239
183
ts. push ( "arch" , "riscv64" ) ;
240
- ts. push ( "cpu" , "generic-rv64" ) ;
241
184
ts. push ( "data-layout" , "e-m:e-p:64:64-i64:64-i128:128-n64-S128" ) ;
242
- ts. push ( "llvm-target" , "riscv64" ) ;
243
- ts. push ( "max-atomic-width" , 64 ) ;
244
- ts. push ( "pre-link-args" , pre_link_args_64) ;
185
+ ts. push ( "llvm-target" , "riscv64-linux-gnu" ) ;
245
186
ts. push ( "target-pointer-width" , "64" ) ;
246
187
} else {
247
188
ts. push ( "arch" , "riscv32" ) ;
248
- ts. push ( "cpu" , "generic-rv32" ) ;
249
189
ts. push ( "data-layout" , "e-m:e-p:32:32-i64:64-n32-S128" ) ;
250
- ts. push ( "llvm-target" , "riscv32" ) ;
251
- ts. push ( "max-atomic-width" , 32 ) ;
252
- ts. push ( "pre-link-args" , pre_link_args_32) ;
190
+ ts. push ( "llvm-target" , "riscv32-linux-gnu" ) ;
253
191
ts. push ( "target-pointer-width" , "32" ) ;
254
192
}
255
193
ts. push ( "code-model" , "medium" ) ;
256
194
ts. push ( "disable-redzone" , true ) ;
257
- ts. push ( "emit-debug-gdb-scripts" , false ) ;
258
195
let mut features = "+m,+a" . to_string ( ) ;
259
196
if cfg. has ( "RISCV_ISA_C" ) {
260
197
features += ",+c" ;
261
198
}
262
199
ts. push ( "features" , features) ;
263
- ts. push ( "frame-pointer" , "always" ) ;
264
- ts. push ( "needs-plt" , true ) ;
265
- ts. push ( "target-c-int-width" , "32" ) ;
266
- ts. push ( "stack-probes" , stack_probes) ;
267
- ts. push ( "vendor" , "" ) ;
268
200
} else if cfg. has ( "X86" ) {
269
201
ts. push ( "arch" , "x86_64" ) ;
270
- ts. push ( "code-model" , "kernel" ) ;
271
- ts. push ( "cpu" , "x86-64" ) ;
272
202
ts. push (
273
203
"data-layout" ,
274
204
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" ,
275
205
) ;
276
- ts. push ( "disable-redzone" , true ) ;
277
- ts. push ( "emit-debug-gdb-scripts" , false ) ;
278
- ts. push (
279
- "features" ,
280
- "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" ,
281
- ) ;
282
- ts. push ( "frame-pointer" , "always" ) ;
283
- ts. push ( "llvm-target" , "x86_64-elf" ) ;
284
- ts. push ( "max-atomic-width" , 64 ) ;
285
- ts. push ( "needs-plt" , true ) ;
286
- ts. push ( "pre-link-args" , pre_link_args_64) ;
287
- ts. push ( "stack-probes" , stack_probes) ;
288
- ts. push ( "target-c-int-width" , "32" ) ;
206
+ ts. push ( "llvm-target" , "x86_64-linux-gnu" ) ;
289
207
ts. push ( "target-pointer-width" , "64" ) ;
290
- ts. push ( "vendor" , "unknown" ) ;
291
208
} else {
292
209
panic ! ( "Unsupported architecture" ) ;
293
210
}
294
211
295
- ts. push ( "env" , "gnu" ) ;
296
- ts. push ( "function-sections" , false ) ;
297
- ts. push ( "linker-is-gnu" , true ) ;
298
- ts. push ( "os" , if cfg. has ( "ARM" ) { "linux" } else { "none" } ) ;
299
- ts. push ( "position-independent-executables" , true ) ;
300
- ts. push ( "relocation-model" , "static" ) ;
301
-
302
- if !cfg. has ( "ARM" ) {
303
- ts. push ( "linker-flavor" , "gcc" ) ;
304
- ts. push ( "panic-strategy" , "abort" ) ;
305
- ts. push ( "relro-level" , "full" ) ;
306
-
307
- if cfg. has ( "CPU_BIG_ENDIAN" ) {
308
- ts. push ( "target-endian" , "big" ) ;
309
- } else {
310
- // Everything else is LE, whether `CPU_LITTLE_ENDIAN`
311
- // is declared or not (e.g. x86).
312
- ts. push ( "target-endian" , "little" ) ;
313
- }
212
+ ts. push ( "emit-debug-gdb-scripts" , false ) ;
213
+ ts. push ( "frame-pointer" , "may-omit" ) ;
214
+ ts. push (
215
+ "stack-probes" ,
216
+ vec ! [ ( "kind" . to_string( ) , Value :: String ( "none" . to_string( ) ) ) ] ,
217
+ ) ;
218
+
219
+ // Everything else is LE, whether `CPU_LITTLE_ENDIAN` is declared or not
220
+ // (e.g. x86). It is also `rustc`'s default.
221
+ if cfg. has ( "CPU_BIG_ENDIAN" ) {
222
+ ts. push ( "target-endian" , "big" ) ;
314
223
}
315
224
316
225
println ! ( "{}" , ts) ;
0 commit comments