Commit f3a503eca2

Jakub Konka <kubkon@jakubkonka.com>
2024-05-23 10:19:17
link/macho: ensure we set alignment of literals to max alignment
1 parent 71bbc5e
Changed files (2)
src/link/MachO/InternalObject.zig
@@ -165,6 +165,7 @@ pub fn dedupLiterals(self: InternalObject, lp: MachO.LiteralPool, macho_file: *M
                 if (target.getLiteralPoolIndex(macho_file)) |lp_index| {
                     const lp_atom = lp.getAtom(lp_index, macho_file);
                     if (target.atom_index != lp_atom.atom_index) {
+                        lp_atom.alignment = lp_atom.alignment.max(target.alignment);
                         target.flags.alive = false;
                         rel.target = lp_atom.atom_index;
                     }
@@ -176,6 +177,7 @@ pub fn dedupLiterals(self: InternalObject, lp: MachO.LiteralPool, macho_file: *M
                     if (target_atom.getLiteralPoolIndex(macho_file)) |lp_index| {
                         const lp_atom = lp.getAtom(lp_index, macho_file);
                         if (target_atom.atom_index != lp_atom.atom_index) {
+                            lp_atom.alignment = lp_atom.alignment.max(target_atom.alignment);
                             target_atom.flags.alive = false;
                             target_sym.atom = lp_atom.atom_index;
                         }
@@ -193,6 +195,7 @@ pub fn dedupLiterals(self: InternalObject, lp: MachO.LiteralPool, macho_file: *M
         if (atom.getLiteralPoolIndex(macho_file)) |lp_index| {
             const lp_atom = lp.getAtom(lp_index, macho_file);
             if (atom.atom_index != lp_atom.atom_index) {
+                lp_atom.alignment = lp_atom.alignment.max(atom.alignment);
                 atom.flags.alive = false;
                 extra.objc_selrefs = lp_atom.atom_index;
                 sym.setExtra(extra, macho_file);
src/link/MachO/Object.zig
@@ -593,6 +593,7 @@ pub fn dedupLiterals(self: Object, lp: MachO.LiteralPool, macho_file: *MachO) vo
                 if (target.getLiteralPoolIndex(macho_file)) |lp_index| {
                     const lp_atom = lp.getAtom(lp_index, macho_file);
                     if (target.atom_index != lp_atom.atom_index) {
+                        lp_atom.alignment = lp_atom.alignment.max(target.alignment);
                         target.flags.alive = false;
                         rel.target = lp_atom.atom_index;
                     }
@@ -604,6 +605,7 @@ pub fn dedupLiterals(self: Object, lp: MachO.LiteralPool, macho_file: *MachO) vo
                     if (target_atom.getLiteralPoolIndex(macho_file)) |lp_index| {
                         const lp_atom = lp.getAtom(lp_index, macho_file);
                         if (target_atom.atom_index != lp_atom.atom_index) {
+                            lp_atom.alignment = lp_atom.alignment.max(target_atom.alignment);
                             target_atom.flags.alive = false;
                             target_sym.atom = lp_atom.atom_index;
                         }