15051 Commits

Author SHA1 Message Date
Jakub Konka
4eff0f4ea1 macho: fix condition for checking available size for an atom 2021-09-01 16:49:16 +02:00
Jakub Konka
7a99cd069a macho: clean up allocating atom logic
Instead of checking for stage1 at every callsite, move the logic
inside `allocateAtom`. This is fine since this logic will disappear
anyhow once I add expanding and shifting segments and sections.
2021-09-01 12:14:29 +02:00
Jakub Konka
d0dc622638 macho: do not reset section's size after allocating atom 2021-09-01 00:06:43 +02:00
Jakub Konka
50db993119 macho: fix allocating sections within segment when parsing objects 2021-08-31 23:05:01 +02:00
Jakub Konka
2831d6e9b8 macho: add first pass at allocating parsed atoms in objects
This commit makes it possible to combine self-hosted with a pre-compiled
C object file, e.g.:

```
zig-out/bin/zig build-exe hello.zig add.o
```

where `add.o` is a pre-compiled C object file.
2021-08-30 15:43:20 +02:00
Jakub Konka
a14e98fcac macho: remove sorting sections and refactor atom parsing in objects 2021-08-27 20:32:11 +02:00
Jakub Konka
ad4a8e7665 macho: keep actual file offset for zerofill sections separately
This way, we will conform to the standard practice of setting the
offset within the section header to the beginning of the file and
we will be able to track the location of the section in the file
for incremental updates.
2021-08-27 13:47:43 +02:00
Jakub Konka
1e65d41a65 macho: merge __common with __bss section 2021-08-27 11:30:02 +02:00
Jakub Konka
705cd64080 macho: preactively add zerofill sections in correct order
The required order on macOS nowadays is:
* __data
* __thread_vars
* __thread_data
* __thread_bss
* __bss
2021-08-27 10:45:56 +02:00
Jakub Konka
8bd0687713 macho: port mechanism for allocating symbols within atoms
such as entire sections represented as a single atom.
2021-08-26 16:16:34 +02:00
Jakub Konka
29df0ca39d Merge remote-tracking branch 'origin/master' into zld-incr 2021-08-26 14:35:34 +02:00
Jakub Konka
570c75cb74 macho: write all atoms in flush so that we can resolve relocs 2021-08-26 14:23:28 +02:00
Jakub Konka
432fb7054d macho: fix stub writing in self-hosted setting 2021-08-26 13:45:28 +02:00
Jakub Konka
d19d3342c2 macho: save lazy binding info as part of the atom 2021-08-26 11:43:11 +02:00
Jakub Konka
c12183b608 macho: fix text atom allocation 2021-08-25 23:00:58 +02:00
Jakub Konka
ee786e5c3c macho: add GOT entries as actual atoms 2021-08-25 17:23:30 +02:00
Jakub Konka
af57ccbe27 macho: generalise free list usage to all sections 2021-08-25 15:11:21 +02:00
Jakub Konka
ea4bd2b879 macho: add routine for creating Got atoms 2021-08-25 10:51:09 +02:00
Andrew Kelley
9c95f38a7c stage1: remove incorrect compile error for var redeclaration
Locals are not allowed to shadow declarations, but declarations are
allowed to shadow each other, as long as there are no ambiguous
references.

