| ... | ... | @@ -484,36 +484,6 @@ fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u64) u64 { |
| 484 | 484 | return start; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | | const 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 | | |
| 498 | | fn 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 | | |
| 517 | 487 | /// TODO move to ZigObject |
| 518 | 488 | pub fn initMetadata(self: *Elf) !void { |
| 519 | 489 | const gpa = self.base.allocator; |
| ... | ... | @@ -718,48 +688,79 @@ pub fn initMetadata(self: *Elf) !void { |
| 718 | 688 | if (self.debug_str_section_index == null) { |
| 719 | 689 | assert(dw.strtab.buffer.items.len == 0); |
| 720 | 690 | 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(.{ |
| 722 | 692 | .name = ".debug_str", |
| 723 | | .size = @intCast(dw.strtab.buffer.items.len), |
| 724 | 693 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, |
| 725 | 694 | .entsize = 1, |
| 695 | .type = elf.SHT_PROGBITS, |
| 696 | .addralign = 1, |
| 697 | .offset = std.math.maxInt(u64), |
| 726 | 698 | }); |
| 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; |
| 727 | 704 | zig_object.debug_strtab_dirty = true; |
| 728 | 705 | } |
| 729 | 706 | |
| 730 | 707 | 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(.{ |
| 732 | 709 | .name = ".debug_info", |
| 733 | | .size = 200, |
| 734 | | .alignment = 1, |
| 710 | .type = elf.SHT_PROGBITS, |
| 711 | .addralign = 1, |
| 712 | .offset = std.math.maxInt(u64), |
| 735 | 713 | }); |
| 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; |
| 736 | 719 | zig_object.debug_info_header_dirty = true; |
| 737 | 720 | } |
| 738 | 721 | |
| 739 | 722 | 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(.{ |
| 741 | 724 | .name = ".debug_abbrev", |
| 742 | | .size = 128, |
| 743 | | .alignment = 1, |
| 725 | .type = elf.SHT_PROGBITS, |
| 726 | .addralign = 1, |
| 727 | .offset = std.math.maxInt(u64), |
| 744 | 728 | }); |
| 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; |
| 745 | 734 | zig_object.debug_abbrev_section_dirty = true; |
| 746 | 735 | } |
| 747 | 736 | |
| 748 | 737 | 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(.{ |
| 750 | 739 | .name = ".debug_aranges", |
| 751 | | .size = 160, |
| 752 | | .alignment = 16, |
| 740 | .type = elf.SHT_PROGBITS, |
| 741 | .addralign = 16, |
| 742 | .offset = std.math.maxInt(u64), |
| 753 | 743 | }); |
| 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; |
| 754 | 749 | zig_object.debug_aranges_section_dirty = true; |
| 755 | 750 | } |
| 756 | 751 | |
| 757 | 752 | 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(.{ |
| 759 | 754 | .name = ".debug_line", |
| 760 | | .size = 250, |
| 761 | | .alignment = 1, |
| 755 | .type = elf.SHT_PROGBITS, |
| 756 | .addralign = 1, |
| 757 | .offset = std.math.maxInt(u64), |
| 762 | 758 | }); |
| 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; |
| 763 | 764 | zig_object.debug_line_header_dirty = true; |
| 764 | 765 | } |
| 765 | 766 | } |