| ... | ... | @@ -269,6 +269,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 269 | 269 | // Append null byte to string tables |
| 270 | 270 | try self.shstrtab.buffer.append(allocator, 0); |
| 271 | 271 | try self.strtab.buffer.append(allocator, 0); |
| 272 | try self.dynstrtab.buffer.append(allocator, 0); |
| 272 | 273 | |
| 273 | 274 | if (options.module != null and !options.use_llvm) { |
| 274 | 275 | if (!options.strip) { |
| ... | ... | @@ -1384,6 +1385,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1384 | 1385 | try self.file(index).?.object.addAtomsToOutputSections(self); |
| 1385 | 1386 | } |
| 1386 | 1387 | try self.sortInitFini(); |
| 1388 | try self.setDynamicSection(); |
| 1389 | self.sortDynamicSymtab(); |
| 1390 | try self.setHashSections(); |
| 1391 | try self.setVersionSymtab(); |
| 1387 | 1392 | try self.updateSectionSizes(); |
| 1388 | 1393 | |
| 1389 | 1394 | try self.allocateSections(); |
| ... | ... | @@ -3748,6 +3753,7 @@ fn initSections(self: *Elf) !void { |
| 3748 | 3753 | .type = elf.SHT_DYNSYM, |
| 3749 | 3754 | .addralign = @alignOf(elf.Elf64_Sym), |
| 3750 | 3755 | .entsize = @sizeOf(elf.Elf64_Sym), |
| 3756 | .info = 1, |
| 3751 | 3757 | }); |
| 3752 | 3758 | self.hash_section_index = try self.addSection(.{ |
| 3753 | 3759 | .name = ".hash", |
| ... | ... | @@ -3873,6 +3879,52 @@ fn sortInitFini(self: *Elf) !void { |
| 3873 | 3879 | } |
| 3874 | 3880 | } |
| 3875 | 3881 | |
| 3882 | fn setDynamicSection(self: *Elf) !void { |
| 3883 | if (self.dynamic_section_index == null) return; |
| 3884 | |
| 3885 | for (self.shared_objects.items) |index| { |
| 3886 | const shared_object = self.file(index).?.shared_object; |
| 3887 | if (!shared_object.alive) continue; |
| 3888 | try self.dynamic.addNeeded(shared_object, self); |
| 3889 | } |
| 3890 | |
| 3891 | if (self.base.options.soname) |soname| { |
| 3892 | try self.dynamic.setSoname(soname, self); |
| 3893 | } |
| 3894 | |
| 3895 | try self.dynamic.setRpath(self.base.options.rpath_list, self); |
| 3896 | } |
| 3897 | |
| 3898 | fn sortDynamicSymtab(self: *Elf) void { |
| 3899 | if (self.gnu_hash_section_index == null) return; |
| 3900 | self.dynsym.sort(self); |
| 3901 | } |
| 3902 | |
| 3903 | fn setVersionSymtab(self: *Elf) !void { |
| 3904 | if (self.versym_section_index == null) return; |
| 3905 | try self.versym.resize(self.base.allocator, self.dynsym.count()); |
| 3906 | self.versym.items[0] = elf.VER_NDX_LOCAL; |
| 3907 | for (self.dynsym.entries.items, 1..) |entry, i| { |
| 3908 | const sym = self.symbol(entry.symbol_index); |
| 3909 | self.versym.items[i] = sym.version_index; |
| 3910 | } |
| 3911 | |
| 3912 | if (self.verneed_section_index) |shndx| { |
| 3913 | try self.verneed.generate(self); |
| 3914 | const shdr = &self.shdrs.items[shndx]; |
| 3915 | shdr.sh_info = @as(u32, @intCast(self.verneed.verneed.items.len)); |
| 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | fn setHashSections(self: *Elf) !void { |
| 3920 | if (self.hash_section_index != null) { |
| 3921 | try self.hash.generate(self); |
| 3922 | } |
| 3923 | if (self.gnu_hash_section_index != null) { |
| 3924 | try self.gnu_hash.calcSize(self); |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3876 | 3928 | fn sectionRank(self: *Elf, shdr: elf.Elf64_Shdr) u8 { |
| 3877 | 3929 | const name = self.shstrtab.getAssumeExists(shdr.sh_name); |
| 3878 | 3930 | const flags = shdr.sh_flags; |