@@ -92,58 +92,77 @@ pub type c_ssize_t = isize;
9292mod c_char_definition {
9393 cfg_if ! {
9494 // 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://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.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
130+ // behaves like an unsigned char."
131+ // https://www.ibm.com/docs/en/xl-c-aix/13.1.3?topic=specifiers-character-types
132+ // riscv32/riscv64:
133+ // C/C++ type representations section in RISC-V Calling Conventions
134+ // page in RISC-V ELF psABI Document says "char is unsigned."
135+ // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/draft-20240829-13bfa9f54634cb60d86b9b333e109f077805b4b3/riscv-cc.adoc#cc-type-representations
136+ // s390x:
137+ // - ELF: "Table 1.1.: Scalar types" in ELF Application Binary Interface s390x Supplement
138+ // Version 1.6.1 categorize ISO C char in unsigned integer
139+ // https://github.com/IBM/s390x-abi/releases/tag/v1.6.1
140+ // - z/OS: XL C/C++ Language Reference says: "By default, char behaves like an unsigned char."
141+ // https://www.ibm.com/docs/en/zos/3.1.0?topic=specifiers-character-types
142+ //
143+ // On the following systems, c_char is signed by default, regardless of architecture.
144+ // Darwin (macOS, iOS, etc.):
145+ // Apple targets' c_char is signed by default even on arm
146+ // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Handle-data-types-and-data-alignment-properly
147+ // Windows:
148+ // Windows MSVC C++ Language Reference says "Microsoft-specific: Variables of type char
149+ // are promoted to int as if from type signed char by default, unless the /J compilation
150+ // option is used."
151+ // https://learn.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-170#character-types)
152+ if #[ cfg( all(
153+ not( any( target_vendor = "apple" , windows) ) ,
154+ any(
155+ target_arch = "aarch64" ,
156+ target_arch = "arm" ,
157+ target_arch = "csky" ,
158+ target_arch = "hexagon" ,
159+ target_arch = "msp430" ,
160+ target_arch = "powerpc" ,
161+ target_arch = "powerpc64" ,
162+ target_arch = "riscv32" ,
163+ target_arch = "riscv64" ,
164+ target_arch = "s390x" ,
109165 ) ,
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" ,
147166 ) ) ] {
148167 pub type c_char = u8 ;
149168 } else {
0 commit comments