From 19a0864e4f96d5c20026dae87c0f9a784ae54272 Mon Sep 17 00:00:00 2001 From: Patrick Wickenhaeuser <35903594+patrickwick@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:38:35 +0200 Subject: [PATCH] 19009: zig objcopy: allow --add-section, --set-section-alignment and --set-section-flags only if the target is an ELF file --- lib/compiler/objcopy.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index 8bd2729702..fe3d2fbc57 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -185,14 +185,17 @@ fn cmdObjCopy( fatal("zig objcopy: ELF to RAW or HEX copying does not support --strip", .{}); if (opt_extract != null) fatal("zig objcopy: ELF to RAW or HEX copying does not support --extract-to", .{}); + if (add_section != null) + fatal("zig objcopy: ELF to RAW or HEX copying does not support --add-section", .{}); + if (set_section_alignment != null) + fatal("zig objcopy: ELF to RAW or HEX copying does not support --set_section_alignment", .{}); + if (set_section_flags != null) + fatal("zig objcopy: ELF to RAW or HEX copying does not support --set_section_flags", .{}); try emitElf(arena, in_file, out_file, elf_hdr, .{ .ofmt = out_fmt, .only_section = only_section, .pad_to = pad_to, - .add_section = add_section, - .set_section_alignment = set_section_alignment, - .set_section_flags = set_section_flags, }); }, .elf => { @@ -279,9 +282,9 @@ pub const EmitRawElfOptions = struct { ofmt: std.Target.ObjectFormat, only_section: ?[]const u8 = null, pad_to: ?u64 = null, - add_section: ?AddSection, - set_section_alignment: ?SetSectionAlignment, - set_section_flags: ?SetSectionFlags, + add_section: ?AddSection = null, + set_section_alignment: ?SetSectionAlignment = null, + set_section_flags: ?SetSectionFlags = null, }; const AddSection = struct {