Commit Graph

1923 Commits

Author SHA1 Message Date
emekoi 1c73c08298 ran zig fmt on stdlib 2019-05-19 16:33:31 -04:00
LemonBoy 232bc1bdee Remove more 64bit-centric assumptions from stdlib 2019-05-18 11:08:04 +02:00
LemonBoy 51aaa02679 VDSO calls must use the C CC 2019-05-16 22:10:38 -04:00
Shawn Landden 1fdb24827f breaking changes to all bit manipulation intrinsics
* `@clz`, `@ctz`, `@popCount`, `@bswap`, `@bitreverse` now
   have a type parameter
 * rename @bitreverse to @bitReverse
 * rename @bswap to @byteSwap

Closes #2119
Closes #2120
2019-05-16 16:37:58 -04:00
Andrew Kelley 978fab817c the wasm freestanding _start function is return value void 2019-05-16 14:19:13 -04:00
Andrew Kelley 81e960eb74 improvements to build-lib use case of WebAssembly
* build-exe does include the startup code that supplies _start for the
   wasm32-freestanding target. Previously this did not occur because
   of logic excluding "freestanding".
 * build-lib for wasm32-freestanding target gets linked by LLD. To avoid
   infinite recursion, compiler_rt and zig libc are built as objects
   rather than libraries.
   - no "lib" prefix and ".wasm" extension instead of ".a". Rather than
   build-lib foo.zig producing "libfoo.a", now it produces "foo.wasm".
 * go back to using `.o` extension for webassembly objects
 * zig libc only provides _start symbol for wasm when linking libc.
2019-05-16 13:56:56 -04:00
daurnimator e30cd800e2 std: update linux syscalls to 5.1 2019-05-16 12:38:40 -04:00
Andrew Kelley 14cdb01f35 improvements to zig's implementation of libc and WebAssembly
* rename std/special/builtin.zig to std/special/c.zig
   not to be confused with @import("builtin") which is entirely
   different, this is zig's multi-target libc implementation.
 * WebAssembly: build-exe is for executables which have a main().
   build-lib is for building libraries of functions to use from,
   for example, a web browser environment.
   - for now pass --export-all for libraries when there are any
     C objects because we have no way to detect the list of exports
     when compiling C code.
   - stop passing --no-entry for executables. if you want --no-entry
     then use build-lib.
 * make the "musl" ABI the default ABI for wasm32-freestanding.
 * zig provides libc for wasm32-freestanding-musl.
2019-05-15 20:14:58 -04:00
LemonBoy 787fd0f1be Fix off-by-one error in LEB128 parsing 2019-05-15 11:11:16 -04:00
Andrew Kelley 5a57610039 clean up code now that #769 is implemented 2019-05-14 19:23:31 -04:00
Marc Tiehuis b64cee2ec2 Merge pull request #2482 from ziglang/linux-elf-read
Mmap debug info on linux
2019-05-14 16:43:21 +12:00
LemonBoy 08d41da916 Fix formatting for multiline asm expressions 2019-05-13 12:20:11 -04:00
Andrew Kelley f3db3b3c13 Merge branch 'asm-cc' of https://github.com/LemonBoy/zig into LemonBoy-asm-cc 2019-05-13 12:10:21 -04:00
LemonBoy a038ef3570 Assemble asm files using CC
Stuffing all the files together and compiling the resulting blob with
the main program is a terrible idea.

