mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
Elf: fix unaligned segments on non-linux
Linux isn't the only OS that `mmap`s segments.
This commit is contained in:
parent
c7ffdbcd41
commit
de68a3ad43
@ -623,7 +623,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
|
||||
const ptr_size = self.ptrWidthBytes();
|
||||
const target = self.base.comp.root_mod.resolved_target.result;
|
||||
const ptr_bit_width = target.ptrBitWidth();
|
||||
const is_linux = target.os.tag == .linux;
|
||||
const has_os = target.os.tag != .freestanding;
|
||||
const zig_object = self.zigObjectPtr().?;
|
||||
|
||||
const fillSection = struct {
|
||||
@ -661,7 +661,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
|
||||
if (self.phdr_zig_got_index == null) {
|
||||
// We really only need ptr alignment but since we are using PROGBITS, linux requires
|
||||
// page align.
|
||||
const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
|
||||
const alignment = if (has_os) self.page_size else @as(u16, ptr_size);
|
||||
const filesz = @as(u64, ptr_size) * options.symbol_count_hint;
|
||||
const off = self.findFreeSpace(filesz, alignment);
|
||||
self.phdr_zig_got_index = try self.addPhdr(.{
|
||||
@ -676,7 +676,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
|
||||
}
|
||||
|
||||
if (self.phdr_zig_load_ro_index == null) {
|
||||
const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
|
||||
const alignment = if (has_os) self.page_size else @as(u16, ptr_size);
|
||||
const filesz: u64 = 1024;
|
||||
const off = self.findFreeSpace(filesz, alignment);
|
||||
self.phdr_zig_load_ro_index = try self.addPhdr(.{
|
||||
@ -691,7 +691,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
|
||||
}
|
||||
|
||||
if (self.phdr_zig_load_rw_index == null) {
|
||||
const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
|
||||
const alignment = if (has_os) self.page_size else @as(u16, ptr_size);
|
||||
const filesz: u64 = 1024;
|
||||
const off = self.findFreeSpace(filesz, alignment);
|
||||
self.phdr_zig_load_rw_index = try self.addPhdr(.{
|
||||
@ -706,7 +706,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
|
||||
}
|
||||
|
||||
if (self.phdr_zig_load_zerofill_index == null) {
|
||||
const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
|
||||
const alignment = if (has_os) self.page_size else @as(u16, ptr_size);
|
||||
self.phdr_zig_load_zerofill_index = try self.addPhdr(.{
|
||||
.type = elf.PT_LOAD,
|
||||
.addr = if (ptr_bit_width >= 32) 0x14000000 else 0xf000,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user