4746 Commits

Author SHA1 Message Date
Evan Haas
ccdb81fb31 Improve handling of C compiler intrinsics in translate-c
C compiler intrinsics can only appear as part of a function call. When called
they are implicitly cast to a function pointer; treat this as a non-null
pointer so that it emits as a regular Zig function call.

Put `pub usingnamespace @import("std").c.builtins;` at the top of translated
C files so that they will have access to builtin functions defined there.

Fixes #6707
2020-12-22 23:59:30 +02:00
Jakub Konka
43dbe86226
Merge pull request #7516 from kubkon/macho-better-space-alloc
macho: space preallocation, and various cleanups and fixes
2020-12-22 14:23:55 +01:00
Jakub Konka
34663abc90 macho: pad out LINKEDIT upto specified filesize 2020-12-22 10:57:58 +01:00
Jakub Konka
f106a46fd2 macho: enable binding and lazy binding info writes 2020-12-21 23:16:00 +01:00
Jakub Konka
3f21f9155f macho: write only bits that changed
Refactor use of `log` to not include an additional newline char.
2020-12-21 19:59:40 +01:00
Jakub Konka
de5421a0a6 macho: deduplicate symbol table relocation codepath 2020-12-21 18:31:26 +01:00
Jakub Konka
a1b3606f0e macho: dynamically preallocate space for LINKEDIT sections as well 2020-12-21 17:03:55 +01:00
Vexu
286077fec8 stage1: add missing error check on inferred struct field ptr 2020-12-21 12:40:51 +02:00
Andrew Kelley
1d94a68936 add an option to compile zig in single-threaded mode
And enable it for Drone CI. I hate to do this, but I need to make
progress on other fronts.
2020-12-20 15:37:58 -07:00
Andrew Kelley
10d30838d1 update WaitGroup to yet another version 2020-12-20 15:08:59 -07:00
Andrew Kelley
4e621d4260 workaround for std lib AutoResetEvent bug 2020-12-20 15:08:59 -07:00
Andrew Kelley
e00b6db2aa update stage2 test harness to new std.Progress API 2020-12-20 15:08:59 -07:00
Andrew Kelley
aa6ef10cc6 std.Progress: make the API thread-safe
We generally get away with atomic primitives, however a lock is required
around the refresh function since it traverses the Node graph, and we
need to be sure no references to Nodes remain after end() is called.
2020-12-20 15:08:59 -07:00
Andrew Kelley
b2f8631a3c ThreadPool: delete dead code
If this errdefer did get run it would constitute a race condition. So I
deleted the dead code for clarity.
2020-12-20 15:08:59 -07:00
Andrew Kelley
32fd637e57 stage2: replace WaitGroup with a trivially auditable one 2020-12-20 15:08:59 -07:00
Andrew Kelley
0d1cd0d482 use kprotty's ThreadPool implementation (v5) 2020-12-20 15:08:59 -07:00
Andrew Kelley
01d33855c7 stage2: protect mutable state from data races in updateCObject 2020-12-20 15:08:59 -07:00
LemonBoy
84549b4267 stage1: Fix for generic fn monomorphization
Don't use the instantiation argument types to build the function
parameter array.