Some files, namely the .S ones, must be run trough the C preprocessor
before assembling them (#2437).

Beside that the aggregate may be mis-compiled due to the presence of
some flags that affect the following code.

For example let's consider two files, a.s and b.s

a.s
```
fn1:
    ret
.data
data1:
    .word 0
```

b.s
```
fn2:
    ret
```

Now, fn1 and fn2 will be both placed in the .text section as intended if
the two files are compiled separately. But if we merge them the `.data`
flag ends up placing fn2 in the wrong section!

This fixes a nasty crash where musl's memset ended up in the
non-executable data segment, leading to too many hours of
head-scratching.
2019-05-13 16:41:07 +02:00
Marc Tiehuis c4d1597f50 Mmap debug info on linux
Closes #907.
2019-05-13 20:04:25 +12:00
Andrew Kelley c1793d6106 zig fmt on the standard library 2019-05-12 12:56:01 -04:00
hryx 173142b16a Undo parse2 import 2019-05-12 03:24:48 -07:00
hryx 0d629421c9 Recursive rewrite of stage2 parser, final sync 2019-05-12 02:10:27 -07:00
hryx 3a3a738478 Recursive rewrite of stage2 parser, part 3 2019-05-12 02:01:45 -07:00
hryx 3787f34286 Merge branch 'master' into rebased 2019-05-12 02:00:49 -07:00
Tyler Philbrick 16aee1f58a Fix memory leak in parser tests
The `arena` instance being used bythe parse tree was valid and
pointed to valid memory, but existed as a local variable inside the
stack frame of the `parse` function (the `const arena`), which was never
stored anywhere before leaving the scope.

This meant that code above the `parse` function saw a valid instance of
an `ArenaAllocator` that pointed to the same backing memory, but didn't
posess any of the local state built up after the call to `parseRoot`,
basically the caller saw an empty arena.

This meant that when `deinit` was called, it saw an Arena with 0
allocations in it's `buffer_list` and wasn't able to destroy any of the
memory.  This caused it to leak and caused FailingAllocator to balk.

The fix is to make sure the parse tree is using the same instance of
ArenaAllocator as is reported up the call stack, the one inside the
`Tree{}` object.  I'm not sure why that field is marked with a comment
to remove it, as it's used by the `std.ast.Tree.deinit()` function, but
this change seems to solve the problem.
2019-05-12 01:54:30 -07:00
hryx 4e28c2571d Recursive rewrite of stage2 parser, part 1 2019-05-12 01:52:16 -07:00
Andrew Kelley 32efa68f90 Merge pull request #2449 from Sahnvour/directallocator
Rework of windows' DirectAllocator
2019-05-11 13:04:20 -04:00
Andrew Kelley 2ef2f9d71f Merge pull request #2475 from LemonBoy/linux-wo-vdso
Fix clock_gettime on systems without VDSO
2019-05-11 12:01:52 -04:00
Sahnvour cd537f822b Use unprotected heap when in single_threaded mode. 2019-05-11 16:41:13 +02:00
Sahnvour a2d5b0fabe Implement Windows' DirectAllocator on top of VirtualAlloc and VirtualFree. 2019-05-11 16:41:13 +02:00
daurnimator 3d93c89fc5 std: the failing allocator didn't actually count allocations
Add a field '.allocations' to actually track the number of allocations.

Additionally, only increment '.deallocations' when memory is freed
2019-05-11 09:55:41 -04:00
LemonBoy 6756e545f4 Fix more corner cases in LEB128 parsing 2019-05-11 09:54:48 -04:00
LemonBoy 1b23348f30 linux: Minor zig fmt induced reformatting 2019-05-11 10:34:22 +02:00
LemonBoy 715d808f14 linux: Fix clock_gettime on systems w/o VDSO 2019-05-11 10:33:41 +02:00
Andrew Kelley bcf4d20289 Merge pull request #2465 from LemonBoy/builtins-for-wasm
A few builtins for wasm
2019-05-10 08:44:27 -04:00
LemonBoy 1606dae728 Fix erroneous test case
The *Mem variants cannot return EndOfStream and are generally unsafe to
use.
Proper order of checks, try both the variants and make sure they return
the same error/result.
Run the leb128.zig tests.
2019-05-10 08:40:36 -04:00
LemonBoy 7fb55ce2bb compiler-rt: Add __ashrti3 2019-05-10 13:26:33 +02:00
LemonBoy fbffece1b5 compiler-rt: Add __lshrti3 2019-05-10 13:26:33 +02:00
LemonBoy 7db2aa1c25 compiler-rt: Add __ashlti3 2019-05-10 13:26:33 +02:00
LemonBoy 8cc4eaea9f Use matching types when parsing fields 2019-05-10 00:44:24 +02:00
LemonBoy 4d8f96dd88 Fix minor bug in LEB128 parsing 2019-05-10 00:41:05 +02:00
Andrew Kelley 72899da44b fix std.os.copyFile
closes #2454
2019-05-09 13:05:06 -04:00
Andrew Kelley a7346ea49f fix build on macOS
Sadly due to a workaround for LLD linker limitations on macOS
we cannot put libuserland into an .a file; instead we have to use object
files. Again due to linker limitations, bundling compiler_rt.o into
another relocatable object also doesn't work. So we're left with
disabling stack probing on macOS for the stage1 self-hosted code.

These workarounds could all be removed if the macos support in the LLD
linker improved, or if Zig project had its own linker that did not have
these issues.
2019-05-08 22:45:49 -04:00
Andrew Kelley 4b9e12be50 Merge pull request #2452 from LemonBoy/more-more-builtins
More more builtins
2019-05-08 22:24:12 -04:00
Andrew Kelley 9bbd71c9ab add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley 9c12237d2d std.debug: fix stack trace iteration code
Previously, the stack trace iteration code was using the number of
frames collected as the number of frames to print, not recognizing the
fixed size of the buffer. So it would redundantly print items, matching
the total number of frames ever collected.

Now the iteration code is limited to the actual stack trace frame count,
and will not print duplicate frames.

Closes #2447
Closes #2151
2019-05-08 19:11:01 -04:00
LemonBoy 4208fa9ad9 compiler-rt: add __floatsitf 2019-05-09 00:25:50 +02:00
LemonBoy 383b8a032e compiler-rt: Add __aeabi_unwind_cpp_pr{0,1,2} 2019-05-09 00:07:46 +02:00
LemonBoy 2dce137d92 compiler-rt: Add __extendsfdf2
Add AEABI builtin __aeabi_f2d
2019-05-09 00:07:46 +02:00
LemonBoy 2be066d057 compiler-rt: Add __floatdidf
Add AEABI builtin __aeabi_l2d
2019-05-08 23:57:09 +02:00
LemonBoy d4434dfb67 compiler-rt: Add __floatundidf & __floatunsidf
Add AEABI builtins __aeabi_ul2d, __aeabi_ui2d
2019-05-08 23:57:09 +02:00
LemonBoy 92fd2df054 compiler-rt: Add __truncdfsf2
Add AEABI builtin __aeabi_d2f
2019-05-08 23:57:09 +02:00
LemonBoy c00167e91a compiler-rt: More division intrinsics 2019-05-08 22:30:20 +02:00
LemonBoy 917103710e compiler-rt: Add __floatsidf & __floatsisf
Also add their AEABI aliases, __aeabi_i2f & __aeabi_i2d
2019-05-08 22:26:54 +02:00