Skip to content

Commit 6228f5c

Browse files
committed
indicate ppc64 elf abi in e_flags
1 parent 5e0bdaa commit 6228f5c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,30 @@ 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.abi.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 options.abi is empty, then try to figure out which ABI to use.
394+
// Based loosely on llvm check (check llvm/include/llvm/TargetParser/Triple.h#isPPC64ELFv2ABI and clang/lib/Basic/Targets/PPC.h#PPC64TargetInfo)
395+
"" => {
396+
if sess.target.llvm_target.contains("bsd") || sess.target.llvm_target.contains("musl") {
397+
EF_PPC64_ABI_ELF_V2
398+
} else {
399+
EF_PPC64_ABI_ELF_V1
400+
}
401+
},
402+
// Fall back
403+
_ => EF_PPC64_ABI_UNKNOWN,
404+
}
405+
}
382406
_ => 0,
383407
}
384408
}

0 commit comments

Comments
 (0)