| ... | @@ -425,6 +425,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) | ... | @@ -425,6 +425,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) |
| 425 | macho_file.getSection(match).sectName(), | 425 | macho_file.getSection(match).sectName(), |
| 426 | }); | 426 | }); |
| 427 | | 427 | |
| | 428 | const arch = macho_file.base.options.target.cpu.arch; |
| 428 | const is_zerofill = blk: { | 429 | const is_zerofill = blk: { |
| 429 | const section_type = sect.type_(); | 430 | const section_type = sect.type_(); |
| 430 | break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; | 431 | break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; |
| ... | @@ -538,6 +539,31 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) | ... | @@ -538,6 +539,31 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) |
| 538 | match, | 539 | match, |
| 539 | sect, | 540 | sect, |
| 540 | ); | 541 | ); |
| | 542 | |
| | 543 | if (arch == .x86_64 and addr == sect.addr) { |
| | 544 | // In x86_64 relocs, it can so happen that the compiler refers to the same |
| | 545 | // atom by both the actual assigned symbol and the start of the section. In this |
| | 546 | // case, we need to link the two together so add an alias. |
| | 547 | const alias = self.sections_as_symbols.get(sect_id) orelse blk: { |
| | 548 | const alias = @intCast(u32, self.symtab.items.len); |
| | 549 | try self.symtab.append(gpa, .{ |
| | 550 | .n_strx = 0, |
| | 551 | .n_type = macho.N_SECT, |
| | 552 | .n_sect = macho_file.getSectionOrdinal(match), |
| | 553 | .n_desc = 0, |
| | 554 | .n_value = addr, |
| | 555 | }); |
| | 556 | try self.sections_as_symbols.putNoClobber(gpa, sect_id, alias); |
| | 557 | break :blk alias; |
| | 558 | }; |
| | 559 | try atom.contained.append(gpa, .{ |
| | 560 | .sym_index = alias, |
| | 561 | .offset = 0, |
| | 562 | .stab = null, |
| | 563 | }); |
| | 564 | try self.atom_by_index_table.put(gpa, alias, atom); |
| | 565 | } |
| | 566 | |
| 541 | try macho_file.addAtomToSection(atom, match); | 567 | try macho_file.addAtomToSection(atom, match); |
| 542 | } | 568 | } |
| 543 | } else { | 569 | } else { |