| ... | @@ -238,7 +238,6 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L | ... | @@ -238,7 +238,6 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L |
| 238 | }); | 238 | }); |
| 239 | | 239 | |
| 240 | try self.populateMetadata(); | 240 | try self.populateMetadata(); |
| 241 | try self.addRpaths(args.rpaths); | | |
| 242 | try self.parseInputFiles(files); | 241 | try self.parseInputFiles(files); |
| 243 | try self.parseLibs(args.libs); | 242 | try self.parseLibs(args.libs); |
| 244 | try self.parseLibSystem(args.libc_stub_path); | 243 | try self.parseLibSystem(args.libc_stub_path); |
| ... | @@ -246,6 +245,9 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L | ... | @@ -246,6 +245,9 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L |
| 246 | try self.resolveStubsAndGotEntries(); | 245 | try self.resolveStubsAndGotEntries(); |
| 247 | try self.updateMetadata(); | 246 | try self.updateMetadata(); |
| 248 | try self.sortSections(); | 247 | try self.sortSections(); |
| | 248 | try self.addRpaths(args.rpaths); |
| | 249 | try self.addDataInCodeLC(); |
| | 250 | try self.addCodeSignatureLC(); |
| 249 | try self.allocateTextSegment(); | 251 | try self.allocateTextSegment(); |
| 250 | try self.allocateDataConstSegment(); | 252 | try self.allocateDataConstSegment(); |
| 251 | try self.allocateDataSegment(); | 253 | try self.allocateDataSegment(); |
| ... | @@ -2231,24 +2233,28 @@ fn populateMetadata(self: *Zld) !void { | ... | @@ -2231,24 +2233,28 @@ fn populateMetadata(self: *Zld) !void { |
| 2231 | std.crypto.random.bytes(&uuid_cmd.uuid); | 2233 | std.crypto.random.bytes(&uuid_cmd.uuid); |
| 2232 | try self.load_commands.append(self.allocator, .{ .Uuid = uuid_cmd }); | 2234 | try self.load_commands.append(self.allocator, .{ .Uuid = uuid_cmd }); |
| 2233 | } | 2235 | } |
| | 2236 | } |
| 2234 | | 2237 | |
| 2235 | if (self.code_signature_cmd_index == null and self.arch.? == .aarch64) { | 2238 | fn addDataInCodeLC(self: *Zld) !void { |
| 2236 | self.code_signature_cmd_index = @intCast(u16, self.load_commands.items.len); | 2239 | if (self.data_in_code_cmd_index == null) { |
| | 2240 | self.data_in_code_cmd_index = @intCast(u16, self.load_commands.items.len); |
| 2237 | try self.load_commands.append(self.allocator, .{ | 2241 | try self.load_commands.append(self.allocator, .{ |
| 2238 | .LinkeditData = .{ | 2242 | .LinkeditData = .{ |
| 2239 | .cmd = macho.LC_CODE_SIGNATURE, | 2243 | .cmd = macho.LC_DATA_IN_CODE, |
| 2240 | .cmdsize = @sizeOf(macho.linkedit_data_command), | 2244 | .cmdsize = @sizeOf(macho.linkedit_data_command), |
| 2241 | .dataoff = 0, | 2245 | .dataoff = 0, |
| 2242 | .datasize = 0, | 2246 | .datasize = 0, |
| 2243 | }, | 2247 | }, |
| 2244 | }); | 2248 | }); |
| 2245 | } | 2249 | } |
| | 2250 | } |
| 2246 | | 2251 | |
| 2247 | if (self.data_in_code_cmd_index == null and self.arch.? == .x86_64) { | 2252 | fn addCodeSignatureLC(self: *Zld) !void { |
| 2248 | self.data_in_code_cmd_index = @intCast(u16, self.load_commands.items.len); | 2253 | if (self.code_signature_cmd_index == null and self.arch.? == .aarch64) { |
| | 2254 | self.code_signature_cmd_index = @intCast(u16, self.load_commands.items.len); |
| 2249 | try self.load_commands.append(self.allocator, .{ | 2255 | try self.load_commands.append(self.allocator, .{ |
| 2250 | .LinkeditData = .{ | 2256 | .LinkeditData = .{ |
| 2251 | .cmd = macho.LC_DATA_IN_CODE, | 2257 | .cmd = macho.LC_CODE_SIGNATURE, |
| 2252 | .cmdsize = @sizeOf(macho.linkedit_data_command), | 2258 | .cmdsize = @sizeOf(macho.linkedit_data_command), |
| 2253 | .dataoff = 0, | 2259 | .dataoff = 0, |
| 2254 | .datasize = 0, | 2260 | .datasize = 0, |
| ... | @@ -2344,9 +2350,7 @@ fn flush(self: *Zld) !void { | ... | @@ -2344,9 +2350,7 @@ fn flush(self: *Zld) !void { |
| 2344 | try self.writeBindInfoTable(); | 2350 | try self.writeBindInfoTable(); |
| 2345 | try self.writeLazyBindInfoTable(); | 2351 | try self.writeLazyBindInfoTable(); |
| 2346 | try self.writeExportInfo(); | 2352 | try self.writeExportInfo(); |
| 2347 | if (self.arch.? == .x86_64) { | 2353 | try self.writeDataInCode(); |
| 2348 | try self.writeDataInCode(); | | |
| 2349 | } | | |
| 2350 | | 2354 | |
| 2351 | { | 2355 | { |
| 2352 | const seg = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment; | 2356 | const seg = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment; |