authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2024-05-30 12:15:24+09:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-05 19:39:43-04:00
logaef66eebe3951c0e803c3535fb1a29768b8afdaf
treed4c0b0b3344574b1e89c0475344cb78200c0df52
parent87150468fc25f2ad70abcc1428112bfb8d31843a

objcopy build step: don't accept multiple sections

The actual `zig objcopy` does not accept keeping multiple sections. If you pass multiple `-j .section` arguments to `zig objcopy`, it will only respect the last one passed. Originally I changed `zig objcopy` to accept multiple sections and then concatenate them instead of returning after outputting the first section (see emitElf) but I realized concatenating probably doesn't make sense.

1 files changed, 6 insertions(+), 8 deletions(-)

lib/std/Build/Step/ObjCopy.zig+6-8
......@@ -33,7 +33,7 @@ output_file: std.Build.GeneratedFile,
3333output_file_debug: ?std.Build.GeneratedFile,
3434
3535format: ?RawFormat,
36only_sections: ?[]const []const u8,
36only_section: ?[]const u8,
3737pad_to: ?u64,
3838strip: Strip,
3939compress_debug: bool,
......@@ -41,7 +41,7 @@ compress_debug: bool,
4141pub const Options = struct {
4242 basename: ?[]const u8 = null,
4343 format: ?RawFormat = null,
44 only_sections: ?[]const []const u8 = null,
44 only_section: ?[]const u8 = null,
4545 pad_to: ?u64 = null,
4646
4747 compress_debug: bool = false,
......@@ -71,7 +71,7 @@ pub fn create(
7171 .output_file = std.Build.GeneratedFile{ .step = &objcopy.step },
7272 .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &objcopy.step } else null,
7373 .format = options.format,
74 .only_sections = options.only_sections,
74 .only_section = options.only_section,
7575 .pad_to = options.pad_to,
7676 .strip = options.strip,
7777 .compress_debug = options.compress_debug,
......@@ -103,7 +103,7 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
103103
104104 const full_src_path = objcopy.input_file.getPath2(b, step);
105105 _ = try man.addFile(full_src_path, null);
106 man.hash.addOptionalListOfBytes(objcopy.only_sections);
106 man.hash.addOptionalBytes(objcopy.only_section);
107107 man.hash.addOptional(objcopy.pad_to);
108108 man.hash.addOptional(objcopy.format);
109109 man.hash.add(objcopy.compress_debug);
......@@ -135,10 +135,8 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
135135 var argv = std.ArrayList([]const u8).init(b.allocator);
136136 try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" });
137137
138 if (objcopy.only_sections) |only_sections| {
139 for (only_sections) |only_section| {
140 try argv.appendSlice(&.{ "-j", only_section });
141 }
138 if (objcopy.only_section) |only_section| {
139 try argv.appendSlice(&.{ "-j", only_section });
142140 }
143141 switch (objcopy.strip) {
144142 .none => {},