16096 Commits

Author SHA1 Message Date
Jakub Konka
dbfcebf8d8 macho: allow undefined symbols in dylibs
We now respect both `-fallow-shlib-undefined` and
`-Wl,"-undefined=dynamic_lookup"` flags. This is the first step
towards solving issues #8180 and #3000. We currently do not expose
any other ld64 equivalent flag for `-undefined` flag - we basically
throw an error should the user specify a different flag. Support for
those is conditional on closing #8180. As a result of this change,
it is now possible to generate a valid native Node.js addon with Zig
for macOS.
2021-12-12 00:32:03 +01:00
Jan Philipp Hafer
efdb94486b compiler_rt: add __bswapsi2, __bswapdi2 and __bswapti2
- each byte gets masked, shifted and combined
- use boring masks instead of comptime for readability
- tests: bit patterns with reverse operation, if applicable

See #1290
2021-12-11 01:43:37 -08:00
Andrew Kelley
97c0373fa7
Merge pull request #10295 from ifreund/prefetch
Implement @prefetch()
2021-12-10 18:54:56 -08:00
Isaac Freund
516945d7d9
langref: document @prefetch() builtin 2021-12-11 00:29:31 +01:00
Isaac Freund
7bb6393b59
stage1: implement @prefetch() builtin 2021-12-11 00:29:31 +01:00
Isaac Freund
175463d75d
AstGen: implement @prefetch() builtin 2021-12-10 23:09:02 +01:00
Isaac Freund
47c309c34a
AstGen: increase zig fmt off/on granularity
This enables automatic formatting for a significant amount of code that
currently doesn't deviate from the standard zig fmt enforced style.
2021-12-10 23:09:01 +01:00
Jakub Konka
75f3e7a4a0
Merge pull request #10310 from ziglang/macho-common-functions
macho: move load command wrappers and parsing utils to std.macho
2021-12-10 21:55:21 +01:00
Jakub Konka
828f61e8df macho: move all helpers from commands.zig into std.macho
This way we will finally be able to share common parsing logic
between different Zig components and 3rd party packages.
2021-12-10 18:18:28 +01:00
Jakub Konka
81e7d8505c macho: move helper functions to libstd
Helper functions such as `commands.sectionName`, etc. should really
belong in `std.macho.section_64` extern struct.
2021-12-10 11:56:51 +01:00
Andrew Kelley
77836e08a2
Merge pull request #9930 from PhaseMage/fix-cache-timestamps
Fix isProblematicTimestamp
2021-12-09 21:11:51 -08:00
Andrew Kelley
3e618f8432 Cache: use mutex to protect recent_problematic_timestamp
The previous commit tried to use atomics but not many CPUs support
128-bit atomics. So we use a mutex. In order to avoid contention, we
also store `recent_problematic_timestamp` locally on the `Manifest`
which is only ever accessed from a single thread at a time, and only
consult the global one if the local one is problematic.

This commit was tested by running `zig build test-behavior` in two
separate terminals at the same time.
2021-12-09 22:10:38 -07:00
Andrew Kelley
fdbb329d10 Cache: fix data race with is_problematic_timestamp
Previously `recent_problematic_timestamp` was unprotected and accessed
potentially with multiple worker threads simultaneously.

This commit protects it with atomics and also introduces a flag to
prevent multiple timestamp checks from within the same call to hit().

Unfortunately the compiler-rt function __sync_val_compare_and_swap_16 is
not yet implemented, so I will have to take a different strategy in a
follow-up commit.
2021-12-09 22:10:38 -07:00
Andrew Kelley
4da83feccb Cache: improvements to previous commit
* put `recent_problematic_timestamp` onto `Cache` so that it can be
   shared by multiple Manifest instances.
 * make `isProblematicTimestamp` return true on any filesystem error.
 * save 1 syscall by using truncate=true in createFile instead of
   calling `setEndPos`.
2021-12-09 22:10:31 -07:00
Travis Martin
72ee042ab0 Cache: fix two issues with isProblematicTimestamp
1. It was looking for trailing zero bits when it should be looking for
   trailing decimal zeros.
2. Clock timestamps had more precision than the actual file timestamps

The fix is to grab a timestamp from a 'just now changed' temp file.
This timestamp is "problematic". Any file timestamp greater than or equal
to this timestamp is considered problematic. File timestamps **prior** to
this **can** be trusted.

Downside is that it causes a disk I/O to write to and then read the
timestamp from this file ~1ms on my system. This is partially mitigated by
keeping track of the most recent problematic timestamp, and only checking
for a new problematic timestamp when checking a timestamp that is equal to
or larger than the last problematic one.

