Commit 6e797d8648

Jakub Konka <kubkon@jakubkonka.com>
2023-11-09 19:41:50
elf: add SHF_INFO_LINK flag to any emitted SHT_RELA section
1 parent 27970ba
Changed files (2)
src
src/link/Elf/Object.zig
@@ -687,6 +687,7 @@ pub fn initRelaSections(self: Object, elf_file: *Elf) !void {
         const out_shdr = &elf_file.shdrs.items[out_shndx];
         out_shdr.sh_addralign = @alignOf(elf.Elf64_Rela);
         out_shdr.sh_entsize = @sizeOf(elf.Elf64_Rela);
+        out_shdr.sh_flags |= elf.SHF_INFO_LINK;
     }
 }
 
src/link/Elf.zig
@@ -4307,7 +4307,6 @@ fn updateComdatGroupsSizes(self: *Elf) void {
         shdr.sh_link = self.symtab_section_index.?;
 
         const sym = self.symbol(cg.symbol(self));
-        std.debug.print("{s}\n", .{sym.name(self)});
         shdr.sh_info = sym.outputSymtabIndex(self) orelse
             self.sectionSymbolOutputSymtabIndex(sym.outputShndx().?);
     }
@@ -6131,7 +6130,7 @@ fn formatShdr(
     });
 }
 
-fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(formatShdrFlags) {
+pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(formatShdrFlags) {
     return .{ .data = sh_flags };
 }
 
@@ -6288,12 +6287,12 @@ fn fmtDumpState(
 
     try writer.writeAll("Output COMDAT groups\n");
     for (self.comdat_group_sections.items) |cg| {
-        try writer.print("shdr({d}) : COMDAT({d})\n", .{ cg.shndx, cg.cg_index });
+        try writer.print("  shdr({d}) : COMDAT({d})\n", .{ cg.shndx, cg.cg_index });
     }
 
     try writer.writeAll("\nOutput shdrs\n");
     for (self.shdrs.items, 0..) |shdr, shndx| {
-        try writer.print("shdr({d}) : phdr({?d}) : {}\n", .{
+        try writer.print("  shdr({d}) : phdr({?d}) : {}\n", .{
             shndx,
             self.phdr_to_shdr_table.get(@intCast(shndx)),
             self.fmtShdr(shdr),
@@ -6301,7 +6300,7 @@ fn fmtDumpState(
     }
     try writer.writeAll("\nOutput phdrs\n");
     for (self.phdrs.items, 0..) |phdr, phndx| {
-        try writer.print("phdr{d} : {}\n", .{ phndx, self.fmtPhdr(phdr) });
+        try writer.print("  phdr{d} : {}\n", .{ phndx, self.fmtPhdr(phdr) });
     }
 }