@@ -271,6 +271,8 @@ pub(super) fn elf_os_abi(sess: &Session) -> u8 {
271271pub ( super ) fn elf_e_flags ( architecture : Architecture , sess : & Session ) -> u32 {
272272 match architecture {
273273 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".
274276 let is_32bit = architecture == Architecture :: Mips ;
275277 let mut e_flags = match sess. target . options . cpu . as_ref ( ) {
276278 "mips1" if is_32bit => elf:: EF_MIPS_ARCH_1 ,
@@ -293,7 +295,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
293295 } ;
294296
295297 // 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 .
297299 match sess. target . options . llvm_abiname . as_ref ( ) {
298300 "o32" if is_32bit => e_flags |= elf:: EF_MIPS_ABI_O32 ,
299301 "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 {
307309 } ;
308310
309311 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.
310321 e_flags |= elf:: EF_MIPS_PIC | elf:: EF_MIPS_CPIC ;
311322 }
312323 if sess. target . options . cpu . contains ( "r6" ) {
0 commit comments