cg_llvm: Reuse LLVM-C Comdat support

Migrate `llvm::set_comdat` and `llvm::SetUniqueComdat` to LLVM-C FFI.

Note, now we can call `llvm::set_comdat` only when the target actually
supports adding comdat. As this has no convenient LLVM-C API, we
implement this as `TargetOptions::supports_comdat`.

Co-authored-by: Stuart Cook <Zalathar@users.noreply.github.com>
This commit is contained in:
Jubilee Young
2024-10-18 00:31:28 -07:00
parent 888efe74a3
commit 45d61b0d26
6 changed files with 32 additions and 10 deletions

View File

@@ -2514,6 +2514,13 @@ fn add_link_args(link_args: &mut LinkArgs, flavor: LinkerFlavor, args: &[&'stati
add_link_args_iter(link_args, flavor, args.iter().copied().map(Cow::Borrowed))
}
impl TargetOptions {
pub fn supports_comdat(&self) -> bool {
// XCOFF and MachO don't support COMDAT.
!self.is_like_aix && !self.is_like_osx
}
}
impl TargetOptions {
fn link_args(flavor: LinkerFlavor, args: &[&'static str]) -> LinkArgs {
let mut link_args = LinkArgs::new();