| ... | ... | @@ -528,13 +528,11 @@ pub const SectionHeader = extern struct { |
| 528 | 528 | |
| 529 | 529 | /// Applicable only to section headers in COFF objects. |
| 530 | 530 | pub fn getAlignment(self: SectionHeader) ?u16 { |
| 531 | | if (self.flags.ALIGN == 0) return null; |
| 532 | | return std.math.powi(u16, 2, self.flags.ALIGN - 1) catch unreachable; |
| 531 | return self.flags.ALIGN.toByteUnits(); |
| 533 | 532 | } |
| 534 | 533 | |
| 535 | 534 | pub fn setAlignment(self: *SectionHeader, new_alignment: u16) void { |
| 536 | | assert(new_alignment > 0 and new_alignment <= 8192); |
| 537 | | self.flags.ALIGN = @intCast(std.math.log2(new_alignment)); |
| 535 | self.flags.ALIGN = .fromByteUnits(new_alignment); |
| 538 | 536 | } |
| 539 | 537 | |
| 540 | 538 | pub fn isCode(self: SectionHeader) bool { |
| ... | ... | @@ -651,6 +649,16 @@ pub const SectionHeader = extern struct { |
| 651 | 649 | @"4096BYTES" = 13, |
| 652 | 650 | @"8192BYTES" = 14, |
| 653 | 651 | _, |
| 652 | |
| 653 | pub fn toByteUnits(a: Align) ?u16 { |
| 654 | if (a == .NONE) return null; |
| 655 | return @as(u16, 1) << (@intFromEnum(a) - 1); |
| 656 | } |
| 657 | |
| 658 | pub fn fromByteUnits(n: u16) Align { |
| 659 | std.debug.assert(std.math.isPowerOfTwo(n)); |
| 660 | return @enumFromInt(@ctz(n) + 1); |
| 661 | } |
| 654 | 662 | }; |
| 655 | 663 | }; |
| 656 | 664 | }; |