aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/Object.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-11-07 13:12:26 +0100
committerJakub Konka <kubkon@jakubkonka.com>2023-11-07 13:31:31 +0100
commitc7ed7c4690dfa297c15b94fe7acba77c52d89e68 (patch)
treec2e8791aefee2e92333ccea7491033179f559c6c /src/link/Elf/Object.zig
parent3df53d1722da9e4fcc8606315c68ffb884a0dd5a (diff)
downloadzig-c7ed7c4690dfa297c15b94fe7acba77c52d89e68.tar.gz
zig-c7ed7c4690dfa297c15b94fe7acba77c52d89e68.zip
elf: generate section symbols when writing symtab
Diffstat (limited to 'src/link/Elf/Object.zig')
-rw-r--r--src/link/Elf/Object.zig15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig
index cb258a4c22..73bd3a7fb3 100644
--- a/src/link/Elf/Object.zig
+++ b/src/link/Elf/Object.zig
@@ -211,6 +211,7 @@ fn addAtom(self: *Object, shdr: ElfShdr, shndx: u16, elf_file: *Elf) error{OutOf
fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMemory}!u16 {
const name = blk: {
const name = self.getString(shdr.sh_name);
+ if (elf_file.isRelocatable()) break :blk name;
if (shdr.sh_flags & elf.SHF_MERGE != 0) break :blk name;
const sh_name_prefixes: []const [:0]const u8 = &.{
".text", ".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss",
@@ -237,7 +238,10 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMem
else => shdr.sh_type,
};
const flags = blk: {
- const flags = shdr.sh_flags & ~@as(u64, elf.SHF_COMPRESSED | elf.SHF_GROUP | elf.SHF_GNU_RETAIN);
+ var flags = shdr.sh_flags;
+ if (!elf_file.isRelocatable()) {
+ flags &= ~@as(u64, elf.SHF_COMPRESSED | elf.SHF_GROUP | elf.SHF_GNU_RETAIN);
+ }
break :blk switch (@"type") {
elf.SHT_INIT_ARRAY, elf.SHT_FINI_ARRAY => flags | elf.SHF_WRITE,
else => flags,
@@ -655,8 +659,13 @@ pub fn allocateAtoms(self: Object, elf_file: *Elf) void {
}
pub fn initRelaSections(self: Object, elf_file: *Elf) !void {
- _ = self;
- _ = elf_file;
+ for (self.atoms.items) |atom_index| {
+ const atom = elf_file.atom(atom_index) orelse continue;
+ if (!atom.flags.alive) continue;
+ const shndx = atom.relocsShndx() orelse continue;
+ const shdr = self.shdrs.items[shndx];
+ _ = try self.initOutputSection(elf_file, shdr);
+ }
}
pub fn updateRelaSectionsSizes(self: Object, elf_file: *Elf) void {