| ... | @@ -43,6 +43,10 @@ phdr_load_ro_index: ?u16 = null, | ... | @@ -43,6 +43,10 @@ phdr_load_ro_index: ?u16 = null, |
| 43 | phdr_load_rw_index: ?u16 = null, | 43 | phdr_load_rw_index: ?u16 = null, |
| 44 | /// The index into the program headers of a PT_LOAD program header with zerofill data. | 44 | /// The index into the program headers of a PT_LOAD program header with zerofill data. |
| 45 | phdr_load_zerofill_index: ?u16 = null, | 45 | phdr_load_zerofill_index: ?u16 = null, |
| | 46 | /// The index into the program headers of the PT_TLS program header. |
| | 47 | phdr_tls_index: ?u16 = null, |
| | 48 | /// The index into the program headers of a PT_LOAD program header with TLS data. |
| | 49 | phdr_load_tls_index: ?u16 = null, |
| 46 | | 50 | |
| 47 | entry_addr: ?u64 = null, | 51 | entry_addr: ?u64 = null, |
| 48 | page_size: u32, | 52 | page_size: u32, |
| ... | @@ -56,10 +60,13 @@ strtab: StringTable(.strtab) = .{}, | ... | @@ -56,10 +60,13 @@ strtab: StringTable(.strtab) = .{}, |
| 56 | /// Representation of the GOT table as committed to the file. | 60 | /// Representation of the GOT table as committed to the file. |
| 57 | got: GotSection = .{}, | 61 | got: GotSection = .{}, |
| 58 | | 62 | |
| | 63 | /// Tracked section headers |
| 59 | text_section_index: ?u16 = null, | 64 | text_section_index: ?u16 = null, |
| 60 | rodata_section_index: ?u16 = null, | 65 | rodata_section_index: ?u16 = null, |
| 61 | data_section_index: ?u16 = null, | 66 | data_section_index: ?u16 = null, |
| 62 | bss_section_index: ?u16 = null, | 67 | bss_section_index: ?u16 = null, |
| | 68 | tdata_section_index: ?u16 = null, |
| | 69 | tbss_section_index: ?u16 = null, |
| 63 | eh_frame_section_index: ?u16 = null, | 70 | eh_frame_section_index: ?u16 = null, |
| 64 | eh_frame_hdr_section_index: ?u16 = null, | 71 | eh_frame_hdr_section_index: ?u16 = null, |
| 65 | dynamic_section_index: ?u16 = null, | 72 | dynamic_section_index: ?u16 = null, |
| ... | @@ -623,6 +630,32 @@ pub fn populateMissingMetadata(self: *Elf) !void { | ... | @@ -623,6 +630,32 @@ pub fn populateMissingMetadata(self: *Elf) !void { |
| 623 | phdr.p_memsz = 1024; | 630 | phdr.p_memsz = 1024; |
| 624 | } | 631 | } |
| 625 | | 632 | |
| | 633 | if (!self.base.options.single_threaded) { |
| | 634 | if (self.phdr_load_tls_index == null) { |
| | 635 | const alignment = if (is_linux) self.page_size else @as(u16, ptr_size); |
| | 636 | self.phdr_load_tls_index = try self.allocateSegment(.{ |
| | 637 | .size = 1024, |
| | 638 | .alignment = alignment, |
| | 639 | .flags = elf.PF_R | elf.PF_W, |
| | 640 | }); |
| | 641 | } |
| | 642 | |
| | 643 | if (self.phdr_tls_index == null) { |
| | 644 | const phdr = &self.phdrs.items[self.phdr_load_tls_index.?]; |
| | 645 | try self.phdrs.append(gpa, .{ |
| | 646 | .p_type = elf.PT_TLS, |
| | 647 | .p_offset = phdr.p_offset, |
| | 648 | .p_vaddr = phdr.p_vaddr, |
| | 649 | .p_paddr = phdr.p_paddr, |
| | 650 | .p_filesz = phdr.p_filesz, |
| | 651 | .p_memsz = phdr.p_memsz, |
| | 652 | .p_align = ptr_size, |
| | 653 | .p_flags = elf.PF_R, |
| | 654 | }); |
| | 655 | self.phdr_table_dirty = true; |
| | 656 | } |
| | 657 | } |
| | 658 | |
| 626 | if (self.shstrtab_section_index == null) { | 659 | if (self.shstrtab_section_index == null) { |
| 627 | assert(self.shstrtab.buffer.items.len == 0); | 660 | assert(self.shstrtab.buffer.items.len == 0); |
| 628 | try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0 | 661 | try self.shstrtab.buffer.append(gpa, 0); // need a 0 at position 0 |