Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion libwild/src/elf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5120,10 +5120,18 @@ fn write_dynamic_file<'data, A: Arch<Platform = Elf>>(
.dynsym_writer
.define_symbol(false, 0, 0, 0, name)?;

// TODO: Update this comment
// Note, we copy st_info, but not st_other since we don't want to copy the
// visibility. We want to emit the symbol with default visibility, otherwise the
// runtime loader may ignore dynamic relocations that reference the symbol.
entry.st_info = symbol.st_info();
let st_bind = if symbol.st_bind() == object::elf::STB_WEAK && !res.flags.is_weak() {
object::elf::STB_GLOBAL
} else if res.flags.is_weak() {
object::elf::STB_WEAK
} else {
symbol.st_bind()
};
entry.set_st_info(st_bind, symbol.st_type());

if let Some(versym) = table_writer.version_writer.versym.as_mut() {
copy_symbol_version(
Expand Down
2 changes: 1 addition & 1 deletion libwild/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ impl<'data, P: Platform> PreludeLayoutState<'data, P> {
let flags = resources
.per_symbol_flags
.get_atomic(canonical_target_id)
.fetch_or(ValueFlags::EXPORT_DYNAMIC);
.fetch_or(ValueFlags::EXPORT_DYNAMIC | ValueFlags::WEAK);

if !flags.has_resolution() {
queue.send_work::<A>(
Expand Down
15 changes: 15 additions & 0 deletions libwild/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,21 @@ pub(crate) fn resolve_symbol<'data, 'scope, P: Platform>(
symbol_id: local_symbol_id,
});
}

if symbol_file_id != file_id {
// TODO: this feels out of place, just by a gut feeling `ValueFlags::merge` should
// be a right place to handle it, but it doesn't work
let flags = resources.per_symbol_flags.get_atomic(symbol_id);
if local_symbol_attributes.is_weak {
if !flags.get().contains(ValueFlags::WEAK) {
flags.or_assign(ValueFlags::WEAK);
};
} else {
if flags.get().contains(ValueFlags::WEAK) {
flags.remove(ValueFlags::WEAK);
};
}
}
}
None => {
resources.outputs.undefined_symbols.push(UndefinedSymbol {
Expand Down
6 changes: 6 additions & 0 deletions libwild/src/symbol_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,9 @@ impl<'data, P: Platform> SymbolLoader<'data, P> for RegularObjectSymbolLoader<'_
if non_interposable {
flags |= ValueFlags::NON_INTERPOSABLE;
}
if sym.is_weak() {
flags |= ValueFlags::WEAK;
}
flags
}

Expand Down Expand Up @@ -1812,6 +1815,9 @@ impl<'data, P: Platform> SymbolLoader<'data, P> for DynamicObjectSymbolLoader<'_
if symbol.is_undefined() {
flags |= ValueFlags::ABSOLUTE;
}
if symbol.is_weak() {
flags |= ValueFlags::WEAK;
}
flags
}

Expand Down
13 changes: 13 additions & 0 deletions libwild/src/value_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ bitflags! {
/// contains the PLT stub address (for address equality), rather than the IRELATIVE GOT
/// entry which will be resolved to the actual function address at runtime.
const IFUNC_GOT_FOR_ADDRESS = 1 << 14;

const WEAK = 1 << 15;
}
}

Expand All @@ -115,6 +117,12 @@ impl ValueFlags {
if other.contains(ValueFlags::NON_INTERPOSABLE) {
*self |= ValueFlags::NON_INTERPOSABLE;
}
// TODO: doesn't have an effect, see the new TODO in resolution.rs
// if other.contains(ValueFlags::WEAK) {
// *self |= ValueFlags::WEAK;
// } else {
// *self &= !ValueFlags::WEAK;
// }
}

/// Returns the subset of the set flags that relate to resolutions.
Expand Down Expand Up @@ -235,6 +243,11 @@ impl ValueFlags {
|| self.contains(ValueFlags::GOT_TLS_DESCRIPTOR)
}

#[must_use]
pub(crate) fn is_weak(self) -> bool {
self.contains(ValueFlags::WEAK)
}

#[must_use]
pub(crate) fn raw(self) -> RawFlags {
RawFlags(self.bits())
Expand Down
4 changes: 0 additions & 4 deletions linker-diff/src/asm_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1680,10 +1680,6 @@ impl<R: RType> DynamicRelocation<'_, R> {
out.r_type = R::from_dynamic_relocation_kind(DynamicRelocationKind::GotEntry);
}

// TODO: Remove this. We currently don't propagate symbol visibility correctly when emitting
// dynamic symbols.
out.entry.is_weak = false;

out
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//#LinkArgs:-Wl,-z,now,-z,pack-relative-relocs
//#Shared:pack-relative-relocs-shared-1.c
//#DiffIgnore:section.rodata
// TODO: Enable linking with ld when fixing #1817
//#SkipLinker:ld
//#DiffIgnore:section.data
//#DiffIgnore:rel.R_AARCH64_ADR_GOT_PAGE.R_AARCH64_ADR_GOT_PAGE
//#EnableLinker:lld

int foo(void);

Expand Down
Loading