@@ -271,6 +271,8 @@ pub(super) fn elf_os_abi(sess: &Session) -> u8 {
271
271
pub ( super ) fn elf_e_flags ( architecture : Architecture , sess : & Session ) -> u32 {
272
272
match architecture {
273
273
Architecture :: Mips | Architecture :: Mips64 | Architecture :: Mips64_N32 => {
274
+ // "N32" indicates an "ILP32" data model on a 64-bit MIPS CPU
275
+ // like SPARC's "v8+", x86_64's "x32", or the watchOS "arm64_32".
274
276
let is_32bit = architecture == Architecture :: Mips ;
275
277
let mut e_flags = match sess. target . options . cpu . as_ref ( ) {
276
278
"mips1" if is_32bit => elf:: EF_MIPS_ARCH_1 ,
@@ -293,7 +295,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
293
295
} ;
294
296
295
297
// If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS,
296
- // which is the only option.
298
+ // which is the only "true" 32-bit option that LLVM supports .
297
299
match sess. target . options . llvm_abiname . as_ref ( ) {
298
300
"o32" if is_32bit => e_flags |= elf:: EF_MIPS_ABI_O32 ,
299
301
"n32" if !is_32bit => e_flags |= elf:: EF_MIPS_ABI2 ,
@@ -307,6 +309,15 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
307
309
} ;
308
310
309
311
if sess. target . options . relocation_model != RelocModel :: Static {
312
+ // PIC means position-independent code. CPIC means "calls PIC".
313
+ // CPIC was mutually exclusive with PIC according to
314
+ // the SVR4 MIPS ABI https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
315
+ // and should have only appeared on static objects with dynamically calls.
316
+ // At some point someone (GCC?) decided to set CPIC even for PIC.
317
+ // Nowadays various things expect both set on the same object file
318
+ // and may even error if you mix CPIC and non-CPIC object files,
319
+ // despite that being the entire point of the CPIC ABI extension!
320
+ // As we are in Rome, we do as the Romans do.
310
321
e_flags |= elf:: EF_MIPS_PIC | elf:: EF_MIPS_CPIC ;
311
322
}
312
323
if sess. target . options . cpu . contains ( "r6" ) {
0 commit comments