This fixes #6082.
2021-12-09 18:34:17 -07:00
Andrew Kelley
01cb0bdb83
Merge pull request #10304 from ziglang/musl-stubgrade
Improve musl libc.so stubs
2021-12-09 14:12:51 -08:00
Andrew Kelley
f69f55c807 stage2: upgrade musl libc stub file
This is the result of the work on tools/gen_stubs.zig. It now uses the
preprocessor to emit different symbols and sizes depending on the
architecture. The data is collected directly from multiple libc.so files
on disk built with upstream musl.

Closes #8178
Addresses #8896 for musl

There is still room for further improvement to this, which is to
put `.ds` directives after symbols that are not followed by aliases, to
avoid the potential problem of a linker believing that all symbols are
aliases of each other.
2021-12-09 01:39:07 -07:00
Andrew Kelley
da9542c0af tools/gen_stubs: add aarch64 and output preprocessor directives
Now it outputs libc.S which can be assembled with zig, and the small
differences per-architecture are handled with preprocessor directives.

There is also now a set of blacklisted symbols which contains
compiler-rt.
2021-12-09 01:21:30 -07:00
Andrew Kelley
04d44db6cc tools/gen_stubs: consolidate symbol properties into MultiSym 2021-12-08 23:45:25 -07:00
Andrew Kelley
808b9239a3 improve musl dynamic stubs file libc.s
tools/gen_stubs.zig now cuts out the middle man and operates directly on
the libc.so ELF file. it outputs accurate .size directives for objects.

std.elf gains an STV enum.
2021-12-08 22:32:31 -07:00
Andrew Kelley
8031783539 stage1: fix regression of shift by negative value error
The previous commit (38b2d6209239f0dad7cb38e656d9d38506f126ca) regressed
the compile error test case for when doing saturating shift left of a
comptime-known negative RHS.

This commit additionally fixes the error for regular shifts in addition
to saturating shifts.
2021-12-08 19:09:37 -07:00
Andrew Kelley
38b2d62092 stage1: saturating shl operates using LHS type
Saturating shift left (`<<|`) previously used the `ir_analyze_bin_op_math`
codepath rather than the `ir_analyze_bit_shift` codepath, leading to it
doing peer type resolution (incorrect) instead of using the LHS type as
the number of bits to do the saturating against.

This required implementing SIMD vector support for `@truncate`.

Additionall, this commit adds a compile error for saturating shift left
on a comptime_int.

stage2 does not pass these new behavior tests yet.

closes #10298
2021-12-08 15:25:31 -07:00
Jakub Konka
64e2bfaa23 macho: write out LC_FUNCTION_START data 2021-12-08 23:24:40 +01:00
Jakub Konka
98e36ea6b9 macho: handle non-extern UNSIGNED relocs on arm64 2021-12-08 20:48:12 +01:00
Jakub Konka
f0ec70edd1 macho: do not write null symbols into undef symbols section
Also, skip creating stub entries for resolved globally defined
regular symbols.
2021-12-08 16:58:29 +01:00
Andrew Kelley
83a6681955 link: fix build for 32-bit targets
This wasn't caught by the CI checks because this function is is only
called for the `use_stage1` codepath.
2021-12-07 17:03:29 -07:00
Andrew Kelley
de81c504b1 CLI: allow -femit-implib when building .exe files too 2021-12-07 01:17:50 -07:00
Andrew Kelley
0812b57466
Merge pull request #10288 from SpexGuy/test-build
Add test executable builds to build.zig
2021-12-07 00:09:33 -08:00
Andrew Kelley
274555be21 stage2: improve handling of the generated file builtin.zig
All Zig code is eligible to `@import("builtin")` which is mapped to a
generated file, build.zig, based on the target and other settings.

Zig invocations which share the same target settings will generate the
same builtin.zig file and thus the path to builtin.zig is in a shared
cache folder, and different projects can sometimes use the same file.

Before this commit, this led to race conditions where multiple
invocations of `zig` would race to write this file. If one process
wanted to *read* the file while the other process *wrote* the file, the
reading process could observe a truncated or partially written
builtin.zig file.