f416535768fc30195cad6cd481f73fd1e80082aa worked around the problem, this
commit solves it.
2020-12-19 19:45:48 -05:00
Jakub Konka
3f7dbde92a macho: bring back allocatedSize function 2020-12-19 23:51:39 +01:00
Jakub Konka
6712575e04 macho: preallocate space for linkedit hidden sections; 2020-12-19 23:37:21 +01:00
Jakub Konka
ca1d03fe77 macho: fix findFreeSpace start value 2020-12-19 19:44:13 +01:00
Jakub Konka
c89f4781bd macho: add missing dirty markers 2020-12-19 12:19:20 +01:00
Jakub Konka
f32681033d macho: auto-coerce to slice 2020-12-19 12:19:10 +01:00
Jakub Konka
99578e828b macho: move findFreeSpace back to MachO struct
However, adding a twist where `findFreeSpace` accepts a `SegmentCommand`
as argument meaning we want to look for free space specifically within
that segment and nowhere else.
2020-12-19 12:19:00 +01:00
Jakub Konka
6a021d845a macho: find free space even for __text section 2020-12-19 12:18:49 +01:00
Jakub Konka
f33b644c4f macho: redo how we allocate within a segment
Firstly, we preallocate segments offset and sizes, and then
when adding sections, we find the free space within each segment.
Currently, this applies to any segment that is not __LINKEDIT
segment since this requires special treatment.
2020-12-19 12:18:35 +01:00
Jakub Konka
b090451646
Merge pull request #7318 from kubkon/cc-macho
stage1: cross compile to x86_64 and arm64 macOS from anywhere with LLVM
2020-12-19 12:13:03 +01:00
Jakub Konka
3f81ddb735 macho: address review comments 2020-12-19 09:59:38 +01:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
Jakub Konka
b42ef0e6ea macho: refactor calculating LEB128 sizes 2020-12-17 10:04:53 +01:00
Jakub Konka
3e9e79378d macho: deduplicate libc headers between macos arch 2020-12-17 10:04:53 +01:00
Jakub Konka
2d5d661703 macho: no need to parse symbol/string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
ae535111a4 macho: cleanup (lazy) binding info tables 2020-12-17 10:04:53 +01:00
Jakub Konka
5e913c9c2c macho: move (lazy)binding tables into imports module 2020-12-17 10:04:53 +01:00
Jakub Konka
46b2a08d06 macho: parse binding info into a table of entries 2020-12-17 10:04:53 +01:00
Jakub Konka
77e545892e macho: do not error out on unknown load commands
Also, do not try to fixup missing libSystem for dylibs.
2020-12-17 10:04:53 +01:00
Jakub Konka
b099fdff93 macho: parse symbol and string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
f5a0b9315b macho: calculate next available dylib ordinal 2020-12-17 10:04:53 +01:00
Jakub Konka
cc2592969d macho: clean up formatting 2020-12-17 10:04:53 +01:00
Jakub Konka
3971522fee macos: add unfiltered aarch64 libc headers 2020-12-17 10:04:53 +01:00
Jakub Konka
2e7883c597 lld+macho: lld xcomp to x86_64 macos now works 2020-12-17 10:04:53 +01:00
Jakub Konka
eb528a9cbc lld+macho: add missing LC_LOAD_DYLIB cmd 2020-12-17 10:04:53 +01:00
Andrew Kelley
6dfe9cc83e zig cc: default to a.exe on windows
This matches Clang. Thanks to Abner Coimbre for pointing this out.
2020-12-16 21:37:15 -07:00
Andrew Kelley
8975fa5b38 stage2: add test_evented_io to cache hash 2020-12-16 19:22:48 -07:00
Veikka Tuominen
d3a57b96a9 translate-c: detect parenthesized string literals 2020-12-16 12:13:23 +02:00
Andrew Kelley
b3c1ced2c3
Merge pull request #7431 from LemonBoy/fix-7426
stage1: Fix crash in can_mutate_comptime_var_state
2020-12-15 15:07:49 -05:00
LemonBoy
5f7352b5b5 stage2: Add -include libc-symbols.h when building crtn.S
This -include is added for nearly every file in glibc's makefiles.
2020-12-15 14:53:46 -05:00
Sébastien Marie
96e3222796 openbsd: crt0.o file is different when build static or dynamic mode
it is a first step for support static *and* dynamic mode for openbsd
2020-12-15 14:53:23 -05:00
Sebastien Marie
7cd6c25c8f
openbsd: link with required system libraries (#7380)
* openbsd: use -lpthread when linking

and while compiling zig stage2, use c++ and c++abi too
2020-12-15 14:45:48 -05:00
LemonBoy
8a2ab60fca stage1: Don't skip steps when analyzing union types
Don't cut any corner and properly run the type trough every single step
even though it has no fields (or, better, the sum of the size of all its
fields is zero).

Fix the logic to consider an explicit non-zero-sized tag enough to treat
the type as sized.

Closes #7451
2020-12-15 14:40:21 -05:00