authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-01 23:08:50+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-04 09:09:57+01:00
log3606b5df3f185edd69af823d3cae213e4b93ff39
tree393bfeef944ad3b311580427e00adeb751046327
parentec2671d16b9363ad7f39312552456cf5e449e930

elf: improve Symbol to handle emitting relocatable object files


4 files changed, 7 insertions(+), 5 deletions(-)

src/link/Elf.zig+1-1
......@@ -1943,7 +1943,7 @@ fn scanRelocs(self: *Elf) !void {
19431943
19441944 for (self.symbols.items, 0..) |*sym, i| {
19451945 const index = @as(u32, @intCast(i));
1946 if (!sym.isLocal() and !sym.flags.has_dynamic) {
1946 if (!sym.isLocal(self) and !sym.flags.has_dynamic) {
19471947 log.debug("'{s}' is non-local", .{sym.name(self)});
19481948 try self.dynsym.addSymbol(index, self);
19491949 }
src/link/Elf/Symbol.zig+3-2
......@@ -42,7 +42,8 @@ pub fn outputShndx(symbol: Symbol) ?u16 {
4242 return symbol.output_section_index;
4343}
4444
45pub fn isLocal(symbol: Symbol) bool {
45pub fn isLocal(symbol: Symbol, elf_file: *Elf) bool {
46 if (elf_file.isObject()) return symbol.elfSym(elf_file).st_bind() == elf.STB_LOCAL;
4647 return !(symbol.flags.import or symbol.flags.@"export");
4748}
4849
......@@ -208,7 +209,7 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
208209 const esym = symbol.elfSym(elf_file);
209210 const st_type = symbol.type(elf_file);
210211 const st_bind: u8 = blk: {
211 if (symbol.isLocal()) break :blk 0;
212 if (symbol.isLocal(elf_file)) break :blk 0;
212213 if (symbol.flags.weak) break :blk elf.STB_WEAK;
213214 if (file_ptr == .shared_object) break :blk elf.STB_GLOBAL;
214215 break :blk esym.st_bind();
src/link/Elf/ZigObject.zig+1
......@@ -1192,6 +1192,7 @@ pub fn updateExports(
11921192 global_esym.st_shndx = esym.st_shndx;
11931193 global_esym.st_info = (stb_bits << 4) | stt_bits;
11941194 global_esym.st_name = name_off;
1195 global_esym.st_size = esym.st_size;
11951196 self.global_esyms.items(.shndx)[actual_esym_index] = esym_shndx;
11961197 }
11971198}
src/link/Elf/file.zig+2-2
......@@ -150,7 +150,7 @@ pub const File = union(enum) {
150150 if (file_ptr.index() != file.index()) continue;
151151 if (global.atom(elf_file)) |atom| if (!atom.flags.alive) continue;
152152 global.flags.output_symtab = true;
153 if (global.isLocal()) {
153 if (global.isLocal(elf_file)) {
154154 output_symtab_size.nlocals += 1;
155155 } else {
156156 output_symtab_size.nglobals += 1;
......@@ -181,7 +181,7 @@ pub const File = union(enum) {
181181 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));
182182 elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file));
183183 elf_file.strtab.appendAssumeCapacity(0);
184 if (global.isLocal()) {
184 if (global.isLocal(elf_file)) {
185185 const out_sym = &elf_file.symtab.items[ilocal];
186186 out_sym.st_name = st_name;
187187 global.setOutputSym(elf_file, out_sym);