authorgravatar for elliot.huang.signed@gmail.combinarycraft007 <elliot.huang.signed@gmail.com> 2024-03-01 09:18:33+08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-01 09:23:54-08:00
loga7a5f4cf4d1d975c95f8f1b71bf2d9bd4afa9204
tree98068895a93b5c2402e9d78f6a58f0f8235ce0fb
parent9e402704e2fc01369dfbf2c9a20ac1ee7d66ca7c

objcopy: support multiple only sections


2 files changed, 13 insertions(+), 6 deletions(-)

lib/std/Build/Cache.zig+5
...@@ -245,6 +245,11 @@ pub const HashHelper = struct {...@@ -245,6 +245,11 @@ pub const HashHelper = struct {
245 for (list_of_bytes) |bytes| hh.addBytes(bytes);245 for (list_of_bytes) |bytes| hh.addBytes(bytes);
246 }246 }
247247
248 pub fn addOptionalListOfBytes(hh: *HashHelper, optional_list_of_bytes: ?[]const []const u8) void {
249 hh.add(optional_list_of_bytes != null);
250 hh.addListOfBytes(optional_list_of_bytes orelse return);
251 }
252
248 /// Convert the input value into bytes and record it as a dependency of the process being cached.253 /// Convert the input value into bytes and record it as a dependency of the process being cached.
249 pub fn add(hh: *HashHelper, x: anytype) void {254 pub fn add(hh: *HashHelper, x: anytype) void {
250 switch (@TypeOf(x)) {255 switch (@TypeOf(x)) {
lib/std/Build/Step/ObjCopy.zig+8-6
...@@ -33,7 +33,7 @@ output_file: std.Build.GeneratedFile,...@@ -33,7 +33,7 @@ output_file: std.Build.GeneratedFile,
33output_file_debug: ?std.Build.GeneratedFile,33output_file_debug: ?std.Build.GeneratedFile,
3434
35format: ?RawFormat,35format: ?RawFormat,
36only_section: ?[]const u8,36only_sections: ?[]const []const u8,
37pad_to: ?u64,37pad_to: ?u64,
38strip: Strip,38strip: Strip,
39compress_debug: bool,39compress_debug: bool,
...@@ -41,7 +41,7 @@ compress_debug: bool,...@@ -41,7 +41,7 @@ compress_debug: bool,
41pub const Options = struct {41pub const Options = struct {
42 basename: ?[]const u8 = null,42 basename: ?[]const u8 = null,
43 format: ?RawFormat = null,43 format: ?RawFormat = null,
44 only_section: ?[]const u8 = null,44 only_sections: ?[]const []const u8 = null,
45 pad_to: ?u64 = null,45 pad_to: ?u64 = null,
4646
47 compress_debug: bool = false,47 compress_debug: bool = false,
...@@ -71,7 +71,7 @@ pub fn create(...@@ -71,7 +71,7 @@ pub fn create(
71 .output_file = std.Build.GeneratedFile{ .step = &self.step },71 .output_file = std.Build.GeneratedFile{ .step = &self.step },
72 .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &self.step } else null,72 .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &self.step } else null,
73 .format = options.format,73 .format = options.format,
74 .only_section = options.only_section,74 .only_sections = options.only_sections,
75 .pad_to = options.pad_to,75 .pad_to = options.pad_to,
76 .strip = options.strip,76 .strip = options.strip,
77 .compress_debug = options.compress_debug,77 .compress_debug = options.compress_debug,
...@@ -103,7 +103,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -103,7 +103,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
103103
104 const full_src_path = self.input_file.getPath(b);104 const full_src_path = self.input_file.getPath(b);
105 _ = try man.addFile(full_src_path, null);105 _ = try man.addFile(full_src_path, null);
106 man.hash.addOptionalBytes(self.only_section);106 man.hash.addOptionalListOfBytes(self.only_sections);
107 man.hash.addOptional(self.pad_to);107 man.hash.addOptional(self.pad_to);
108 man.hash.addOptional(self.format);108 man.hash.addOptional(self.format);
109 man.hash.add(self.compress_debug);109 man.hash.add(self.compress_debug);
...@@ -135,8 +135,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -135,8 +135,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
135 var argv = std.ArrayList([]const u8).init(b.allocator);135 var argv = std.ArrayList([]const u8).init(b.allocator);
136 try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" });136 try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" });
137137
138 if (self.only_section) |only_section| {138 if (self.only_sections) |only_sections| {
139 try argv.appendSlice(&.{ "-j", only_section });139 for (only_sections) |only_section| {
140 try argv.appendSlice(&.{ "-j", only_section });
141 }
140 }142 }
141 switch (self.strip) {143 switch (self.strip) {
142 .none => {},144 .none => {},