| ... | @@ -1208,14 +1208,15 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1208,14 +1208,15 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1208 | } | 1208 | } |
| 1209 | } | 1209 | } |
| 1210 | | 1210 | |
| | 1211 | try self.initOutputSections(); |
| 1211 | try self.addLinkerDefinedSymbols(); | 1212 | try self.addLinkerDefinedSymbols(); |
| 1212 | self.claimUnresolved(); | 1213 | self.claimUnresolved(); |
| 1213 | | 1214 | |
| 1214 | // Scan and create missing synthetic entries such as GOT indirection. | 1215 | // Scan and create missing synthetic entries such as GOT indirection. |
| 1215 | try self.scanRelocs(); | 1216 | try self.scanRelocs(); |
| 1216 | | 1217 | |
| 1217 | // Generate and emit non-incremental sections. | 1218 | // Generate and emit synthetic sections. |
| 1218 | try self.initSections(); | 1219 | try self.initSyntheticSections(); |
| 1219 | try self.initSpecialPhdrs(); | 1220 | try self.initSpecialPhdrs(); |
| 1220 | try self.sortShdrs(); | 1221 | try self.sortShdrs(); |
| 1221 | for (self.objects.items) |index| { | 1222 | for (self.objects.items) |index| { |
| ... | @@ -3210,21 +3211,18 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { | ... | @@ -3210,21 +3211,18 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { |
| 3210 | self.rela_iplt_start_index = try linker_defined.addGlobal("__rela_iplt_start", self); | 3211 | self.rela_iplt_start_index = try linker_defined.addGlobal("__rela_iplt_start", self); |
| 3211 | self.rela_iplt_end_index = try linker_defined.addGlobal("__rela_iplt_end", self); | 3212 | self.rela_iplt_end_index = try linker_defined.addGlobal("__rela_iplt_end", self); |
| 3212 | | 3213 | |
| 3213 | for (self.objects.items) |index| { | 3214 | for (self.shdrs.items) |shdr| { |
| 3214 | const object = self.file(index).?.object; | 3215 | if (self.getStartStopBasename(shdr)) |name| { |
| 3215 | for (object.atoms.items) |atom_index| { | 3216 | const gpa = self.base.allocator; |
| 3216 | if (self.getStartStopBasename(atom_index)) |name| { | 3217 | try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2); |
| 3217 | const gpa = self.base.allocator; | 3218 | |
| 3218 | try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2); | 3219 | const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name}); |
| 3219 | | 3220 | defer gpa.free(start); |
| 3220 | const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name}); | 3221 | const stop = try std.fmt.allocPrintZ(gpa, "__stop_{s}", .{name}); |
| 3221 | defer gpa.free(start); | 3222 | defer gpa.free(stop); |
| 3222 | const stop = try std.fmt.allocPrintZ(gpa, "__stop_{s}", .{name}); | 3223 | |
| 3223 | defer gpa.free(stop); | 3224 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(start, self)); |
| 3224 | | 3225 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(stop, self)); |
| 3225 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(start, self)); | | |
| 3226 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(stop, self)); | | |
| 3227 | } | | |
| 3228 | } | 3226 | } |
| 3229 | } | 3227 | } |
| 3230 | | 3228 | |
| ... | @@ -3354,12 +3352,14 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void { | ... | @@ -3354,12 +3352,14 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void { |
| 3354 | } | 3352 | } |
| 3355 | } | 3353 | } |
| 3356 | | 3354 | |
| 3357 | fn initSections(self: *Elf) !void { | 3355 | fn initOutputSections(self: *Elf) !void { |
| 3358 | const ptr_size = self.ptrWidthBytes(); | | |
| 3359 | | | |
| 3360 | for (self.objects.items) |index| { | 3356 | for (self.objects.items) |index| { |
| 3361 | try self.file(index).?.object.initOutputSections(self); | 3357 | try self.file(index).?.object.initOutputSections(self); |
| 3362 | } | 3358 | } |
| | 3359 | } |
| | 3360 | |
| | 3361 | fn initSyntheticSections(self: *Elf) !void { |
| | 3362 | const ptr_size = self.ptrWidthBytes(); |
| 3363 | | 3363 | |
| 3364 | const needs_eh_frame = for (self.objects.items) |index| { | 3364 | const needs_eh_frame = for (self.objects.items) |index| { |
| 3365 | if (self.file(index).?.object.cies.items.len > 0) break true; | 3365 | if (self.file(index).?.object.cies.items.len > 0) break true; |
| ... | @@ -5748,10 +5748,9 @@ pub fn isCIdentifier(name: []const u8) bool { | ... | @@ -5748,10 +5748,9 @@ pub fn isCIdentifier(name: []const u8) bool { |
| 5748 | return true; | 5748 | return true; |
| 5749 | } | 5749 | } |
| 5750 | | 5750 | |
| 5751 | fn getStartStopBasename(self: *Elf, atom_index: Atom.Index) ?[]const u8 { | 5751 | fn getStartStopBasename(self: *Elf, shdr: elf.Elf64_Shdr) ?[]const u8 { |
| 5752 | const atom_ptr = self.atom(atom_index) orelse return null; | 5752 | const name = self.getShString(shdr.sh_name); |
| 5753 | const name = atom_ptr.name(self); | 5753 | if (shdr.sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) { |
| 5754 | if (atom_ptr.inputShdr(self).sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) { | | |
| 5755 | if (isCIdentifier(name)) return name; | 5754 | if (isCIdentifier(name)) return name; |
| 5756 | } | 5755 | } |
| 5757 | return null; | 5756 | return null; |