-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! A `Comdat` helps resolve linker errors for duplicate sections. | ||
// https://llvm.org/doxygen/IR_2Comdat_8h_source.html | ||
// https://stackoverflow.com/questions/1834597/what-is-the-comdat-section-used-for | ||
|
||
use llvm_sys::comdat::{LLVMComdatSelectionKind, LLVMSetComdatSelectionKind, LLVMGetComdatSelectionKind}; | ||
use llvm_sys::prelude::LLVMComdatRef; | ||
|
||
enum_rename!{ | ||
/// Determines how linker conflicts are to be resolved. | ||
ComdatSelectionKind <=> LLVMComdatSelectionKind { | ||
/// The linker may choose any COMDAT. | ||
Any <=> LLVMAnyComdatSelectionKind, | ||
/// The data referenced by the COMDAT must be the same. | ||
ExactMatch <=> LLVMExactMatchComdatSelectionKind, | ||
/// The linker will choose the largest COMDAT. | ||
Largest <=> LLVMLargestComdatSelectionKind, | ||
/// No other Module may specify this COMDAT. | ||
NoDuplicates <=> LLVMNoDuplicatesComdatSelectionKind, | ||
/// The data referenced by the COMDAT must be the same size. | ||
SameSize <=> LLVMSameSizeComdatSelectionKind, | ||
} | ||
} | ||
|
||
/// A `Comdat` determines how to resolve duplicate sections when linking. | ||
#[derive(Debug, PartialEq, Copy, Clone)] | ||
pub struct Comdat(pub(crate) LLVMComdatRef); | ||
|
||
impl Comdat { | ||
pub(crate) fn new(comdat: LLVMComdatRef) -> Self { | ||
debug_assert!(!comdat.is_null()); | ||
|
||
Comdat(comdat) | ||
} | ||
|
||
/// Gets what kind of `Comdat` this is. | ||
pub fn get_selection_kind(&self) -> ComdatSelectionKind { | ||
let kind_ptr = unsafe { | ||
LLVMGetComdatSelectionKind(self.0) | ||
}; | ||
|
||
ComdatSelectionKind::new(kind_ptr) | ||
} | ||
|
||
/// Sets what kind of `Comdat` this should be. | ||
pub fn set_selection_kind(&self, kind: ComdatSelectionKind) { | ||
unsafe { | ||
LLVMSetComdatSelectionKind(self.0, kind.as_llvm_enum()) | ||
} | ||
} | ||
} |