15071 Commits

Author SHA1 Message Date
Jakub Konka
a2279e7e20 macho: fix commands.zig tests 2021-09-07 12:23:26 +02:00
Jakub Konka
c35f668932 macho: update max section alignment when inserting atoms 2021-09-07 10:07:09 +02:00
Jakub Konka
6836cc473c macho: make sure that parsed bss atoms are zero-filled 2021-09-06 18:30:40 +02:00
Jakub Konka
81e5320973 macho: set and reset file offset to zerofill sections in flush
This way, there's no need to special the set/reset behaviour at
every stage of updating sections/atoms.
2021-09-06 17:43:24 +02:00
Jakub Konka
29d2e19c3e macho: allocate sections one after the other and grow if needed 2021-09-06 17:31:20 +02:00
Jakub Konka
2914ea9e33 macho: require atom padding for machine code only 2021-09-06 11:17:20 +02:00
Jakub Konka
5e64d9745b macho: fix noninclusion of data-in-code
Also, calculate non-extern, section offset based addends for SIGNED
and UNSIGNED relocations on x86_64 upfront as an offset wrt to the
target symbol representing position of the section/atom within the
final artifact.
2021-09-06 10:38:51 +02:00
Jakub Konka
61dca19107 macho: encaps logic for extract sect offset into fn 2021-09-05 23:30:06 +02:00
Jakub Konka
ea8808f87b macho: add logic for segment expansion 2021-09-05 11:15:48 +02:00
Jakub Konka
d92b5416e8 macho: add a small routine to update section ordinals at the end
The actual ordinals may change when adding new sections to the segments.
2021-09-05 00:19:45 +02:00
Jakub Konka
7e87f93e06 macho: unfortunately, LINKEDIT commands NEED to be in order
Otherwise, Apple's tooling goes mental and reports that the executable
is malformed/fails strict validation. We absolutely have to get it
right to support tools such `codesign` which are required to
successfully launch an app on an iOS device for instance. When Zig
matures enough so that we can ditch any Apple tooling and still be
able to successfully codesign for iOS and other, we can revisit this
area. Until then however, we are stuck in having to rewrite the LINKEDIT
segment at every update run of the self-hosted.

FYI, the strict layout for the MachO binary apparently is (please,
read this with a pinch of salt as this is inferred by me):
* __TEXT segment
* __DATA_CONST segment
* __DATA segment
* __LINKEDIT segment
* dyld info (rebase, bind, weak bind, lazy bind, export)
* symbol table
* dynamic symbol table
* string table
* code signature (if expected)
2021-09-04 22:59:16 +02:00
Jakub Konka
80e1c244b6 macho: dyld info subsections need to follow in strict order
MachO, why are doing this to me?
2021-09-03 17:12:39 +02:00
Jakub Konka
1d2199b71c macho: dirty export trie when adding globals
Similarly, dirty rebase info when adding a GOT atom.
2021-09-03 13:41:28 +02:00
Jakub Konka
7536a2f8cf macho: minor fixes to allow the linker to output malformed stage1 2021-09-03 11:47:58 +02:00
Jakub Konka
a783f3a369 macho: remove obsolete mentions of stage1 2021-09-03 00:25:47 +02:00
Jakub Konka
4b07da7090 macho: remove all Zld codepaths 2021-09-03 00:21:45 +02:00
Jakub Konka
5af13f35f9 macho: implement basic section movement and reallocation 2021-09-02 18:19:07 +02:00
Jakub Konka
4741c04254 macho: better spec for sections which don't require padding 2021-09-02 00:44:33 +02:00
Jakub Konka
9dbad2d188 macho: fix calculating file offset for atom when allocating 2021-09-01 23:44:01 +02:00
Jakub Konka
17066cc12e macho: minor refactor of const namings 2021-09-01 23:26:24 +02:00
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