lib/tldr/src/formats/elf/merge/section.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const elf = @import("../root.zig");
 3 
 4 const Allocator = std.mem.Allocator;
 5 const ObjectFile = elf.parser.ObjectFile;
 6 const MergeSectionLayout = elf.layout.MergeSectionLayout;
 7 const SectionHeader = elf.format.SectionHeader;
 8 
 9 pub fn ensure(
10     allocator: Allocator,
11     object: ObjectFile,
12     merge_sections: *[]MergeSectionLayout,
13 ) Allocator.Error![]MergeSectionLayout {
14     if (merge_sections.*.len != 0) return merge_sections.*;
15     const sections = try allocator.alloc(MergeSectionLayout, object.sections.len);
16     @memset(sections, .{});
17     merge_sections.* = sections;
18     return sections;
19 }
20 
21 pub fn fixed(section: SectionHeader) bool {
22     if ((section.flags & std.elf.SHF_ALLOC) == 0) return false;
23     if ((section.flags & std.elf.SHF_MERGE) == 0) return false;
24     if ((section.flags & std.elf.SHF_STRINGS) != 0) return false;
25     if (section.section_type != std.elf.SHT_PROGBITS) return false;
26     if (section.entry_size == 0) return false;
27     return true;
28 }
29 
30 pub fn string(section: SectionHeader) bool {
31     if ((section.flags & std.elf.SHF_ALLOC) == 0) return false;
32     if ((section.flags & std.elf.SHF_MERGE) == 0) return false;
33     if ((section.flags & std.elf.SHF_STRINGS) == 0) return false;
34     if (section.section_type != std.elf.SHT_PROGBITS) return false;
35     if (section.entry_size > 1) return false;
36     if (section.alignment > 1) return false;
37     return true;
38 }