Commit 7b2cbcf0fe

Jakub Konka <kubkon@jakubkonka.com>
2023-10-15 15:38:16
codegen+elf: check if extern is a variable ref
1 parent 45197ea
Changed files (3)
src/link/Elf/Object.zig
@@ -214,8 +214,6 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMem
                 break :blk prefix;
             }
         }
-        if (std.mem.eql(u8, name, ".tcommon")) break :blk ".tbss";
-        if (std.mem.eql(u8, name, ".common")) break :blk ".bss";
         break :blk name;
     };
     const @"type" = switch (shdr.sh_type) {
src/link/Elf.zig
@@ -4597,7 +4597,6 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {
         for (slice, 0..) |*shdr, ii| {
             if (shdr.sh_type == elf.SHT_NOBITS) continue;
             off = alignment.@"align"(cover.start + ii, shdr.sh_addralign, off);
-            // off = mem.alignForward(u64, off, shdr.sh_addralign);
             shdr.sh_offset = off;
             off += shdr.sh_size;
             try self.phdr_to_shdr_table.putNoClobber(gpa, @intCast(ii + cover.start), phndx);
src/codegen.zig
@@ -892,9 +892,12 @@ fn genDeclRef(
 
     if (bin_file.cast(link.File.Elf)) |elf_file| {
         if (is_extern) {
-            const variable = decl.getOwnedVariable(mod).?;
             const name = mod.intern_pool.stringToSlice(decl.name);
-            const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);
+            // TODO audit this
+            const lib_name = if (decl.getOwnedVariable(mod)) |ov|
+                mod.intern_pool.stringToSliceUnwrap(ov.lib_name)
+            else
+                null;
             return GenResult.mcv(.{ .load_actual_got = try elf_file.getGlobalSymbol(name, lib_name) });
         }
         const sym_index = try elf_file.getOrCreateMetadataForDecl(decl_index);