authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-15 15:38:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:06+02:00
log7b2cbcf0fe6dcaea7ee108c13422f6d00ed4bc8e
tree1926dba17efdbd327ac737551b68f8e649c5f06d
parent45197ea7adfa34806b549263c06b988b5e35d48c

codegen+elf: check if extern is a variable ref


3 files changed, 5 insertions(+), 5 deletions(-)

src/codegen.zig+5-2
...@@ -892,9 +892,12 @@ fn genDeclRef(...@@ -892,9 +892,12 @@ fn genDeclRef(
892892
893 if (bin_file.cast(link.File.Elf)) |elf_file| {893 if (bin_file.cast(link.File.Elf)) |elf_file| {
894 if (is_extern) {894 if (is_extern) {
895 const variable = decl.getOwnedVariable(mod).?;
896 const name = mod.intern_pool.stringToSlice(decl.name);895 const name = mod.intern_pool.stringToSlice(decl.name);
897 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);896 // TODO audit this
897 const lib_name = if (decl.getOwnedVariable(mod)) |ov|
898 mod.intern_pool.stringToSliceUnwrap(ov.lib_name)
899 else
900 null;
898 return GenResult.mcv(.{ .load_actual_got = try elf_file.getGlobalSymbol(name, lib_name) });901 return GenResult.mcv(.{ .load_actual_got = try elf_file.getGlobalSymbol(name, lib_name) });
899 }902 }
900 const sym_index = try elf_file.getOrCreateMetadataForDecl(decl_index);903 const sym_index = try elf_file.getOrCreateMetadataForDecl(decl_index);
src/link/Elf.zig-1
...@@ -4597,7 +4597,6 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {...@@ -4597,7 +4597,6 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {
4597 for (slice, 0..) |*shdr, ii| {4597 for (slice, 0..) |*shdr, ii| {
4598 if (shdr.sh_type == elf.SHT_NOBITS) continue;4598 if (shdr.sh_type == elf.SHT_NOBITS) continue;
4599 off = alignment.@"align"(cover.start + ii, shdr.sh_addralign, off);4599 off = alignment.@"align"(cover.start + ii, shdr.sh_addralign, off);
4600 // off = mem.alignForward(u64, off, shdr.sh_addralign);
4601 shdr.sh_offset = off;4600 shdr.sh_offset = off;
4602 off += shdr.sh_size;4601 off += shdr.sh_size;
4603 try self.phdr_to_shdr_table.putNoClobber(gpa, @intCast(ii + cover.start), phndx);4602 try self.phdr_to_shdr_table.putNoClobber(gpa, @intCast(ii + cover.start), phndx);
src/link/Elf/Object.zig-2
...@@ -214,8 +214,6 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMem...@@ -214,8 +214,6 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMem
214 break :blk prefix;214 break :blk prefix;
215 }215 }
216 }216 }
217 if (std.mem.eql(u8, name, ".tcommon")) break :blk ".tbss";
218 if (std.mem.eql(u8, name, ".common")) break :blk ".bss";
219 break :blk name;217 break :blk name;
220 };218 };
221 const @"type" = switch (shdr.sh_type) {219 const @"type" = switch (shdr.sh_type) {