Commit b48baeeebb

Jakub Konka <kubkon@jakubkonka.com>
2023-11-11 07:47:17
elf: fix typo in initial section offsets
1 parent aa0fbbc
Changed files (3)
src/link/Elf/Object.zig
@@ -251,7 +251,7 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: ElfShdr) error{OutOfMem
         .type = @"type",
         .flags = flags,
         .name = name,
-        .offset = std.math.maxInt(u32),
+        .offset = std.math.maxInt(u64),
     });
     return out_shndx;
 }
src/link/Elf/ZigObject.zig
@@ -749,14 +749,14 @@ fn getDeclShdrIndex(
                         .type = elf.SHT_NOBITS,
                         .flags = elf.SHF_ALLOC | elf.SHF_WRITE | elf.SHF_TLS,
                         .name = ".tbss",
-                        .offset = std.math.maxInt(u32),
+                        .offset = std.math.maxInt(u64),
                     });
 
                     break :blk elf_file.sectionByName(".tdata") orelse try elf_file.addSection(.{
                         .type = elf.SHT_PROGBITS,
                         .flags = elf.SHF_ALLOC | elf.SHF_WRITE | elf.SHF_TLS,
                         .name = ".tdata",
-                        .offset = std.math.maxInt(u32),
+                        .offset = std.math.maxInt(u64),
                     });
                 }
                 if (variable.is_const) break :blk elf_file.zig_data_rel_ro_section_index.?;
src/link/Elf.zig
@@ -4531,7 +4531,10 @@ fn allocateAllocSectionsObject(self: *Elf) !void {
     for (self.shdrs.items) |*shdr| {
         if (shdr.sh_type == elf.SHT_NULL) continue;
         if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue;
-        if (shdr.sh_type == elf.SHT_NOBITS) continue;
+        if (shdr.sh_type == elf.SHT_NOBITS) {
+            shdr.sh_offset = 0;
+            continue;
+        }
         const needed_size = shdr.sh_size;
         if (needed_size > self.allocatedSize(shdr.sh_offset)) {
             shdr.sh_size = 0;