| ... | ... | @@ -543,7 +543,7 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) ?u64 { |
| 543 | 543 | const shdr_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Shdr) else @sizeOf(elf.Elf64_Shdr); |
| 544 | 544 | const tight_size = self.shdrs.items.len * shdr_size; |
| 545 | 545 | const increased_size = padToIdeal(tight_size); |
| 546 | | const test_end = off + increased_size; |
| 546 | const test_end = off +| increased_size; |
| 547 | 547 | if (end > off and start < test_end) { |
| 548 | 548 | return test_end; |
| 549 | 549 | } |
| ... | ... | @@ -552,7 +552,7 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) ?u64 { |
| 552 | 552 | for (self.shdrs.items) |shdr| { |
| 553 | 553 | if (shdr.sh_type == elf.SHT_NOBITS) continue; |
| 554 | 554 | const increased_size = padToIdeal(shdr.sh_size); |
| 555 | | const test_end = shdr.sh_offset + increased_size; |
| 555 | const test_end = shdr.sh_offset +| increased_size; |
| 556 | 556 | if (end > shdr.sh_offset and start < test_end) { |
| 557 | 557 | return test_end; |
| 558 | 558 | } |
| ... | ... | @@ -561,7 +561,7 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) ?u64 { |
| 561 | 561 | for (self.phdrs.items) |phdr| { |
| 562 | 562 | if (phdr.p_type != elf.PT_LOAD) continue; |
| 563 | 563 | const increased_size = padToIdeal(phdr.p_filesz); |
| 564 | | const test_end = phdr.p_offset + increased_size; |
| 564 | const test_end = phdr.p_offset +| increased_size; |
| 565 | 565 | if (end > phdr.p_offset and start < test_end) { |
| 566 | 566 | return test_end; |
| 567 | 567 | } |
| ... | ... | @@ -653,6 +653,7 @@ pub fn allocateAllocSection(self: *Elf, opts: AllocateAllocSectionOpts) error{Ou |
| 653 | 653 | .type = opts.type, |
| 654 | 654 | .flags = opts.flags, |
| 655 | 655 | .addralign = opts.alignment, |
| 656 | .offset = std.math.maxInt(u64), |
| 656 | 657 | }); |
| 657 | 658 | const shdr = &self.shdrs.items[index]; |
| 658 | 659 | try self.phdr_to_shdr_table.putNoClobber(gpa, index, opts.phdr_index); |
| ... | ... | @@ -690,6 +691,7 @@ fn allocateNonAllocSection(self: *Elf, opts: AllocateNonAllocSectionOpts) error{ |
| 690 | 691 | .info = opts.info, |
| 691 | 692 | .addralign = opts.alignment, |
| 692 | 693 | .entsize = opts.entsize, |
| 694 | .offset = std.math.maxInt(u64), |
| 693 | 695 | }); |
| 694 | 696 | const shdr = &self.shdrs.items[index]; |
| 695 | 697 | const off = self.findFreeSpace(opts.size, opts.alignment); |
| ... | ... | @@ -3841,6 +3843,7 @@ fn initSections(self: *Elf) !void { |
| 3841 | 3843 | .type = elf.SHT_PROGBITS, |
| 3842 | 3844 | .flags = elf.SHF_ALLOC, |
| 3843 | 3845 | .addralign = ptr_size, |
| 3846 | .offset = std.math.maxInt(u64), |
| 3844 | 3847 | }); |
| 3845 | 3848 | |
| 3846 | 3849 | if (self.base.options.eh_frame_hdr) { |
| ... | ... | @@ -3849,6 +3852,7 @@ fn initSections(self: *Elf) !void { |
| 3849 | 3852 | .type = elf.SHT_PROGBITS, |
| 3850 | 3853 | .flags = elf.SHF_ALLOC, |
| 3851 | 3854 | .addralign = 4, |
| 3855 | .offset = std.math.maxInt(u64), |
| 3852 | 3856 | }); |
| 3853 | 3857 | } |
| 3854 | 3858 | } |
| ... | ... | @@ -3859,6 +3863,7 @@ fn initSections(self: *Elf) !void { |
| 3859 | 3863 | .type = elf.SHT_PROGBITS, |
| 3860 | 3864 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3861 | 3865 | .addralign = ptr_size, |
| 3866 | .offset = std.math.maxInt(u64), |
| 3862 | 3867 | }); |
| 3863 | 3868 | } |
| 3864 | 3869 | |
| ... | ... | @@ -3880,6 +3885,7 @@ fn initSections(self: *Elf) !void { |
| 3880 | 3885 | .flags = elf.SHF_ALLOC, |
| 3881 | 3886 | .addralign = @alignOf(elf.Elf64_Rela), |
| 3882 | 3887 | .entsize = @sizeOf(elf.Elf64_Rela), |
| 3888 | .offset = std.math.maxInt(u64), |
| 3883 | 3889 | }); |
| 3884 | 3890 | } |
| 3885 | 3891 | |
| ... | ... | @@ -3889,12 +3895,14 @@ fn initSections(self: *Elf) !void { |
| 3889 | 3895 | .type = elf.SHT_PROGBITS, |
| 3890 | 3896 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 3891 | 3897 | .addralign = 16, |
| 3898 | .offset = std.math.maxInt(u64), |
| 3892 | 3899 | }); |
| 3893 | 3900 | self.got_plt_section_index = try self.addSection(.{ |
| 3894 | 3901 | .name = ".got.plt", |
| 3895 | 3902 | .type = elf.SHT_PROGBITS, |
| 3896 | 3903 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3897 | 3904 | .addralign = @alignOf(u64), |
| 3905 | .offset = std.math.maxInt(u64), |
| 3898 | 3906 | }); |
| 3899 | 3907 | self.rela_plt_section_index = try self.addSection(.{ |
| 3900 | 3908 | .name = ".rela.plt", |
| ... | ... | @@ -3902,6 +3910,7 @@ fn initSections(self: *Elf) !void { |
| 3902 | 3910 | .flags = elf.SHF_ALLOC, |
| 3903 | 3911 | .addralign = @alignOf(elf.Elf64_Rela), |
| 3904 | 3912 | .entsize = @sizeOf(elf.Elf64_Rela), |
| 3913 | .offset = std.math.maxInt(u64), |
| 3905 | 3914 | }); |
| 3906 | 3915 | } |
| 3907 | 3916 | |
| ... | ... | @@ -3911,6 +3920,7 @@ fn initSections(self: *Elf) !void { |
| 3911 | 3920 | .type = elf.SHT_PROGBITS, |
| 3912 | 3921 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 3913 | 3922 | .addralign = 16, |
| 3923 | .offset = std.math.maxInt(u64), |
| 3914 | 3924 | }); |
| 3915 | 3925 | } |
| 3916 | 3926 | |
| ... | ... | @@ -3919,6 +3929,7 @@ fn initSections(self: *Elf) !void { |
| 3919 | 3929 | .name = ".copyrel", |
| 3920 | 3930 | .type = elf.SHT_NOBITS, |
| 3921 | 3931 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3932 | .offset = std.math.maxInt(u64), |
| 3922 | 3933 | }); |
| 3923 | 3934 | } |
| 3924 | 3935 | |
| ... | ... | @@ -3937,6 +3948,7 @@ fn initSections(self: *Elf) !void { |
| 3937 | 3948 | .type = elf.SHT_PROGBITS, |
| 3938 | 3949 | .flags = elf.SHF_ALLOC, |
| 3939 | 3950 | .addralign = 1, |
| 3951 | .offset = std.math.maxInt(u64), |
| 3940 | 3952 | }); |
| 3941 | 3953 | } |
| 3942 | 3954 | |
| ... | ... | @@ -3947,6 +3959,7 @@ fn initSections(self: *Elf) !void { |
| 3947 | 3959 | .type = elf.SHT_STRTAB, |
| 3948 | 3960 | .entsize = 1, |
| 3949 | 3961 | .addralign = 1, |
| 3962 | .offset = std.math.maxInt(u64), |
| 3950 | 3963 | }); |
| 3951 | 3964 | self.dynamic_section_index = try self.addSection(.{ |
| 3952 | 3965 | .name = ".dynamic", |
| ... | ... | @@ -3954,6 +3967,7 @@ fn initSections(self: *Elf) !void { |
| 3954 | 3967 | .type = elf.SHT_DYNAMIC, |
| 3955 | 3968 | .entsize = @sizeOf(elf.Elf64_Dyn), |
| 3956 | 3969 | .addralign = @alignOf(elf.Elf64_Dyn), |
| 3970 | .offset = std.math.maxInt(u64), |
| 3957 | 3971 | }); |
| 3958 | 3972 | self.dynsymtab_section_index = try self.addSection(.{ |
| 3959 | 3973 | .name = ".dynsym", |
| ... | ... | @@ -3962,6 +3976,7 @@ fn initSections(self: *Elf) !void { |
| 3962 | 3976 | .addralign = @alignOf(elf.Elf64_Sym), |
| 3963 | 3977 | .entsize = @sizeOf(elf.Elf64_Sym), |
| 3964 | 3978 | .info = 1, |
| 3979 | .offset = std.math.maxInt(u64), |
| 3965 | 3980 | }); |
| 3966 | 3981 | self.hash_section_index = try self.addSection(.{ |
| 3967 | 3982 | .name = ".hash", |
| ... | ... | @@ -3969,12 +3984,14 @@ fn initSections(self: *Elf) !void { |
| 3969 | 3984 | .type = elf.SHT_HASH, |
| 3970 | 3985 | .addralign = 4, |
| 3971 | 3986 | .entsize = 4, |
| 3987 | .offset = std.math.maxInt(u64), |
| 3972 | 3988 | }); |
| 3973 | 3989 | self.gnu_hash_section_index = try self.addSection(.{ |
| 3974 | 3990 | .name = ".gnu.hash", |
| 3975 | 3991 | .flags = elf.SHF_ALLOC, |
| 3976 | 3992 | .type = elf.SHT_GNU_HASH, |
| 3977 | 3993 | .addralign = 8, |
| 3994 | .offset = std.math.maxInt(u64), |
| 3978 | 3995 | }); |
| 3979 | 3996 | |
| 3980 | 3997 | const needs_versions = for (self.dynsym.entries.items) |entry| { |
| ... | ... | @@ -3988,12 +4005,14 @@ fn initSections(self: *Elf) !void { |
| 3988 | 4005 | .type = elf.SHT_GNU_VERSYM, |
| 3989 | 4006 | .addralign = @alignOf(elf.Elf64_Versym), |
| 3990 | 4007 | .entsize = @sizeOf(elf.Elf64_Versym), |
| 4008 | .offset = std.math.maxInt(u64), |
| 3991 | 4009 | }); |
| 3992 | 4010 | self.verneed_section_index = try self.addSection(.{ |
| 3993 | 4011 | .name = ".gnu.version_r", |
| 3994 | 4012 | .flags = elf.SHF_ALLOC, |
| 3995 | 4013 | .type = elf.SHT_GNU_VERNEED, |
| 3996 | 4014 | .addralign = @alignOf(elf.Elf64_Verneed), |
| 4015 | .offset = std.math.maxInt(u64), |
| 3997 | 4016 | }); |
| 3998 | 4017 | } |
| 3999 | 4018 | } |
| ... | ... | @@ -4004,6 +4023,7 @@ fn initSections(self: *Elf) !void { |
| 4004 | 4023 | .type = elf.SHT_SYMTAB, |
| 4005 | 4024 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), |
| 4006 | 4025 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), |
| 4026 | .offset = std.math.maxInt(u64), |
| 4007 | 4027 | }); |
| 4008 | 4028 | } |
| 4009 | 4029 | if (self.strtab_section_index == null) { |
| ... | ... | @@ -4012,6 +4032,7 @@ fn initSections(self: *Elf) !void { |
| 4012 | 4032 | .type = elf.SHT_STRTAB, |
| 4013 | 4033 | .entsize = 1, |
| 4014 | 4034 | .addralign = 1, |
| 4035 | .offset = std.math.maxInt(u64), |
| 4015 | 4036 | }); |
| 4016 | 4037 | } |
| 4017 | 4038 | if (self.shstrtab_section_index == null) { |
| ... | ... | @@ -4020,6 +4041,7 @@ fn initSections(self: *Elf) !void { |
| 4020 | 4041 | .type = elf.SHT_STRTAB, |
| 4021 | 4042 | .entsize = 1, |
| 4022 | 4043 | .addralign = 1, |
| 4044 | .offset = std.math.maxInt(u64), |
| 4023 | 4045 | }); |
| 4024 | 4046 | } |
| 4025 | 4047 | } |
| ... | ... | @@ -5651,6 +5673,7 @@ pub const AddSectionOpts = struct { |
| 5651 | 5673 | info: u32 = 0, |
| 5652 | 5674 | addralign: u64 = 0, |
| 5653 | 5675 | entsize: u64 = 0, |
| 5676 | offset: u64 = 0, |
| 5654 | 5677 | }; |
| 5655 | 5678 | |
| 5656 | 5679 | pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 { |
| ... | ... | @@ -5662,7 +5685,7 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 { |
| 5662 | 5685 | .sh_type = opts.type, |
| 5663 | 5686 | .sh_flags = opts.flags, |
| 5664 | 5687 | .sh_addr = 0, |
| 5665 | | .sh_offset = 0, |
| 5688 | .sh_offset = opts.offset, |
| 5666 | 5689 | .sh_size = 0, |
| 5667 | 5690 | .sh_link = opts.link, |
| 5668 | 5691 | .sh_info = opts.info, |