Skip to content

Commit 6eabdc8

Browse files
committed
link: Improve handling of --build-id when using LLD.
1 parent d5ac3be commit 6eabdc8

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/link/Coff.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,7 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
17631763
man.hash.addOptionalBytes(entry_name);
17641764
man.hash.add(coff.base.stack_size);
17651765
man.hash.add(coff.image_base);
1766+
man.hash.add(coff.base.build_id);
17661767
{
17671768
// TODO remove this, libraries must instead be resolved by the frontend.
17681769
for (coff.lib_directories) |lib_directory| man.hash.addOptionalBytes(lib_directory.path);
@@ -1895,6 +1896,12 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
18951896
}
18961897
try argv.append(try allocPrint(arena, "-BASE:{d}", .{coff.image_base}));
18971898

1899+
switch (coff.base.build_id) {
1900+
.none => try argv.append("-BUILD-ID:NO"),
1901+
.fast => try argv.append("-BUILD-ID"),
1902+
.uuid, .sha1, .md5, .hexstring => {},
1903+
}
1904+
18981905
if (target.cpu.arch == .x86) {
18991906
try argv.append("-MACHINE:X86");
19001907
} else if (target.cpu.arch == .x86_64) {

src/link/Elf.zig

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,8 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
15961596
man.hash.addListOfBytes(self.rpath_table.keys());
15971597
if (output_mode == .Exe) {
15981598
man.hash.add(self.base.stack_size);
1599-
man.hash.add(self.base.build_id);
16001599
}
1600+
man.hash.add(self.base.build_id);
16011601
man.hash.addListOfBytes(self.symbol_wrap_set.keys());
16021602
man.hash.add(comp.skip_linker_dependencies);
16031603
man.hash.add(self.z_nodelete);
@@ -1753,20 +1753,14 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
17531753
});
17541754
}
17551755

1756-
if (is_exe_or_dyn_lib) {
1757-
switch (self.base.build_id) {
1758-
.none => {},
1759-
.fast, .uuid, .sha1, .md5 => {
1760-
try argv.append(try std.fmt.allocPrint(arena, "--build-id={s}", .{
1761-
@tagName(self.base.build_id),
1762-
}));
1763-
},
1764-
.hexstring => |hs| {
1765-
try argv.append(try std.fmt.allocPrint(arena, "--build-id=0x{s}", .{
1766-
std.fmt.fmtSliceHexLower(hs.toSlice()),
1767-
}));
1768-
},
1769-
}
1756+
switch (self.base.build_id) {
1757+
.none => try argv.append("--build-id=none"),
1758+
.fast, .uuid, .sha1, .md5 => try argv.append(try std.fmt.allocPrint(arena, "--build-id={s}", .{
1759+
@tagName(self.base.build_id),
1760+
})),
1761+
.hexstring => |hs| try argv.append(try std.fmt.allocPrint(arena, "--build-id=0x{s}", .{
1762+
std.fmt.fmtSliceHexLower(hs.toSlice()),
1763+
})),
17701764
}
17711765

17721766
try argv.append(try std.fmt.allocPrint(arena, "--image-base={d}", .{self.image_base}));

src/link/Wasm.zig

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,6 +4078,17 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
40784078
try std.fmt.allocPrint(arena, "stack-size={d}", .{wasm.base.stack_size}),
40794079
});
40804080

4081+
switch (wasm.base.build_id) {
4082+
.none => try argv.append("--build-id=none"),
4083+
.fast, .uuid, .sha1 => try argv.append(try std.fmt.allocPrint(arena, "--build-id={s}", .{
4084+
@tagName(wasm.base.build_id),
4085+
})),
4086+
.hexstring => |hs| try argv.append(try std.fmt.allocPrint(arena, "--build-id=0x{s}", .{
4087+
std.fmt.fmtSliceHexLower(hs.toSlice()),
4088+
})),
4089+
.md5 => {},
4090+
}
4091+
40814092
if (wasm.import_symbols) {
40824093
try argv.append("--allow-undefined");
40834094
}
@@ -4089,11 +4100,6 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
40894100
try argv.append("--pie");
40904101
}
40914102

4092-
// XXX - TODO: add when wasm-ld supports --build-id.
4093-
// if (wasm.base.build_id) {
4094-
// try argv.append("--build-id=tree");
4095-
// }
4096-
40974103
try argv.appendSlice(&.{ "-o", full_out_path });
40984104

40994105
if (target.cpu.arch == .wasm64) {

0 commit comments

Comments
 (0)