diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-28 12:06:21 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-28 12:06:21 +0200 |
| commit | 22127a879234459dad65c73ffae4d5ec9da548c1 (patch) | |
| tree | a746af3dbaecd03566dc642f808a641d64346df7 | |
| parent | 42011a82498655ab3471aa92642878de7c7f024a (diff) | |
| download | zig-22127a879234459dad65c73ffae4d5ec9da548c1.tar.gz zig-22127a879234459dad65c73ffae4d5ec9da548c1.zip | |
elf: pre-allocate TLS load segment and PT_TLS phdr
| -rw-r--r-- | src/link/Elf.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 9f045bec7a..30eb1deb46 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -43,6 +43,10 @@ phdr_load_ro_index: ?u16 = null, phdr_load_rw_index: ?u16 = null, /// The index into the program headers of a PT_LOAD program header with zerofill data. phdr_load_zerofill_index: ?u16 = null, +/// The index into the program headers of the PT_TLS program header. +phdr_tls_index: ?u16 = null, +/// The index into the program headers of a PT_LOAD program header with TLS data. +phdr_load_tls_index: ?u16 = null, entry_addr: ?u64 = null, page_size: u32, @@ -56,10 +60,13 @@ strtab: StringTable(.strtab) = .{}, /// Representation of the GOT table as committed to the file. got: GotSection = .{}, +/// Tracked section headers text_section_index: ?u16 = null, rodata_section_index: ?u16 = null, data_section_index: ?u16 = null, bss_section_index: ?u16 = null, +tdata_section_index: ?u16 = null, +tbss_section_index: ?u16 = null, eh_frame_section_index: ?u16 = null, eh_frame_hdr_section_index: ?u16 = null, dynamic_section_index: ?u16 = null, @@ -623,6 +630,32 @@ pub fn populateMissingMetadata(self: *Elf) !void { phdr.p_memsz = 1024; } + if (!self.base.options.single_threaded) { + if (self.phdr_load_tls_index == null) { + const alignment = if (is_linux) self.page_size else @as(u16, ptr_size); + self.phdr_load_tls_index = try self.allocateSegment(.{ + .size = 1024, + .alignment = alignment, + .flags = elf.PF_R | elf.PF_W, + }); + } + + if (self.phdr_tls_index == null) { + const phdr = &self.phdrs.items[self.phdr_load_tls_index.?]; + try self.phdrs.append(gpa, .{ + .p_type = elf.PT_TLS, + .p_offset = phdr.p_offset, + .p_vaddr = phdr.p_vaddr, + .p_paddr = phdr.p_paddr, + .p_filesz = phdr.p_filesz, + .p_memsz = phdr.p_memsz, + .p_align = ptr_size, + .p_flags = elf.PF_R, + }); + self.phdr_table_dirty = true; + } + } + if (self.shstrtab_section_index == null) { assert(self.shstrtab.buffer.items.len == 0); try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0 |
