Skip to content

Commit

Permalink
Merge pull request #21629 from ziglang/elf-incr
Browse files Browse the repository at this point in the history
elf: more incremental progress
  • Loading branch information
andrewrk authored Oct 10, 2024
2 parents 5d7ed61 + 73c3b9b commit 2e29277
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 414 deletions.
35 changes: 16 additions & 19 deletions src/link/Dwarf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,10 @@ pub const Section = struct {
if (dwarf.bin_file.cast(.elf)) |elf_file| {
const zo = elf_file.zigObjectPtr().?;
const atom = zo.symbol(sec.index).atom(elf_file).?;
const shndx = atom.output_section_index;
if (sec == &dwarf.debug_frame.section)
try elf_file.growAllocSection(shndx, len, sec.alignment.toByteUnits().?)
else
try elf_file.growNonAllocSection(shndx, len, sec.alignment.toByteUnits().?, true);
const shdr = elf_file.sections.items(.shdr)[shndx];
atom.size = shdr.sh_size;
atom.alignment = InternPool.Alignment.fromNonzeroByteUnits(shdr.sh_addralign);
sec.len = shdr.sh_size;
atom.size = len;
atom.alignment = sec.alignment;
sec.len = len;
try zo.allocateAtom(atom, false, elf_file);
} else if (dwarf.bin_file.cast(.macho)) |macho_file| {
const header = if (macho_file.d_sym) |*d_sym| header: {
try d_sym.growSection(@intCast(sec.index), len, true, macho_file);
Expand All @@ -418,11 +413,15 @@ pub const Section = struct {
if (dwarf.bin_file.cast(.elf)) |elf_file| {
const zo = elf_file.zigObjectPtr().?;
const atom = zo.symbol(sec.index).atom(elf_file).?;
const shndx = atom.output_section_index;
const shdr = &elf_file.sections.items(.shdr)[shndx];
atom.size = sec.len;
shdr.sh_offset += len;
shdr.sh_size = sec.len;
if (atom.prevAtom(elf_file)) |_| {
// FIXME:JK trimming/shrinking has to be reworked on ZigObject/Elf level
atom.value += len;
} else {
const shdr = &elf_file.sections.items(.shdr)[atom.output_section_index];
shdr.sh_offset += len;
atom.value = 0;
}
atom.size -= len;
} else if (dwarf.bin_file.cast(.macho)) |macho_file| {
const header = if (macho_file.d_sym) |*d_sym|
&d_sym.sections.items[sec.index]
Expand Down Expand Up @@ -911,11 +910,9 @@ const Entry = struct {
if (std.debug.runtime_safety) {
log.err("missing {} from {s}", .{
@as(Entry.Index, @enumFromInt(entry - unit.entries.items.ptr)),
std.mem.sliceTo(if (dwarf.bin_file.cast(.elf)) |elf_file| sh_name: {
const zo = elf_file.zigObjectPtr().?;
const shndx = zo.symbol(sec.index).atom(elf_file).?.output_section_index;
break :sh_name elf_file.shstrtab.items[elf_file.sections.items(.shdr)[shndx].sh_name..];
} else if (dwarf.bin_file.cast(.macho)) |macho_file|
std.mem.sliceTo(if (dwarf.bin_file.cast(.elf)) |elf_file|
elf_file.zigObjectPtr().?.symbol(sec.index).name(elf_file)
else if (dwarf.bin_file.cast(.macho)) |macho_file|
if (macho_file.d_sym) |*d_sym|
&d_sym.sections.items[sec.index].segname
else
Expand Down
Loading

0 comments on commit 2e29277

Please sign in to comment.