Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial arm64 support #1429

Merged
merged 9 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions std/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ pub const Elf_MIPS_ABIFlags_v0 = extern struct {
flags2: Elf32_Word,
};

pub const Auxv = switch (@sizeOf(usize)) {
4 => Elf32_auxv_t,
8 => Elf64_auxv_t,
else => @compileError("expected pointer size of 32 or 64"),
};
pub const Ehdr = switch (@sizeOf(usize)) {
4 => Elf32_Ehdr,
8 => Elf64_Ehdr,
Expand Down
11 changes: 8 additions & 3 deletions std/os/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,21 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
};
}

pub var linux_aux_raw = []usize{0} ** 38;
pub var linux_elf_aux_maybe: ?[*]std.elf.Auxv = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you want this to be initialized to null, not undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it is always set at program initialization, initializing it to null requires more code in every executable. I make it a maybe because one might want to unmap the entire elf auxiliary vector to save space.

Copy link
Member

@andrewrk andrewrk Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not set at program initialization when zig code is used as a library, with main in a C object, for example. It's also not set at program initialization when the user puts export fn main(argc: c_int, argv: [*][*]u8) c_int {...} and links with libc. Why would initializing it to null require more code? It's static data, so if it's null it would go in the .bss section.

pub var posix_environ_raw: [][*]u8 = undefined;

/// See std.elf for the constants.
pub fn linuxGetAuxVal(index: usize) usize {
if (builtin.link_libc) {
return usize(std.c.getauxval(index));
} else {
return linux_aux_raw[index];
} else if (linux_elf_aux_maybe) |auxv| {
var i: usize = 0;
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
if (auxv[i].a_type == index)
return auxv[i].a_un.a_val;
}
}
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this return null, and make the return ?usize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The libc version doesn't distinguish, so the zig-native version matches the API.

}

pub fn getBaseAddress() usize {
Expand Down
6 changes: 2 additions & 4 deletions std/os/linux/arm64.zig
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,8 @@ pub const SYS_io_pgetevents = 292;
pub const SYS_syscalls = 293;

pub const VDSO_USEFUL = true;
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
pub const VDSO_CGT_VER = "LINUX_2.6";
pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
pub const VDSO_GETCPU_VER = "LINUX_2.6";
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
pub const VDSO_CGT_VER = "LINUX_2.6.39";

pub fn syscall0(number: usize) usize {
return asm volatile ("svc #0"
Expand Down
2 changes: 1 addition & 1 deletion std/os/linux/vdso.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cstr = std.cstr;
const mem = std.mem;

pub fn lookup(vername: []const u8, name: []const u8) usize {
const vdso_addr = std.os.linux_aux_raw[std.elf.AT_SYSINFO_EHDR];
const vdso_addr = std.os.linuxGetAuxVal(std.elf.AT_SYSINFO_EHDR);
if (vdso_addr == 0) return 0;

const eh = @intToPtr(*elf.Ehdr, vdso_addr);
Expand Down
7 changes: 2 additions & 5 deletions std/special/bootstrap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ fn posixCallMainAndExit() noreturn {
const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
if (builtin.os == builtin.Os.linux) {
const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);
var i: usize = 0;
while (auxv[i] != 0) : (i += 2) {
if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
}
std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size);
std.os.linux_elf_aux_maybe = @ptrCast([*]std.elf.Auxv, auxv);
std.debug.assert(std.os.linuxGetAuxVal(std.elf.AT_PAGESZ) == std.os.page_size);
}

std.os.posix.exit(callMainWithArgs(argc, argv, envp));
Expand Down