Skip to content

Commit 1c16e08

Browse files
refactor: Move some ELF-specific dynamic allocation code (#1728)
Issue #1538
1 parent 9312851 commit 1c16e08

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

libwild/src/elf.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,21 @@ impl platform::Platform for Elf {
460460
.sum::<usize>(), "resolved relocations");
461461
}
462462

463+
fn activate_dynamic<'data>(
464+
state: &mut layout::DynamicLayoutState<'data, Self>,
465+
common: &mut CommonGroupState<'data, Self>,
466+
) {
467+
common.allocate(
468+
part_id::DYNAMIC,
469+
size_of::<crate::elf::DynamicEntry>() as u64,
470+
);
471+
472+
common.allocate(part_id::DYNSTR, state.lib_name.len() as u64 + 1);
473+
474+
state.format_specific_state.symbol_versions_needed =
475+
vec![false; state.object.verdefnum as usize];
476+
}
477+
463478
fn pre_finalise_sizes_prelude<'scope, 'data>(
464479
prelude: &mut layout::PreludeLayoutState<'data, Self>,
465480
common: &mut layout::CommonGroupState<'data, Self>,
@@ -2164,10 +2179,6 @@ impl<'data> platform::ObjectFile<'data> for File<'data> {
21642179
Ok(())
21652180
}
21662181

2167-
fn activate_dynamic(&self, state: &mut DynamicLayoutStateExt<'data>) {
2168-
state.symbol_versions_needed = vec![false; self.verdefnum as usize];
2169-
}
2170-
21712182
fn finalise_sizes_dynamic(
21722183
&self,
21732184
lib_name: &[u8],

libwild/src/layout.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ pub(crate) struct DynamicLayoutState<'data, P: Platform> {
10761076
input: InputRef<'data>,
10771077
file_id: FileId,
10781078
pub(crate) symbol_id_range: SymbolIdRange,
1079-
lib_name: &'data [u8],
1079+
pub(crate) lib_name: &'data [u8],
10801080

10811081
pub(crate) format_specific_state: P::DynamicLayoutStateExt<'data>,
10821082
}
@@ -4554,15 +4554,7 @@ impl<'data, P: Platform> DynamicLayoutState<'data, P> {
45544554
queue: &mut LocalWorkQueue,
45554555
scope: &Scope<'scope>,
45564556
) -> Result {
4557-
self.object
4558-
.activate_dynamic(&mut self.format_specific_state);
4559-
4560-
common.allocate(
4561-
part_id::DYNAMIC,
4562-
size_of::<crate::elf::DynamicEntry>() as u64,
4563-
);
4564-
4565-
common.allocate(part_id::DYNSTR, self.lib_name.len() as u64 + 1);
4557+
P::activate_dynamic(self, common);
45664558

45674559
self.request_all_undefined_symbols::<A>(resources, queue, scope)
45684560
}

libwild/src/platform.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ pub(crate) trait Platform: Copy + Send + Sync + Sized + std::fmt::Debug + 'stati
284284
/// Called after GC phase has completed. Mostly useful for platform-specific logging.
285285
fn finalise_find_required_sections(groups: &[layout::GroupState<Self>]);
286286

287+
/// The dynamic object will be linked against. This is a chance to perform extra initialisation
288+
/// of `state`.
289+
fn activate_dynamic<'data>(
290+
state: &mut layout::DynamicLayoutState<'data, Self>,
291+
common: &mut CommonGroupState<'data, Self>,
292+
);
293+
287294
fn pre_finalise_sizes_prelude<'scope, 'data>(
288295
prelude: &mut layout::PreludeLayoutState<'data, Self>,
289296
common: &mut layout::CommonGroupState<'data, Self>,
@@ -663,13 +670,6 @@ pub(crate) trait ObjectFile<'data>: Sized + Send + Sync + std::fmt::Debug + 'dat
663670

664671
fn symbol_versions(&self) -> &[<Self::Platform as Platform>::SymbolVersionIndex];
665672

666-
/// The dynamic object will be linked against. This is a chance to perform extra initialisation
667-
/// of `state`.
668-
fn activate_dynamic(
669-
&self,
670-
state: &mut <Self::Platform as Platform>::DynamicLayoutStateExt<'data>,
671-
);
672-
673673
fn dynamic_symbol_used(
674674
&self,
675675
symbol_index: object::SymbolIndex,

0 commit comments

Comments
 (0)