This commit makes the following improvements:
 - limitations:
   - avoid clobbering the inode, mtime in the hot path
   - avoid creating a partially written file
   - builtin.zig needs to be on disk for debug info / stack trace purposes
   - don't mark the task as complete until the file is finished being populated
     (possibly by an external process)
 - strategy:
   - create the `@import("builtin")` `Module.File` during the AstGen
     work, based on generating the contents in memory rather than
     loading from disk.
   - write builtin.zig in a separate task that doesn't have
     to complete until the end of the AstGen work queue so that it
     can be done in parallel with everything else.
   - when writing the file, first stat the file path. If it exists, we are done.
   - otherwise, write the file to a temp file in the same directory and atomically
     rename it into place (clobbering the inode, mtime in the cold path).
 - summary:
   - all limitations respected
   - hot path: one stat() syscall that happens in a worker thread

This required adding a missing function to the standard library:
`std.fs.Dir.statFile`. In this commit, it does open() and then fstat()
which is two syscalls. It should be improved in a future commit to only
make one.

Fixes #9439.
2021-12-06 23:30:18 -08:00
Michael Dusan
a711fcbbfa ci: linux: supply on_master_sucess with VERSION
- move on_master_success to the package step
- add required secret availability for packaging

This replaces a1b79ea5857a52332d9da49d261a7fd04e52a466 .
2021-12-06 23:13:06 -08:00
Lee Cannon
7d1f47313d stage2: fix TracyAllocator bugs 2021-12-06 16:09:12 -08:00
Andrew Kelley
a3d9cd1c1d std.os: handle ETXTBSY from open() 2021-12-06 16:29:39 -07:00
Martin Wickham
5924994045 Fix run() for test_exe steps 2021-12-06 15:57:19 -06:00
Andrew Kelley
ca974de521 stage2: fix double-free when error reading cached ZIR
We already had a `keep_zir` flag. No need to call deinit manually.
2021-12-06 14:29:49 -07:00
Andrew Kelley
003bba47cc libunwind: patch to silence warning
Not sure why this warning is being emitted; let's reexamine it on the
next libunwind upgrade. I triggered it with this:

zig c++ -o hello hello.cpp -target x86_64-windows
2021-12-06 14:29:40 -07:00
Martin Wickham
3771e77667 Add test executable builds to build.zig 2021-12-06 14:55:35 -06:00
Jeremy Fillingim
fffa89700e Fix test label off-by-one error (#10277).
The console test# label [test#/#tests] was being generated inside
refreshWithHeldLock (in lib/std/Progress.zig), using the number of
completed items. This was being incremented by 1 when displayed,
which is not required.
2021-12-06 12:18:41 -08:00
Jakub Konka
933999dad1
Merge pull request #10280 from ziglang/zld-rel-code-path
macho: add preliminary non-prealloc path to the linker
2021-12-06 09:52:09 +01:00
Martin Wickham
2af94e76a3
Add emit path options to emit args in build.zig (#10278) 2021-12-05 19:54:33 -05:00
Jakub Konka
71d19318e7 macho: do not preserve temp symbol names
and do not write out local symbol in MachO's symbol table if global
symbol exists with the same name.
2021-12-06 00:09:51 +01:00
Jakub Konka
3ac973c706 macho: fix incremental codepath for linking objects 2021-12-06 00:00:50 +01:00
Andrew Kelley
a7828c261a
Merge pull request #10276 from tiehuis/musl-trig-reimpl
sin/cos/tan musl reimplementation
2021-12-05 14:49:04 -08:00
Jakub Konka
124e942714 macho: refactor logging and function names 2021-12-05 23:26:30 +01:00
Jakub Konka
397a11c107 macho: sort sections when linking stage1 binary 2021-12-05 22:46:53 +01:00
Jakub Konka
c86f2402d0 macho: don't prealloc sections when stage1 2021-12-05 22:46:46 +01:00
Luuk de Gram
9e03cf9489 wasm: Initial behavior tests succeeding
- Correctly load slice value on stack
- Implement WrapErrorUnionErr and payload
- Implement trunc, fix sliceLen and write undefined
- Implement slice as return type and argument

Note: This also fixes a memory leak for inferred error sets, and for usingnamespace
2021-12-05 12:19:01 -08:00
Marc Tiehuis
b02384e03d std/math: hide internal cos/tan functions 2021-12-06 01:17:01 +13:00
Marc Tiehuis
d28b445329 std/math: fix __rem_pio2 underflow
Error in translated code. Found by fuzzing.
2021-12-06 01:02:09 +13:00
Marc Tiehuis
149444723f std/math: Add test cases for #9901
Closes #9901.
Closes #9902.
2021-12-06 01:02:09 +13:00
Marc Tiehuis
e24398361d std/math: replace golang sin/cos/tan with musl sin/cos/tan 2021-12-06 01:02:09 +13:00