authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-11 23:21:05+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-12 00:03:47+02:00
log6aa9c63f632a284069c88475cbde3cc6b114750b
treed7cbd990e26b9c21fea41960e6891c0551ac0d35
parentac587744e30817df86b9c759b307d41fe7951832

zld: throw an error if found unknown section in object

We will silently ignore expected section that are either won't take part in linking such as any `__DWARF` section, or are known but are not yet implemented such as `__TEXT,__eh_frame`. For any other we will throw an error and exit. Also, inform the caller that we currently are unable to handle frameworks.

2 files changed, 49 insertions(+), 1 deletions(-)

src/link/MachO.zig+5
...@@ -807,6 +807,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -807,6 +807,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
807 rpaths.appendAssumeCapacity(key.*);807 rpaths.appendAssumeCapacity(key.*);
808 }808 }
809809
810 // frameworks
811 for (self.base.options.frameworks) |framework| {
812 log.warn("frameworks not yet supported for '-framework {s}'", .{framework});
813 }
814
810 if (self.base.options.verbose_link) {815 if (self.base.options.verbose_link) {
811 var argv = std.ArrayList([]const u8).init(arena);816 var argv = std.ArrayList([]const u8).init(arena);
812817
src/link/MachO/Zld.zig+44-1
...@@ -442,6 +442,25 @@ fn updateMetadata(self: *Zld) !void {...@@ -442,6 +442,25 @@ fn updateMetadata(self: *Zld) !void {
442 const flags = source_sect.flags;442 const flags = source_sect.flags;
443443
444 switch (flags) {444 switch (flags) {
445 macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS => {
446 if (self.text_section_index != null) continue;
447
448 self.text_section_index = @intCast(u16, text_seg.sections.items.len);
449 try text_seg.addSection(self.allocator, .{
450 .sectname = makeStaticString("__text"),
451 .segname = makeStaticString("__TEXT"),
452 .addr = 0,
453 .size = 0,
454 .offset = 0,
455 .@"align" = 0,
456 .reloff = 0,
457 .nreloc = 0,
458 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
459 .reserved1 = 0,
460 .reserved2 = 0,
461 .reserved3 = 0,
462 });
463 },
445 macho.S_REGULAR, macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS => {464 macho.S_REGULAR, macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS => {
446 if (mem.eql(u8, segname, "__TEXT")) {465 if (mem.eql(u8, segname, "__TEXT")) {
447 if (mem.eql(u8, sectname, "__ustring")) {466 if (mem.eql(u8, sectname, "__ustring")) {
...@@ -654,8 +673,32 @@ fn updateMetadata(self: *Zld) !void {...@@ -654,8 +673,32 @@ fn updateMetadata(self: *Zld) !void {
654 .reserved3 = 0,673 .reserved3 = 0,
655 });674 });
656 },675 },
676 macho.S_COALESCED |
677 macho.S_ATTR_NO_TOC |
678 macho.S_ATTR_STRIP_STATIC_SYMS |
679 macho.S_ATTR_LIVE_SUPPORT => {
680 log.debug("TODO __eh_frame section: type 0x{x}, name '{s},{s}'", .{
681 flags, segname, sectname,
682 });
683 continue;
684 },
685 macho.S_REGULAR | macho.S_ATTR_DEBUG => {
686 if (mem.eql(u8, "__LD", segname) and mem.eql(u8, "__compact_unwind", sectname)) {
687 log.debug("TODO compact unwind section: type 0x{x}, name '{s},{s}'", .{
688 flags, segname, sectname,
689 });
690 }
691 continue;
692 },
657 else => {693 else => {
658 log.debug("unhandled section type 0x{x} for '{s}/{s}'", .{ flags, segname, sectname });694 if (mem.eql(u8, "__LLVM", segname) and mem.eql(u8, "__asm", sectname)) {
695 log.debug("TODO LLVM bitcode section: type 0x{x}, name '{s},{s}'", .{
696 flags, segname, sectname,
697 });
698 continue;
699 }
700 log.err("unhandled section type 0x{x} for '{s},{s}'", .{ flags, segname, sectname });
701 return error.UnhandledSection;
659 },702 },
660 }703 }
661 }704 }