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 all commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ set(ZIG_STD_FILES
"os/linux/index.zig"
"os/linux/vdso.zig"
"os/linux/x86_64.zig"
"os/linux/arm64.zig"
"os/path.zig"
"os/time.zig"
"os/windows/advapi32.zig"
Expand Down
4 changes: 2 additions & 2 deletions src-self-hosted/libc_installation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub const LibCInstallation = struct {
switch (builtin.arch) {
builtin.Arch.i386 => try stream.write("x86"),
builtin.Arch.x86_64 => try stream.write("x64"),
builtin.Arch.aarch64 => try stream.write("arm"),
builtin.Arch.aarch64v8 => try stream.write("arm"),
else => return error.UnsupportedArchitecture,
}
const ucrt_lib_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "ucrt.lib");
Expand Down Expand Up @@ -355,7 +355,7 @@ pub const LibCInstallation = struct {
switch (builtin.arch) {
builtin.Arch.i386 => try stream.write("x86\\"),
builtin.Arch.x86_64 => try stream.write("x64\\"),
builtin.Arch.aarch64 => try stream.write("arm\\"),
builtin.Arch.aarch64v8 => try stream.write("arm\\"),
else => return error.UnsupportedArchitecture,
}
const kernel32_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "kernel32.lib");
Expand Down
4 changes: 2 additions & 2 deletions src-self-hosted/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
switch (ctx.comp.target.getArch()) {
builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"),
builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"),
builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"),
builtin.Arch.aarch64v8 => try ctx.args.append(c"-MACHINE:ARM"),
else => return error.UnsupportedLinkArchitecture,
}

Expand Down Expand Up @@ -556,7 +556,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
}
},
DarwinPlatform.Kind.IPhoneOS => {
if (ctx.comp.target.getArch() == builtin.Arch.aarch64) {
if (ctx.comp.target.getArch() == builtin.Arch.aarch64v8) {
// iOS does not need any crt1 files for arm64
} else if (platform.versionLessThan(3, 1)) {
try ctx.args.append(c"-lcrt1.o");
Expand Down
44 changes: 39 additions & 5 deletions src-self-hosted/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,20 @@ pub const Target = union(enum) {
builtin.Arch.renderscript32,
=> return 32,

builtin.Arch.aarch64,
builtin.Arch.aarch64_be,
builtin.Arch.aarch64v8_3a,
builtin.Arch.aarch64v8_2a,
builtin.Arch.aarch64v8_1a,
builtin.Arch.aarch64v8,
builtin.Arch.aarch64v8r,
builtin.Arch.aarch64v8m_baseline,
builtin.Arch.aarch64v8m_mainline,
builtin.Arch.aarch64_bev8_3a,
builtin.Arch.aarch64_bev8_2a,
builtin.Arch.aarch64_bev8_1a,
builtin.Arch.aarch64_bev8,
builtin.Arch.aarch64_bev8r,
builtin.Arch.aarch64_bev8m_baseline,
builtin.Arch.aarch64_bev8m_mainline,
builtin.Arch.mips64,
builtin.Arch.mips64el,
builtin.Arch.powerpc64,
Expand Down Expand Up @@ -316,8 +328,23 @@ pub const Target = union(enum) {
builtin.Arch.sparcel,
=> return "/lib/ld-linux.so.2",

builtin.Arch.aarch64 => return "/lib/ld-linux-aarch64.so.1",
builtin.Arch.aarch64_be => return "/lib/ld-linux-aarch64_be.so.1",
builtin.Arch.aarch64v8_3a,
builtin.Arch.aarch64v8_2a,
builtin.Arch.aarch64v8_1a,
builtin.Arch.aarch64v8,
builtin.Arch.aarch64v8r,
builtin.Arch.aarch64v8m_baseline,
builtin.Arch.aarch64v8m_mainline,
=> return "/lib/ld-linux-aarch64.so.1",

builtin.Arch.aarch64_bev8_3a,
builtin.Arch.aarch64_bev8_2a,
builtin.Arch.aarch64_bev8_1a,
builtin.Arch.aarch64_bev8,
builtin.Arch.aarch64_bev8r,
builtin.Arch.aarch64_bev8m_baseline,
builtin.Arch.aarch64_bev8m_mainline,
=> return "/lib/ld-linux-aarch64_be.so.1",

builtin.Arch.armv8_3a,
builtin.Arch.armv8_2a,
Expand Down Expand Up @@ -530,7 +557,14 @@ pub const Target = union(enum) {
pub fn getDarwinArchString(self: Target) []const u8 {
const arch = self.getArch();
switch (arch) {
builtin.Arch.aarch64 => return "arm64",
builtin.Arch.aarch64v8_3a,
builtin.Arch.aarch64v8_2a,
builtin.Arch.aarch64v8_1a,
builtin.Arch.aarch64v8,
builtin.Arch.aarch64v8r,
builtin.Arch.aarch64v8m_baseline,
builtin.Arch.aarch64v8m_mainline,
=> return "arm64",
builtin.Arch.thumb,
builtin.Arch.armv8_3a,
builtin.Arch.armv8_2a,
Expand Down
4 changes: 2 additions & 2 deletions src/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void populate_termination(Termination *term, int status) {
static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, Termination *term) {
pid_t pid = fork();
if (pid == -1)
zig_panic("fork failed");
zig_panic("fork failed: %s", strerror(errno));
if (pid == 0) {
// child
const char **argv = allocate<const char *>(args.length + 2);
Expand Down Expand Up @@ -841,7 +841,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,

pid_t pid = fork();
if (pid == -1)
zig_panic("fork failed");
zig_panic("fork failed: %s", strerror(errno));
if (pid == 0) {
// child
if (dup2(stdin_pipe[0], STDIN_FILENO) == -1)
Expand Down
21 changes: 18 additions & 3 deletions src/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,22 @@ static const ArchType arch_list[] = {
{ZigLLVM_armeb, ZigLLVM_ARMSubArch_v5te},
{ZigLLVM_armeb, ZigLLVM_ARMSubArch_v4t},

{ZigLLVM_aarch64, ZigLLVM_NoSubArch},
{ZigLLVM_aarch64_be, ZigLLVM_NoSubArch},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_3a},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_2a},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_1a},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8r},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_baseline},
{ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_mainline},

{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_3a},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_2a},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_1a},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8r},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_baseline},
{ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_mainline},

{ZigLLVM_arc, ZigLLVM_NoSubArch},
{ZigLLVM_avr, ZigLLVM_NoSubArch},
{ZigLLVM_bpfel, ZigLLVM_NoSubArch},
Expand Down Expand Up @@ -928,8 +942,9 @@ const char *arch_stack_pointer_register_name(const ArchType *arch) {
return "sp";
case ZigLLVM_x86_64:
return "rsp";

case ZigLLVM_aarch64:
return "sp";

case ZigLLVM_arm:
case ZigLLVM_thumb:
case ZigLLVM_aarch64_be:
Expand Down
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
4 changes: 3 additions & 1 deletion std/fmt/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,9 @@ test "fmt.format" {
const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
assert(mem.eql(u8, result, "f64: nan\n"));
}
{
Copy link
Member

Choose a reason for hiding this comment

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

can you disable this test only for ARM?

if (builtin.arch ...

if (builtin.arch != builtin.Arch.armv8) {
// negative nan is not defined by IEE 754,
// and ARM thus normalizes it to positive nan
var buf1: [32]u8 = undefined;
const result = try bufPrint(buf1[0..], "f64: {}\n", -math.nan_f64);
assert(mem.eql(u8, result, "f64: -nan\n"));
Expand Down
8 changes: 7 additions & 1 deletion std/math/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub const pi = 3.14159265358979323846264338327950288419716939937510;

// float.h details
pub const f64_true_min = 4.94065645841246544177e-324;
pub const f64_min = 2.22507385850720138309e-308;
pub const f64_min = 2.2250738585072014e-308;
pub const f64_max = 1.79769313486231570815e+308;
pub const f64_epsilon = 2.22044604925031308085e-16;
pub const f64_toint = 1.0 / f64_epsilon;
Expand Down Expand Up @@ -650,3 +650,9 @@ pub fn lossyCast(comptime T: type, value: var) T {
else => @compileError("bad type"),
}
}

test "math.f64_min" {
const f64_min_u64 = 0x0010000000000000;
const fmin: f64 = f64_min;
assert(@bitCast(u64, fmin) == f64_min_u64);
}
18 changes: 11 additions & 7 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 = null;
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 Expand Up @@ -1641,7 +1646,7 @@ pub const Dir = struct {
}

while (true) {
const result = posix.getdents(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len);
const result = posix.getdents64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len);
const err = posix.getErrno(result);
if (err > 0) {
switch (err) {
Expand All @@ -1659,7 +1664,7 @@ pub const Dir = struct {
break;
}
}
const linux_entry = @ptrCast(*align(1) posix.dirent, &self.handle.buf[self.handle.index]);
const linux_entry = @ptrCast(*align(1) posix.dirent64, &self.handle.buf[self.handle.index]);
const next_index = self.handle.index + linux_entry.d_reclen;
self.handle.index = next_index;

Expand All @@ -1670,8 +1675,7 @@ pub const Dir = struct {
continue :start_over;
}

const type_char = self.handle.buf[next_index - 1];
const entry_kind = switch (type_char) {
const entry_kind = switch (linux_entry.d_type) {
posix.DT_BLK => Entry.Kind.BlockDevice,
posix.DT_CHR => Entry.Kind.CharacterDevice,
posix.DT_DIR => Entry.Kind.Directory,
Expand Down
Loading