elf: fix setting st_value of _end synthetic symbol

This commit is contained in:
Jakub Konka 2023-09-29 22:18:38 +02:00
parent 8e90b41ae0
commit 5381bfd348
2 changed files with 9 additions and 3 deletions

View File

@ -3433,9 +3433,14 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void {
// _end
{
const end_symbol = self.symbol(self.end_index.?);
end_symbol.value = 0;
for (self.shdrs.items, 0..) |*shdr, shndx| {
if (shdr.sh_flags & elf.SHF_ALLOC != 0) {
end_symbol.value = shdr.sh_addr + shdr.sh_size;
if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue;
const phdr_index = self.phdr_to_shdr_table.get(@intCast(shndx)).?;
const phdr = self.phdrs.items[phdr_index];
const value = phdr.p_vaddr + phdr.p_memsz;
if (end_symbol.value < value) {
end_symbol.value = value;
end_symbol.output_section_index = @intCast(shndx);
}
}

View File

@ -198,7 +198,8 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
// }
if (st_shndx == elf.SHN_ABS) break :blk symbol.value;
const shdr = &elf_file.shdrs.items[st_shndx];
if (shdr.sh_flags & elf.SHF_TLS != 0) break :blk symbol.value - elf_file.tlsAddress();
if (shdr.sh_flags & elf.SHF_TLS != 0 and file_ptr != .linker_defined)
break :blk symbol.value - elf_file.tlsAddress();
break :blk symbol.value;
};
out.* = .{