@@ -90,6 +90,7 @@ pub type c_ptrdiff_t = isize;
90
90
pub type c_ssize_t = isize ;
91
91
92
92
mod c_char_definition {
93
+ #[ cfg( bootstrap) ]
93
94
cfg_if ! {
94
95
// These are the targets on which c_char is unsigned. Usually the
95
96
// signedness is the same for all target_os values on a given architecture
@@ -178,9 +179,101 @@ mod c_char_definition {
178
179
pub type c_char = i8 ;
179
180
}
180
181
}
182
+ #[ cfg( not( bootstrap) ) ]
183
+ crate :: cfg_match! {
184
+ // These are the targets on which c_char is unsigned. Usually the
185
+ // signedness is the same for all target_os values on a given architecture
186
+ // but there are some exceptions (see isSignedCharDefault() in clang).
187
+ //
188
+ // aarch64:
189
+ // Section 10 "Arm C and C++ language mappings" in Procedure Call Standard for the Arm®
190
+ // 64-bit Architecture (AArch64) says C/C++ char is unsigned byte.
191
+ // https://github.com/ARM-software/abi-aa/blob/2024Q3/aapcs64/aapcs64.rst#arm-c-and-c-language-mappings
192
+ // arm:
193
+ // Section 8 "Arm C and C++ Language Mappings" in Procedure Call Standard for the Arm®
194
+ // Architecture says C/C++ char is unsigned byte.
195
+ // https://github.com/ARM-software/abi-aa/blob/2024Q3/aapcs32/aapcs32.rst#arm-c-and-c-language-mappings
196
+ // csky:
197
+ // Section 2.1.2 "Primary Data Type" in C-SKY V2 CPU Applications Binary Interface
198
+ // Standards Manual says ANSI C char is unsigned byte.
199
+ // https://github.com/c-sky/csky-doc/blob/9f7121f7d40970ba5cc0f15716da033db2bb9d07/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf
200
+ // Note: this doesn't seem to match Clang's default (https://github.com/rust-lang/rust/issues/129945).
201
+ // hexagon:
202
+ // Section 3.1 "Basic data type" in Qualcomm Hexagon™ Application
203
+ // Binary Interface User Guide says "By default, the `char` data type is unsigned."
204
+ // https://docs.qualcomm.com/bundle/publicresource/80-N2040-23_REV_K_Qualcomm_Hexagon_Application_Binary_Interface_User_Guide.pdf
205
+ // msp430:
206
+ // Section 2.1 "Basic Types" in MSP430 Embedded Application Binary
207
+ // Interface says "The char type is unsigned by default".
208
+ // https://www.ti.com/lit/an/slaa534a/slaa534a.pdf
209
+ // Note: this doesn't seem to match Clang's default (https://github.com/rust-lang/rust/issues/129945).
210
+ // powerpc/powerpc64:
211
+ // - PPC32 SysV: "Table 3-1 Scalar Types" in System V Application Binary Interface PowerPC
212
+ // Processor Supplement says ANSI C char is unsigned byte
213
+ // https://refspecs.linuxfoundation.org/elf/elfspec_ppc.pdf
214
+ // - PPC64 ELFv1: Section 3.1.4 "Fundamental Types" in 64-bit PowerPC ELF Application
215
+ // Binary Interface Supplement 1.9 says ANSI C is unsigned byte
216
+ // https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#FUND-TYPE
217
+ // - PPC64 ELFv2: Section 2.1.2.2 "Fundamental Types" in 64-Bit ELF V2 ABI Specification
218
+ // says char is unsigned byte
219
+ // https://openpowerfoundation.org/specifications/64bitelfabi/
220
+ // - AIX: XL C for AIX Language Reference says "By default, char behaves like an unsigned char."
221
+ // https://www.ibm.com/docs/en/xl-c-aix/13.1.3?topic=specifiers-character-types
222
+ // riscv32/riscv64:
223
+ // C/C++ type representations section in RISC-V Calling Conventions
224
+ // page in RISC-V ELF psABI Document says "char is unsigned."
225
+ // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/draft-20240829-13bfa9f54634cb60d86b9b333e109f077805b4b3/riscv-cc.adoc#cc-type-representations
226
+ // s390x:
227
+ // - ELF: "Table 1.1.: Scalar types" in ELF Application Binary Interface s390x Supplement
228
+ // Version 1.6.1 categorize ISO C char in unsigned integer
229
+ // https://github.com/IBM/s390x-abi/releases/tag/v1.6.1
230
+ // - z/OS: XL C/C++ Language Reference says: "By default, char behaves like an unsigned char."
231
+ // https://www.ibm.com/docs/en/zos/3.1.0?topic=specifiers-character-types
232
+ // Xtensa:
233
+ // - "The char type is unsigned by default for Xtensa processors."
234
+ //
235
+ // On the following operating systems, c_char is signed by default, regardless of architecture.
236
+ // Darwin (macOS, iOS, etc.):
237
+ // Apple targets' c_char is signed by default even on arm
238
+ // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Handle-data-types-and-data-alignment-properly
239
+ // Windows:
240
+ // Windows MSVC C++ Language Reference says "Microsoft-specific: Variables of type char
241
+ // are promoted to int as if from type signed char by default, unless the /J compilation
242
+ // option is used."
243
+ // https://learn.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-170#character-types)
244
+ // L4RE:
245
+ // The kernel builds with -funsigned-char on all targets (but useserspace follows the
246
+ // architecture defaults). As we only have a target for userspace apps so there are no
247
+ // special cases for L4RE below.
248
+ all(
249
+ not( windows) ,
250
+ not( target_vendor = "apple" ) ,
251
+ any(
252
+ target_arch = "aarch64" ,
253
+ target_arch = "arm" ,
254
+ target_arch = "csky" ,
255
+ target_arch = "hexagon" ,
256
+ target_arch = "msp430" ,
257
+ target_arch = "powerpc" ,
258
+ target_arch = "powerpc64" ,
259
+ target_arch = "riscv64" ,
260
+ target_arch = "riscv32" ,
261
+ target_arch = "s390x" ,
262
+ target_arch = "xtensa" ,
263
+ )
264
+ ) => {
265
+ pub type c_char = u8 ;
266
+ }
267
+ _ => {
268
+ // On every other target, c_char is signed.
269
+ pub type c_char = i8 ;
270
+ }
271
+ }
181
272
}
182
273
274
+
183
275
mod c_int_definition {
276
+ #[ cfg( bootstrap) ]
184
277
cfg_if ! {
185
278
if #[ cfg( any( target_arch = "avr" , target_arch = "msp430" ) ) ] {
186
279
pub type c_int = i16 ;
@@ -190,9 +283,21 @@ mod c_int_definition {
190
283
pub type c_uint = u32 ;
191
284
}
192
285
}
286
+ #[ cfg( not( bootstrap) ) ]
287
+ crate :: cfg_match! {
288
+ any( target_arch = "avr" , target_arch = "msp430" ) => {
289
+ pub type c_int = i16 ;
290
+ pub type c_uint = u16 ;
291
+ }
292
+ _ => {
293
+ pub type c_int = i32 ;
294
+ pub type c_uint = u32 ;
295
+ }
296
+ }
193
297
}
194
298
195
299
mod c_long_definition {
300
+ #[ cfg( bootstrap) ]
196
301
cfg_if ! {
197
302
if #[ cfg( all( target_pointer_width = "64" , not( windows) ) ) ] {
198
303
pub type c_long = i64 ;
@@ -203,6 +308,18 @@ mod c_long_definition {
203
308
pub type c_ulong = u32 ;
204
309
}
205
310
}
311
+ #[ cfg( not( bootstrap) ) ]
312
+ crate :: cfg_match! {
313
+ all( target_pointer_width = "64" , not( windows) ) => {
314
+ pub type c_long = i64 ;
315
+ pub type c_ulong = u64 ;
316
+ }
317
+ _ => {
318
+ // The minimal size of `long` in the C standard is 32 bits
319
+ pub type c_long = i32 ;
320
+ pub type c_ulong = u32 ;
321
+ }
322
+ }
206
323
}
207
324
208
325
// N.B., for LLVM to recognize the void pointer type and by extension
0 commit comments