closes #678
2021-08-24 22:35:37 -07:00
Andrew Kelley
f1f28af188 fix stage2 test cases expecting wrong line numbers
Previous commit shifted everything down in the start.zig file, and
unfortunately our stage2 test harness depends on absolute line
numbers for a couple tests.
2021-08-24 13:42:31 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Jakub Konka
aee6f14bce macho: use existing rebase mechanism to rebase lazy pointers 2021-08-24 20:16:34 +02:00
Koakuma
dd75302563 Linux/SPARCv9: use C calling convention for restore_rt
This is needed to prevent infinite loop when calling rt_sigreturn.
2021-08-24 14:08:54 -04:00
Koakuma
e3840817d7 Linux/SPARCv9: account for branch delay in freeAndExit() 2021-08-24 14:08:54 -04:00
Jakub Konka
32ce8238a8 macho: rewrite populateLazyBindOffsetsInStubHelper to use atoms
Instead of referencing stub indices since these can now be obtained
in a more generic fashion from the actual linked-list of atoms in
the __stub_helper section.
2021-08-24 15:19:28 +02:00
Takeshi Yoneda
5c79370e9c
wasm: pass --export-dynamic to wasm-ld for WASI reactors. (#9605)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-24 14:03:50 +02:00
Frank Denis
8a37fe2176
BoundedArray: a simple way to represent small data whose max size is known (#9134)
This is a simple structure containing an array and a length, that can be viewed as a slice.

It is useful to pass-by-copy small data whose exact size is known at runtime, but whose maximum size is known at comptime. This greatly simplifies code that otherwise would require an allocator, or reimplementing what this type does.
2021-08-24 13:59:28 +02:00
lucky
8c41a8e761
add scrypt kdf (#9577)
add phc encoding parser
add password hash functions to benchmark
change bcrypt to be consistent with scrypt

Co-authored-by: lucky <>
2021-08-24 13:58:09 +02:00
Jakub Konka
8d30092704 macho: port stub and lazy ptr atoms to stage2 2021-08-24 13:16:43 +02:00
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Frank Denis
9e3ec98937
Don't define valgrind_support on macOS (#9612)
Unfortunately, Valgrind for macOS has been broken for years,
and the Homebrew formula is only for Linux.
2021-08-23 20:06:02 -04:00
Andrew Kelley
bb38931c71 stage1: @intToEnum implicitly does an @intCast
This is a backwards-compatible language change.

Previously, `@intToEnum` coerced its integer operand to the integer tag
type of the destination enum type, often requiring the callsite to
additionally wrap the operand in an `@intCast`. Now, the `@intCast` is
implicit, and any integer operand can be passed to `@intToEnum`.

The same as before, it is illegal behavior to pass any integer which does
not have a corresponding enum tag.
2021-08-23 15:30:57 -07:00
Jakub Konka
91c0552cfc macho: add routine for creating stubs in __stubs section 2021-08-24 00:03:51 +02:00
Jakub Konka
876071b50b macho: fix writing stubs (on x86_64 only) and lazy ptrs 2021-08-23 23:23:00 +02:00
Jakub Konka
9e7b2fb894 macho: add routine for creating lazy pointer for stub 2021-08-23 23:01:14 +02:00
Jakub Konka
799c5bb955 macho: add routine for creating a dynamic stub_helper atom
With this routine, we are now able to freely shift stub_helper
section in memory and in file since the VM addressing is now dynamically
dependent on the positioning of `__stub_helper` preamble and other
sections generated by the linker.
2021-08-23 22:12:04 +02:00
Nguyễn Gia Phong
d5ef5da594
Update comment: s/var/anytype/ (#9611) 2021-08-23 16:22:27 +02:00
William Stein
c465b34d32
Trivial typo "for for" --> "for" (also a few nearby run-on sentence). (#9610) 2021-08-23 08:31:21 +02:00
daurnimator
72c4b80d31
std.os: (p)writev should perform partial writes if iov.len > IOV_MAX
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-08-22 22:22:53 +03:00
Richard Eklycke
62e3d67605 Fix typo introduced in 50a29f7
Now the last argument will be checked as well
2021-08-22 13:29:06 -04:00
Jacob G-W
4ac37eb484 stage2 Air: add struct_field_ptr_index_{0..3}
Since these are very common, it will save memory.
2021-08-21 23:52:55 -04:00
Andrew Kelley
f378b0adce stage2: comptime function with the same args is memoized
* Introduce `memoized_calls` to `Module` which stores all the comptime
   function calls that are cached. It is keyed on the `*Fn` and the
   comptime arguments, but it does not yet properly detect comptime function
   pointers and avoid memoizing in this case. So it will have false
   positives for when a comptime function call mutates data through a
   pointer parameter.
 * Sema: Add a new helper function: `resolveConstMaybeUndefVal`
 * Value: add `enumToInt` method and use it in `zirEnumToInt`. It is
   also used by the hashing function.
 * Value: fix representation of optionals to match error unions.
   Previously it would not handle nested optionals correctly. Now it
   matches the memory layout of error unions and supports nested
   optionals properly. This required changes in all the backends for
   generating optional constants.
 * TypedValue gains `eql` and `hash` methods.
 * Value: Implement hashing for floats, optionals, and enums.
   Additionally, the zig type tag is added to the hash, where it was not
   previously, so that values of differing types will get different
   hashes.
2021-08-21 20:47:42 -07:00
Andrew Kelley
2b40815a22 stage2: fix wrong value for Decl owns_tv
In the case of a comptime function call of a function that returns a
type, resulting in a compiler crash on deinit().
2021-08-21 20:47:42 -07:00
Jakub Konka
ea499203fe macho: incrementally write dyld_private and stub_helper atoms
By incrementally I mean using the incremental linker machinery
and concepts. Currently, lots of repetition but already highlighted
a potential problem with resolving relocations for symbols that
weren't seen yet but wanting to write the atom to file (before
seeing the relevant atoms).
2021-08-21 22:26:02 +02:00
Jonathan Marler
f28868e8fd mingw.zig: fix logic to add crt sources
The current version of code uses isARM to check if we are compiling to any arm target then checks the target bit width to either add the 32-bit sources or 64-bit source.  However, isARM only returns true for 32-bit targets, and isAARCH64 is for the 64-bit targets.

I also replaced the unreachable with a @panic when we receive an unsupported arch because this code is reachable and should turn into an error.
2021-08-21 20:40:07 +03:00
Jakub Konka
d61d85abd2 macho: implement aarch64 prong of createStubHelperAtom 2021-08-21 18:55:15 +02:00
Martin Wickham
27e3216285 Add a flag to build a single-threaded compiler, for debugging 2021-08-21 19:41:28 +03:00
Aydin Mercan
e3e6df17ed linux: Add recent clone/clone3 and missing signalfd flags.
The following flags have been introduced:
- CLONE_PIDFD (>=5.2)
- CLONE_INTO_CGROUP (>=5.7)
- SFD_CLOEXEC and SFD_NONBLOCK (>=2.6.27)
2021-08-21 19:41:00 +03:00
Veikka Tuominen
724995e892 translate-c: avoid repeating string in type when making it mutable 2021-08-21 16:32:09 +03:00
Evan Haas
3b25205833 translate-c: allow string literals to be used as char *
In C the type of string literals is `char *`, so when using them in
a non-const context we have to cast the const away.

Fixes #9126
2021-08-21 16:32:09 +03:00