@@ -92,58 +92,76 @@ pub type c_ssize_t = isize;
92
92
mod c_char_definition {
93
93
cfg_if ! {
94
94
// These are the targets on which c_char is unsigned.
95
- if #[ cfg( any(
96
- all(
97
- target_os = "linux" ,
98
- any(
99
- target_arch = "aarch64" ,
100
- target_arch = "arm" ,
101
- target_arch = "hexagon" ,
102
- target_arch = "powerpc" ,
103
- target_arch = "powerpc64" ,
104
- target_arch = "s390x" ,
105
- target_arch = "riscv64" ,
106
- target_arch = "riscv32" ,
107
- target_arch = "csky"
108
- )
95
+ // These should match the Clang's defaults, except when Clang does not match the ABI's defaults.
96
+ //
97
+ // aarch64:
98
+ // Section 10 "Arm C and C++ language mappings" in Procedure Call Standard for the Arm®
99
+ // 64-bit Architecture (AArch64) says C/C++ char is unsigned byte.
100
+ // https://github.com/ARM-software/abi-aa/blob/2024Q3/aapcs64/aapcs64.rst#arm-c-and-c-language-mappings
101
+ // arm:
102
+ // Section 8 "Arm C and C++ Language Mappings" in Procedure Call Standard for the Arm®
103
+ // Architecture says C/C++ char is unsigned byte.
104
+ // https://github.com/ARM-software/abi-aa/blob/2024Q3/aapcs32/aapcs32.rst#arm-c-and-c-language-mappings
105
+ // csky:
106
+ // Section 2.1.2 "Primary Data Type" in C-SKY V2 CPU Applications Binary Interface
107
+ // Standards Manual says ANSI C char is unsigned byte.
108
+ // https://github.com/c-sky/csky-doc/blob/9f7121f7d40970ba5cc0f15716da033db2bb9d07/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf
109
+ // Note: this doesn't seem to match Clang's default (https://github.com/rust-lang/rust/issues/129945).
110
+ // hexagon:
111
+ // Section 3.1 "Basic data type" in Qualcomm Hexagon™ Application
112
+ // Binary Interface User Guide says "By default, the `char` data type is unsigned."
113
+ // https://docs.qualcomm.com/bundle/publicresource/80-N2040-23_REV_K_Qualcomm_Hexagon_Application_Binary_Interface_User_Guide.pdf
114
+ // msp430:
115
+ // Section 2.1 "Basic Types" in MSP430 Embedded Application Binary
116
+ // Interface says "The char type is unsigned by default".
117
+ // https://www.ti.com/lit/an/slaa534a/slaa534a.pdf
118
+ // Note: this doesn't seem to match Clang's default (https://github.com/rust-lang/rust/issues/129945).
119
+ // powerpc/powerpc64:
120
+ // - PPC32 SysV: "Table 3-1 Scalar Types" in System V Application Binary Interface PowerPC
121
+ // Processor Supplement says ANSI C char is unsigned byte
122
+ // https://refspecs.linuxfoundation.org/elf/elfspec_ppc.pdf
123
+ // - PPC64 ELFv1: Section 3.1.4 "Fundamental Types" in 64-bit PowerPC ELF Application
124
+ // Binary Interface Supplement 1.9 says ANSI C is unsigned byte
125
+ // https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#FUND-TYPE
126
+ // - PPC64 ELFv2: Section 2.1.2.2 "Fundamental Types" in 64-Bit ELF V2 ABI Specification
127
+ // says char is unsigned byte
128
+ // https://openpowerfoundation.org/specifications/64bitelfabi/
129
+ // - AIX: XL C for AIX Language Reference says "By default, char behaves like an unsigned char."
130
+ // https://www.ibm.com/docs/en/xl-c-aix/13.1.3?topic=specifiers-character-types
131
+ // riscv32/riscv64:
132
+ // C/C++ type representations section in RISC-V Calling Conventions
133
+ // page in RISC-V ELF psABI Document says "char is unsigned."
134
+ // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/draft-20240829-13bfa9f54634cb60d86b9b333e109f077805b4b3/riscv-cc.adoc#cc-type-representations
135
+ // s390x:
136
+ // - ELF: "Table 1.1.: Scalar types" in ELF Application Binary Interface s390x Supplement
137
+ // Version 1.6.1 categorize ISO C char in unsigned integer
138
+ // https://github.com/IBM/s390x-abi/releases/tag/v1.6.1
139
+ // - z/OS: XL C/C++ Language Reference says: "By default, char behaves like an unsigned char."
140
+ // https://www.ibm.com/docs/en/zos/3.1.0?topic=specifiers-character-types
141
+ //
142
+ // On the following systems, c_char is signed by default, regardless of architecture.
143
+ // Darwin (macOS, iOS, etc.):
144
+ // Apple targets' c_char is signed by default even on arm
145
+ // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Handle-data-types-and-data-alignment-properly
146
+ // Windows:
147
+ // Windows MSVC C++ Language Reference says "Microsoft-specific: Variables of type char
148
+ // are promoted to int as if from type signed char by default, unless the /J compilation
149
+ // option is used."
150
+ // https://learn.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-170#character-types)
151
+ if #[ cfg( all(
152
+ not( any( target_vendor = "apple" , windows) ) ,
153
+ any(
154
+ target_arch = "aarch64" ,
155
+ target_arch = "arm" ,
156
+ target_arch = "csky" ,
157
+ target_arch = "hexagon" ,
158
+ target_arch = "msp430" ,
159
+ target_arch = "powerpc" ,
160
+ target_arch = "powerpc64" ,
161
+ target_arch = "riscv32" ,
162
+ target_arch = "riscv64" ,
163
+ target_arch = "s390x" ,
109
164
) ,
110
- all( target_os = "android" , any( target_arch = "aarch64" , target_arch = "arm" ) ) ,
111
- all( target_os = "l4re" , target_arch = "x86_64" ) ,
112
- all(
113
- any( target_os = "freebsd" , target_os = "openbsd" , target_os = "rtems" ) ,
114
- any(
115
- target_arch = "aarch64" ,
116
- target_arch = "arm" ,
117
- target_arch = "powerpc" ,
118
- target_arch = "powerpc64" ,
119
- target_arch = "riscv64"
120
- )
121
- ) ,
122
- all(
123
- target_os = "netbsd" ,
124
- any(
125
- target_arch = "aarch64" ,
126
- target_arch = "arm" ,
127
- target_arch = "powerpc" ,
128
- target_arch = "riscv64"
129
- )
130
- ) ,
131
- all(
132
- target_os = "vxworks" ,
133
- any(
134
- target_arch = "aarch64" ,
135
- target_arch = "arm" ,
136
- target_arch = "powerpc64" ,
137
- target_arch = "powerpc"
138
- )
139
- ) ,
140
- all(
141
- target_os = "fuchsia" ,
142
- any( target_arch = "aarch64" , target_arch = "riscv64" )
143
- ) ,
144
- all( target_os = "nto" , target_arch = "aarch64" ) ,
145
- target_os = "horizon" ,
146
- target_os = "aix" ,
147
165
) ) ] {
148
166
pub type c_char = u8 ;
149
167
} else {
0 commit comments