@@ -270,45 +270,50 @@ pub(super) fn elf_os_abi(sess: &Session) -> u8 {
270
270
271
271
pub ( super ) fn elf_e_flags ( architecture : Architecture , sess : & Session ) -> u32 {
272
272
match architecture {
273
- Architecture :: Mips => {
274
- let arch = match sess. target . options . cpu . as_ref ( ) {
275
- "mips1" => elf:: EF_MIPS_ARCH_1 ,
276
- "mips2" => elf:: EF_MIPS_ARCH_2 ,
273
+ Architecture :: Mips | Architecture :: Mips64 | Architecture :: Mips64_N32 => {
274
+ let is_32bit = architecture == Architecture :: Mips ;
275
+ let mut e_flags = match sess. target . options . cpu . as_ref ( ) {
276
+ "mips1" if is_32bit => elf:: EF_MIPS_ARCH_1 ,
277
+ "mips2" if is_32bit => elf:: EF_MIPS_ARCH_2 ,
277
278
"mips3" => elf:: EF_MIPS_ARCH_3 ,
278
279
"mips4" => elf:: EF_MIPS_ARCH_4 ,
279
280
"mips5" => elf:: EF_MIPS_ARCH_5 ,
280
- s if s. contains ( "r6" ) => elf:: EF_MIPS_ARCH_32R6 ,
281
- _ => elf:: EF_MIPS_ARCH_32R2 ,
281
+ "mips32r2" if is_32bit => elf:: EF_MIPS_ARCH_32R2 ,
282
+ "mips32r6" if is_32bit => elf:: EF_MIPS_ARCH_32R6 ,
283
+ "mips64r2" if !is_32bit => elf:: EF_MIPS_ARCH_64R2 ,
284
+ "mips64r6" if !is_32bit => elf:: EF_MIPS_ARCH_64R6 ,
285
+ s if s. starts_with ( "mips32" ) && !is_32bit => {
286
+ sess. dcx ( ) . fatal ( format ! ( "invalid CPU `{}` for 64-bit MIPS target" , s) )
287
+ }
288
+ s if s. starts_with ( "mips64" ) && is_32bit => {
289
+ sess. dcx ( ) . fatal ( format ! ( "invalid CPU `{}` for 32-bit MIPS target" , s) )
290
+ }
291
+ _ if is_32bit => elf:: EF_MIPS_ARCH_32R2 ,
292
+ _ => elf:: EF_MIPS_ARCH_64R2 ,
282
293
} ;
283
294
284
- let mut e_flags = elf:: EF_MIPS_CPIC | arch;
285
-
286
- // If the ABI is explicitly given, use it or default to O32.
287
- match sess. target . options . llvm_abiname . to_lowercase ( ) . as_str ( ) {
288
- "n32" => e_flags |= elf:: EF_MIPS_ABI2 ,
289
- "o32" => e_flags |= elf:: EF_MIPS_ABI_O32 ,
290
- _ => e_flags |= elf:: EF_MIPS_ABI_O32 ,
295
+ // If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS,
296
+ // which is the only option.
297
+ match sess. target . options . llvm_abiname . as_ref ( ) {
298
+ "o32" if is_32bit => e_flags |= elf:: EF_MIPS_ABI_O32 ,
299
+ "n32" if !is_32bit => e_flags |= elf:: EF_MIPS_ABI2 ,
300
+ "n64" if !is_32bit => { }
301
+ "" if is_32bit => e_flags |= elf:: EF_MIPS_ABI_O32 ,
302
+ "" => sess. dcx ( ) . fatal ( "LLVM ABI must be specifed for 64-bit MIPS targets" ) ,
303
+ s if is_32bit => {
304
+ sess. dcx ( ) . fatal ( format ! ( "invalid LLVM ABI `{}` for 32-bit MIPS target" , s) )
305
+ }
306
+ s => sess. dcx ( ) . fatal ( format ! ( "invalid LLVM ABI `{}` for 64-bit MIPS target" , s) ) ,
291
307
} ;
292
308
293
309
if sess. target . options . relocation_model != RelocModel :: Static {
294
- e_flags |= elf:: EF_MIPS_PIC ;
310
+ e_flags |= elf:: EF_MIPS_PIC | elf :: EF_MIPS_CPIC ;
295
311
}
296
312
if sess. target . options . cpu . contains ( "r6" ) {
297
313
e_flags |= elf:: EF_MIPS_NAN2008 ;
298
314
}
299
315
e_flags
300
316
}
301
- Architecture :: Mips64 => {
302
- // copied from `mips64el-linux-gnuabi64-gcc foo.c -c`
303
- let e_flags = elf:: EF_MIPS_CPIC
304
- | elf:: EF_MIPS_PIC
305
- | if sess. target . options . cpu . contains ( "r6" ) {
306
- elf:: EF_MIPS_ARCH_64R6 | elf:: EF_MIPS_NAN2008
307
- } else {
308
- elf:: EF_MIPS_ARCH_64R2
309
- } ;
310
- e_flags
311
- }
312
317
Architecture :: Riscv32 | Architecture :: Riscv64 => {
313
318
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
314
319
let mut e_flags: u32 = 0x0 ;
0 commit comments