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

initial arm64 support #1429

merged 9 commits into from Oct 6, 2018

Conversation

shawnl
Copy link
Contributor

@shawnl shawnl commented Aug 27, 2018

  • _start
  • syscalls
  • clone
  • vdso

@shawnl shawnl closed this Aug 27, 2018
@shawnl shawnl reopened this Aug 27, 2018
@shawnl shawnl closed this Aug 27, 2018
@andrewrk
Copy link
Member

I'm happy to add arm support, but the biggest showstopper is #835 - if we can't get automated tests running on every pushed commit, we can't add support. The biggest step anyone can do toward getting zig to support another target is solving the CI problem.

@shawnl
Copy link
Contributor Author

shawnl commented Aug 27, 2018

ok, the hello world builds in --release-fast mode, just not debug mode, as there are problems with the atomics (which compile out) and maybe other bugs. That is why I closed it, I wanted more to work

@shawnl shawnl reopened this Aug 27, 2018
@andrewrk andrewrk added this to the 1.0.0 milestone Aug 27, 2018
@andrewrk
Copy link
Member

This PR depends on having CI for ARM.

@shawnl shawnl force-pushed the arm64 branch 3 times, most recently from c1a1012 to 8b6bd05 Compare August 28, 2018 11:40
@shawnl
Copy link
Contributor Author

shawnl commented Aug 29, 2018

CI for arm https://buildbot.git.icu/buildbot/

builds on pushes to master, and if you set up github webhooks to

https://buildbot.git.icu/buildbot/change_hook/github (push)

then it will build on pull requests.

I don't know how to get it integrated in the github GUI.
I can add FreeBSD and OpenBSD when someone does the porting work.

@shawnl shawnl force-pushed the arm64 branch 13 times, most recently from 2599ed7 to 789ee9e Compare August 30, 2018 18:36
@shawnl
Copy link
Contributor Author

shawnl commented Aug 30, 2018

llvm is generating garbage assembly https://bugs.llvm.org/show_bug.cgi?id=38734 which this bug is blocked on.

also, the CI is timing out on windows and max osx.

@andrewrk
Copy link
Member

This might be zig doing the C ABI incorrectly. LLVM sadly does not provide the C ABI. I would check the equivalent LLVM IR generated by clang and compare.

@andrewrk
Copy link
Member

Oh, wait, that does seem like an llvm bug because your code is not doing the c ABI. Nevermind previous comment.

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 3, 2018
@shawnl shawnl force-pushed the arm64 branch 2 times, most recently from 30e22c9 to e7ca743 Compare September 8, 2018 03:37
these don't exist on new platforms (such as arm64)

also switch from the deprecated dirent to dirent64
arm64 complains about the old value (I added a test)
From IEEE-754 standard:

Conversion of a quiet NaN in a supported format to an external character sequence
shall produce a language-defined one of “nan” or a sequence that is equivalent except
for case (e.g., “NaN”), with an optional preceding sign. (This standard does not interpret
the sign of a NaN.)
Auxillery vectors are not guaranteed to be in any order, this
just happens to work on x86_64.
}
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.

Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

This looks really good. I have a few things to address, and then it's ready for merge.

@@ -1034,11 +1034,6 @@ 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 ...

@@ -624,6 +625,54 @@ pub const S_IWOTH = 0o002;
pub const S_IXOTH = 0o001;
pub const S_IRWXO = 0o007;

pub const O_CREAT = 0o100;
Copy link
Member

Choose a reason for hiding this comment

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

Although these constants are the same on x86_64 and aarch64, they are per-architecture values:

andy@xps ~/d/musl> grep -RI O_CREAT
arch/mips64/bits/fcntl.h:#define O_CREAT        0400
arch/generic/bits/fcntl.h:#define O_CREAT        0100
arch/x32/bits/fcntl.h:#define O_CREAT        0100
arch/powerpc64/bits/fcntl.h:#define O_CREAT        0100
arch/arm/bits/fcntl.h:#define O_CREAT        0100
arch/s390x/bits/fcntl.h:#define O_CREAT        0100
arch/mips/bits/fcntl.h:#define O_CREAT        0400
arch/x86_64/bits/fcntl.h:#define O_CREAT        0100
arch/aarch64/bits/fcntl.h:#define O_CREAT        0100
arch/m68k/bits/fcntl.h:#define O_CREAT        0100
arch/mipsn32/bits/fcntl.h:#define O_CREAT        0400
arch/powerpc/bits/fcntl.h:#define O_CREAT        0100

I think they should stay in the per-architecture files to prevent bugs when more architecture support is added in the future.

@@ -1189,17 +1272,22 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
}

pub fn fstat(fd: i32, stat_buf: *Stat) usize {
return syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
return fstatat(fd, c"", stat_buf, AT_EMPTY_PATH);
Copy link
Member

@andrewrk andrewrk Oct 2, 2018

Choose a reason for hiding this comment

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

I don't think this is really important, but, is there a benefit to not calling fstat? The previous version of this function does slightly less work, since it has to set up 2 fewer parameters, and it supports older kernels. (Same question for e.g. epoll_pwait.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by comment: arm64 doesn't have an epoll_wait() syscall, only epoll_pwait(). libc emulates epoll_wait() as epoll_pwait() with a null sigmask, just like this PR does.

(Arm64 does have fstat() though, so no reason I can see to use fstatat().)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arm64 also has execve and execveat

std/os/index.zig Outdated
@@ -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.

@andrewrk
Copy link
Member

andrewrk commented Oct 2, 2018

I believe the current buildbot failures are due to building against llvm 6 instead of llvm 7.

src/os.cpp Outdated
@@ -839,9 +839,9 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
if ((err = pipe(stderr_pipe)))
zig_panic("pipe failed");

pid_t pid = fork();
pid_t pid = vfork();
Copy link
Member

Choose a reason for hiding this comment

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

This should be posix_spawn rather than vfork. See #1620

@shawnl shawnl force-pushed the arm64 branch 2 times, most recently from 1d8040b to f19d421 Compare October 5, 2018 18:40
@andrewrk
Copy link
Member

andrewrk commented Oct 5, 2018

Looks good to me. Are you ready for me to merge?

@andrewrk
Copy link
Member

andrewrk commented Oct 5, 2018

By the way, it looks like the buildbot environment has the wrong llvm/clang version.

@shawnl
Copy link
Contributor Author

shawnl commented Oct 6, 2018

I believe the current buildbot failures are due to building against llvm 6 instead of llvm 7.

That is the fault of this line:

cmake/Findllvm.cmake: NAMES llvm-config llvm-config-7 llvm-config-7.0

llvm-config on debian still points to llvm-config-6

should i prepare a patch?

@shawnl
Copy link
Contributor Author

shawnl commented Oct 6, 2018

Looks good to me. Are you ready for me to merge?

yes

@andrewrk
Copy link
Member

andrewrk commented Oct 6, 2018

should i prepare a patch?

I just went ahead and fixed it in master. And I'll merge this PR too. Excellent work.

@andrewrk andrewrk merged commit d40c4e7 into ziglang:master Oct 6, 2018
@andrewrk
Copy link
Member

andrewrk commented Oct 8, 2018

Looks like the build bot environment is not fixed by the Findllvm.cmake change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants