Skip to content

Commit

Permalink
Split init-fini-arrays into separate features. (#83)
Browse files Browse the repository at this point in the history
Define separate features for init and fini arrays. Some use cases need
init arrays and don't need fini arrays due to using mechanisms like
`__cxa_atexit` instead.
  • Loading branch information
sunfishcode committed Oct 17, 2023
1 parent 242242f commit 6aac3da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ signal = ["rustix/runtime"]
param = ["rustix/param"]

# Enable support for ELF `.init_array` and `.fini_array`.
init-fini-arrays = []
init-fini-arrays = ["init-array", "fini-array"]

# Enable support for ELF `.init_array`.
init-array = []

# Enable support for ELF `.fini_array`.
fini-array = []

# Enable highly experimental support for performing startup-time relocations,
# needed to support statically-linked PIE executables.
Expand Down
4 changes: 2 additions & 2 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub(super) unsafe extern "C" fn entry(mem: *mut usize) -> ! {
init_runtime(mem, envp);

// Call the functions registered via `.init_array`.
#[cfg(feature = "init-fini-arrays")]
#[cfg(feature = "init-array")]
{
use core::arch::asm;
use core::ffi::c_void;
Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn exit(status: c_int) -> ! {
// Call the `.fini_array` functions, in reverse order. We only do this
// in "origin-program" mode because if we're using libc, libc does this
// in `exit`.
#[cfg(all(feature = "init-fini-arrays", feature = "origin-program"))]
#[cfg(all(feature = "fini-array", feature = "origin-program"))]
unsafe {
use core::arch::asm;
use core::ffi::c_void;
Expand Down

0 comments on commit 6aac3da

Please sign in to comment.