pub enum Linkage {
Show 17 variants
Appending,
AvailableExternally,
Common,
DLLExport,
DLLImport,
External,
ExternalWeak,
Ghost,
Internal,
LinkerPrivate,
LinkerPrivateWeak,
LinkOnceAny,
LinkOnceODRAutoHide,
LinkOnceODR,
Private,
WeakAny,
WeakODR,
}
Expand description
This enum defines how to link a global variable or function in a module. The variant documentation is mostly taken straight from LLVM’s own documentation except for some minor clarification.
It is illegal for a function declaration to have any linkage type other than external or extern_weak.
All Global Variables, Functions and Aliases can have one of the following DLL storage class: DLLImport
& DLLExport
.
Variants§
Appending
Appending
linkage may only be applied to global variables of pointer to array type. When two global
variables with appending linkage are linked together, the two global arrays are appended together.
This is the LLVM, typesafe, equivalent of having the system linker append together “sections” with
identical names when .o files are linked. Unfortunately this doesn’t correspond to any feature in .o
files, so it can only be used for variables like llvm.global_ctors which llvm interprets specially.
AvailableExternally
Globals with AvailableExternally
linkage are never emitted into the object file corresponding to
the LLVM module. From the linker’s perspective, an AvailableExternally
global is equivalent to an
external declaration. They exist to allow inlining and other optimizations to take place given
knowledge of the definition of the global, which is known to be somewhere outside the module. Globals
with AvailableExternally
linkage are allowed to be discarded at will, and allow inlining and other
optimizations. This linkage type is only allowed on definitions, not declarations.
Common
Common
linkage is most similar to “weak” linkage, but they are used for tentative definitions
in C, such as “int X;” at global scope. Symbols with Common linkage are merged in the same way as
weak symbols, and they may not be deleted if unreferenced. Common
symbols may not have an explicit
section, must have a zero initializer, and may not be marked ‘constant’. Functions and aliases may
not have Common
linkage.
DLLExport
DLLExport
causes the compiler to provide a global pointer to a pointer in a DLL, so that it can be
referenced with the dllimport attribute. On Microsoft Windows targets, the pointer name is formed by
combining _imp and the function or variable name. Since this storage class exists for defining a dll
interface, the compiler, assembler and linker know it is externally referenced and must refrain from
deleting the symbol.
DLLImport
DLLImport
causes the compiler to reference a function or variable via a global pointer to a pointer
that is set up by the DLL exporting the symbol. On Microsoft Windows targets, the pointer name is
formed by combining _imp and the function or variable name.
External
If none of the other identifiers are used, the global is externally visible, meaning that it participates in linkage and can be used to resolve external symbol references.
ExternalWeak
The semantics of this linkage follow the ELF object file model: the symbol is weak until linked, if not linked, the symbol becomes null instead of being an undefined reference.
Ghost
FIXME: Unknown linkage type
Internal
Similar to private, but the value shows as a local symbol (STB_LOCAL in the case of ELF) in the object file. This corresponds to the notion of the ‘static’ keyword in C.
LinkerPrivate
FIXME: Unknown linkage type
LinkerPrivateWeak
FIXME: Unknown linkage type
LinkOnceAny
Globals with LinkOnceAny
linkage are merged with other globals of the same name when linkage occurs.
This can be used to implement some forms of inline functions, templates, or other code which must be
generated in each translation unit that uses it, but where the body may be overridden with a more
definitive definition later. Unreferenced LinkOnceAny
globals are allowed to be discarded. Note that
LinkOnceAny
linkage does not actually allow the optimizer to inline the body of this function into
callers because it doesn’t know if this definition of the function is the definitive definition within
the program or whether it will be overridden by a stronger definition. To enable inlining and other
optimizations, use LinkOnceODR
linkage.
LinkOnceODRAutoHide
FIXME: Unknown linkage type
LinkOnceODR
Some languages allow differing globals to be merged, such as two functions with different semantics.
Other languages, such as C++, ensure that only equivalent globals are ever merged (the “one definition
rule” — “ODR”). Such languages can use the LinkOnceODR
and WeakODR
linkage types to indicate that
the global will only be merged with equivalent globals. These linkage types are otherwise the same
as their non-odr versions.
Private
Global values with Private
linkage are only directly accessible by objects in the current module.
In particular, linking code into a module with a private global value may cause the private to be
renamed as necessary to avoid collisions. Because the symbol is private to the module, all references
can be updated. This doesn’t show up in any symbol table in the object file.
WeakAny
WeakAny
linkage has the same merging semantics as linkonce linkage, except that unreferenced globals
with weak linkage may not be discarded. This is used for globals that are declared WeakAny in C source code.
WeakODR
Some languages allow differing globals to be merged, such as two functions with different semantics.
Other languages, such as C++, ensure that only equivalent globals are ever merged (the “one definition
rule” — “ODR”). Such languages can use the LinkOnceODR
and WeakODR
linkage types to indicate that
the global will only be merged with equivalent globals. These linkage types are otherwise the same
as their non-odr versions.
Trait Implementations§
source§impl From<LLVMLinkage> for Linkage
impl From<LLVMLinkage> for Linkage
source§fn from(src: LLVMLinkage) -> Self
fn from(src: LLVMLinkage) -> Self
source§impl Into<LLVMLinkage> for Linkage
impl Into<LLVMLinkage> for Linkage
source§fn into(self) -> LLVMLinkage
fn into(self) -> LLVMLinkage
source§impl Ord for Linkage
impl Ord for Linkage
source§impl PartialEq for Linkage
impl PartialEq for Linkage
source§impl PartialOrd for Linkage
impl PartialOrd for Linkage
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Linkage
impl Eq for Linkage
impl StructuralPartialEq for Linkage
Auto Trait Implementations§
impl Freeze for Linkage
impl RefUnwindSafe for Linkage
impl Send for Linkage
impl Sync for Linkage
impl Unpin for Linkage
impl UnwindSafe for Linkage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more