feature. See also
. The project being documented here (as the example) is the Zig library itself.
objcopy.emitElf
fn emitElf(
arena: Allocator,
in: *File.Reader,
out: *File.Writer,
elf_hdr: elf.Header,
options: EmitRawElfOptions,
) !void
File
Code
fn emitElf(
arena: Allocator,
in: *File.Reader,
out: *File.Writer,
elf_hdr: elf.Header,
options: EmitRawElfOptions,
) !void {
var binary_elf_output = try BinaryElfOutput.parse(arena, in, elf_hdr);
defer binary_elf_output.deinit();
if (options.ofmt == .elf) {
fatal("zig objcopy: ELF to ELF copying is not implemented yet", .{});
}
if (options.only_section) |target_name| {
switch (options.ofmt) {
.hex => fatal("zig objcopy: hex format with sections is not implemented yet", .{}),
.raw => {
for (binary_elf_output.sections.items) |section| {
if (section.name) |curr_name| {
if (!std.mem.eql(u8, curr_name, target_name))
continue;
} else {
continue;
}
try writeBinaryElfSection(in, out, section);
try padFile(out, options.pad_to);
return;
}
},
else => unreachable,
}
return error.SectionNotFound;
}
switch (options.ofmt) {
.raw => {
for (binary_elf_output.sections.items) |section| {
try out.seekTo(section.binaryOffset);
try writeBinaryElfSection(in, out, section);
}
try padFile(out, options.pad_to);
},
.hex => {
if (binary_elf_output.segments.items.len == 0) return;
if (!containsValidAddressRange(binary_elf_output.segments.items)) {
return error.InvalidHexfileAddressRange;
}
var hex_writer = HexWriter{ .out = out };
for (binary_elf_output.segments.items) |segment| {
try hex_writer.writeSegment(segment, in);
}
if (options.pad_to) |_| {
return error.InvalidArgument;
}
try hex_writer.writeEof();
},
else => unreachable,
}
}