Skip to content

Commit 9c1180b

Browse files
committed
indicate ppc64 elf abi in e_flags
1 parent 7859a37 commit 9c1180b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,24 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
379379
};
380380
e_flags
381381
}
382+
Architecture::PowerPc64 => {
383+
const EF_PPC64_ABI_UNKNOWN: u32 = 0;
384+
const EF_PPC64_ABI_ELF_V1: u32 = 1;
385+
const EF_PPC64_ABI_ELF_V2: u32 = 2;
386+
387+
match sess.target.options.llvm_abiname.as_ref() {
388+
// If the flags do not correctly indicate the ABI,
389+
// linkers such as ld.lld assume that the ppc64 object files are always ELFv2
390+
// which leads to broken binaries if ELFv1 is used for the object files.
391+
"elfv1" => EF_PPC64_ABI_ELF_V1,
392+
"elfv2" => EF_PPC64_ABI_ELF_V2,
393+
"" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
394+
bug!("No ABI specified for this PPC64 ELF target");
395+
}
396+
// Fall back
397+
_ => EF_PPC64_ABI_UNKNOWN,
398+
}
399+
}
382400
_ => 0,
383401
}
384402
}

tests/ui/check-cfg/well-known-values.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
129129
LL | target_abi = "_UNEXPECTED_VALUE",
130130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131131
|
132-
= note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elfv1`, `elfv2`, `fortanix`, `ilp32`, `ilp32e`, `llvm`, `macabi`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, and `x32`
132+
= note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `fortanix`, `ilp32`, `ilp32e`, `llvm`, `macabi`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, and `x32`
133133
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
134134

135135
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`

0 commit comments

Comments
 (0)