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
36 changes: 20 additions & 16 deletions libwild/src/elf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ use uuid::Uuid;
use zerocopy::FromBytes;
use zerocopy::transmute_mut;

mod debug_relocations;

type ElfLayout<'data, C> = Layout<'data, elf::Elf<C>>;

/// A cache for managing ELF relocations and optimization of relocation entries.
Expand Down Expand Up @@ -2464,7 +2466,7 @@ fn write_debug_section<'data, C: ElfClass, A: Arch<Platform = elf::Elf<C>>>(
let relocations = object.relocations(section_index)?;
let result = match relocations {
elf::RelocationList::Rela(rela) => {
apply_debug_rela_relocations::<C, A>(object, out, section_index, rela, layout)
debug_relocations::apply_rela::<C, A>(object, out, section_index, rela, layout)
}
elf::RelocationList::Crel(crel_iter) => {
apply_debug_relocations::<C, A, elf::ElfCrel<C>, _>(
Expand Down Expand Up @@ -2731,7 +2733,7 @@ fn apply_relocations<
Ok(())
}

const PARALLEL_DEBUG_RELOCATION_MIN: usize = 64 * 1024;
const PARALLEL_DEBUG_RELOCATION_MIN: usize = 16;
// Byte and bit-mask relocations modify at most eight bytes. A paired ULEB128 relocation can
// modify all ten bytes required to encode a u64.
const MAX_DEBUG_RELOCATION_WRITE_SIZE: u64 = u64::BITS.div_ceil(7) as u64;
Expand Down Expand Up @@ -3002,20 +3004,7 @@ fn apply_debug_relocations_impl<
output_offset: u64,
previous: Option<R>,
) -> Result<usize> {
let section_name = object.object.section_name(section_index)?;

// TODO: Starting with DWARF 6, the tombstone value will be defined as -1 and -2.
// However, the change is premature as consumers of the DWARF format don't fully support
// the new tombstone values.
//
// Link: https://dwarfstd.org/issues/200609.1.html
let tombstone_value: u64 =
if section_name == DEBUG_LOC_SECTION_NAME || section_name == DEBUG_RANGES_SECTION_NAME {
// These sections use zero as a list terminator.
1
} else {
0
};
let tombstone_value = debug_tombstone_value(object.object.section_name(section_index)?);

let mut relocation_count = 0;
let mut relocation_cache = RelocationCache {
Expand Down Expand Up @@ -3050,6 +3039,21 @@ fn apply_debug_relocations_impl<
Ok(relocation_count)
}

/// The value written by a debug relocation against a discarded section.
fn debug_tombstone_value(section_name: &[u8]) -> u64 {
// TODO: Starting with DWARF 6, the tombstone value will be defined as -1 and -2.
// However, the change is premature as consumers of the DWARF format don't fully support
// the new tombstone values.
//
// Link: https://dwarfstd.org/issues/200609.1.html
if section_name == DEBUG_LOC_SECTION_NAME || section_name == DEBUG_RANGES_SECTION_NAME {
// These sections use zero as a list terminator.
1
} else {
0
}
}

fn record_debug_relocations<C: ElfClass>(
object: &ObjectLayout<elf::Elf<C>>,
section_index: object::SectionIndex,
Expand Down
Loading
Loading