authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-01 17:06:50+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-04 09:09:14+01:00
log74f12d0691292e9730327971bbf6c27a78095ae8
tree88fa06aaa82f9d1593cc8b206956a012b12435cc
parentabf6c20cb93f9b9b9b3ef0d935bd1e12063f4c36

elf: remove now obsolete allocateNonAllocSection helper


1 files changed, 45 insertions(+), 44 deletions(-)

src/link/Elf.zig+45-44
......@@ -484,36 +484,6 @@ fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u64) u64 {
484484 return start;
485485}
486486
487const AllocateNonAllocSectionOpts = struct {
488 name: [:0]const u8,
489 size: u64,
490 alignment: u16 = 1,
491 flags: u32 = 0,
492 type: u32 = elf.SHT_PROGBITS,
493 link: u32 = 0,
494 info: u32 = 0,
495 entsize: u64 = 0,
496};
497
498fn allocateNonAllocSection(self: *Elf, opts: AllocateNonAllocSectionOpts) error{OutOfMemory}!u16 {
499 const index = try self.addSection(.{
500 .name = opts.name,
501 .type = opts.type,
502 .flags = opts.flags,
503 .link = opts.link,
504 .info = opts.info,
505 .addralign = opts.alignment,
506 .entsize = opts.entsize,
507 .offset = std.math.maxInt(u64),
508 });
509 const shdr = &self.shdrs.items[index];
510 const off = self.findFreeSpace(opts.size, opts.alignment);
511 log.debug("allocating '{s}' from 0x{x} to 0x{x} ", .{ opts.name, off, off + opts.size });
512 shdr.sh_offset = off;
513 shdr.sh_size = opts.size;
514 return index;
515}
516
517487/// TODO move to ZigObject
518488pub fn initMetadata(self: *Elf) !void {
519489 const gpa = self.base.allocator;
......@@ -718,48 +688,79 @@ pub fn initMetadata(self: *Elf) !void {
718688 if (self.debug_str_section_index == null) {
719689 assert(dw.strtab.buffer.items.len == 0);
720690 try dw.strtab.buffer.append(gpa, 0);
721 self.debug_str_section_index = try self.allocateNonAllocSection(.{
691 self.debug_str_section_index = try self.addSection(.{
722692 .name = ".debug_str",
723 .size = @intCast(dw.strtab.buffer.items.len),
724693 .flags = elf.SHF_MERGE | elf.SHF_STRINGS,
725694 .entsize = 1,
695 .type = elf.SHT_PROGBITS,
696 .addralign = 1,
697 .offset = std.math.maxInt(u64),
726698 });
699 const shdr = &self.shdrs.items[self.debug_str_section_index.?];
700 const size = @as(u64, @intCast(dw.strtab.buffer.items.len));
701 const off = self.findFreeSpace(size, 1);
702 shdr.sh_offset = off;
703 shdr.sh_size = size;
727704 zig_object.debug_strtab_dirty = true;
728705 }
729706
730707 if (self.debug_info_section_index == null) {
731 self.debug_info_section_index = try self.allocateNonAllocSection(.{
708 self.debug_info_section_index = try self.addSection(.{
732709 .name = ".debug_info",
733 .size = 200,
734 .alignment = 1,
710 .type = elf.SHT_PROGBITS,
711 .addralign = 1,
712 .offset = std.math.maxInt(u64),
735713 });
714 const shdr = &self.shdrs.items[self.debug_info_section_index.?];
715 const size: u64 = 200;
716 const off = self.findFreeSpace(size, 1);
717 shdr.sh_offset = off;
718 shdr.sh_size = size;
736719 zig_object.debug_info_header_dirty = true;
737720 }
738721
739722 if (self.debug_abbrev_section_index == null) {
740 self.debug_abbrev_section_index = try self.allocateNonAllocSection(.{
723 self.debug_abbrev_section_index = try self.addSection(.{
741724 .name = ".debug_abbrev",
742 .size = 128,
743 .alignment = 1,
725 .type = elf.SHT_PROGBITS,
726 .addralign = 1,
727 .offset = std.math.maxInt(u64),
744728 });
729 const shdr = &self.shdrs.items[self.debug_abbrev_section_index.?];
730 const size: u64 = 128;
731 const off = self.findFreeSpace(size, 1);
732 shdr.sh_offset = off;
733 shdr.sh_size = size;
745734 zig_object.debug_abbrev_section_dirty = true;
746735 }
747736
748737 if (self.debug_aranges_section_index == null) {
749 self.debug_aranges_section_index = try self.allocateNonAllocSection(.{
738 self.debug_aranges_section_index = try self.addSection(.{
750739 .name = ".debug_aranges",
751 .size = 160,
752 .alignment = 16,
740 .type = elf.SHT_PROGBITS,
741 .addralign = 16,
742 .offset = std.math.maxInt(u64),
753743 });
744 const shdr = &self.shdrs.items[self.debug_aranges_section_index.?];
745 const size: u64 = 160;
746 const off = self.findFreeSpace(size, 16);
747 shdr.sh_offset = off;
748 shdr.sh_size = size;
754749 zig_object.debug_aranges_section_dirty = true;
755750 }
756751
757752 if (self.debug_line_section_index == null) {
758 self.debug_line_section_index = try self.allocateNonAllocSection(.{
753 self.debug_line_section_index = try self.addSection(.{
759754 .name = ".debug_line",
760 .size = 250,
761 .alignment = 1,
755 .type = elf.SHT_PROGBITS,
756 .addralign = 1,
757 .offset = std.math.maxInt(u64),
762758 });
759 const shdr = &self.shdrs.items[self.debug_line_section_index.?];
760 const size: u64 = 250;
761 const off = self.findFreeSpace(size, 1);
762 shdr.sh_offset = off;
763 shdr.sh_size = size;
763764 zig_object.debug_line_header_dirty = true;
764765 }
765766 }