6641 Commits

Author SHA1 Message Date
Michal Ziulek
e06052f201
Added implementation for _fseeki64 and _ftelli64 from mingw-w64 9.0.0 (#9402). (#9766)
* Added fseeki64.c from mingw-w64 9.0.0. This file was missing in Zig distribution. This file contains implementation for _fseeki64 and _ftelli64 functions.
2021-09-15 13:38:00 -04:00
Jakub Konka
25416d8121 macho: when adding extern fn, check if already resolved
This way, we will generate valid relocation info in the codegen.
2021-09-15 16:51:56 +02:00
Andrew Kelley
0395b35cee stage2: implement cmpxchg and improve comptime eval
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime
   and comptime codepaths are implement.
 * Implement Codegen for LLVM backend and C backend.
 * Add LazySrcLoc.node_offset_builtin_call_argX 3...5
 * Sema: rework comptime control flow.
   - `error.ComptimeReturn` is used to signal that a comptime function
     call has returned a result (stored in the Inlining struct).
     `analyzeCall` notices this and handles the result.
   - The ZIR instructions `break_inline`, `block_inline`,
     `condbr_inline` are now redundant and can be deleted. `break`,
     `block`, and `condbr` function equivalently inside a comptime scope.
   - The ZIR instructions `loop` and `repeat` also are modified to
     directly perform comptime control flow inside a comptime scope,
     skipping an unnecessary mechanism for analysis of runtime code.
     This makes Zig perform closer to an interpreter when evaluating
     comptime code.
 * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func
   for adding to the inferred error set. This fixes a bug for
    inlined/comptime function calls.
 * Implement ZIR printing for cmpxchg.
 * stage1: make cmpxchg respect --single-threaded
   - Our LLVM C++ API wrapper failed to expose this boolean flag before.
 * Fix AIR printing for struct fields showing incorrect liveness data.
2021-09-14 21:58:22 -07:00
Jacob G-W
370be12652 plan9 linker: fix for 32 bit 2021-09-14 19:04:09 +03:00
Jakub Konka
85f065a511
Merge pull request #9676 from ziglang/zld-incr
MachO: merges stage1 with self-hosted codepath
2021-09-14 14:20:11 +02:00
Jakub Konka
05763f43b3 macho: disable splitting sections into atoms in release
since we don't actually benefit from it just yet, and getting
it right for release and dead code stripping will require some more
thought put into it.
2021-09-14 10:28:58 +02:00
Andrew Kelley
264acfdf3c stage2: fix incorrect spelling of AtomicOrder 2021-09-13 22:01:40 -07:00
Andrew Kelley
97d69e3352 stage2: add array_to_slice AIR instruction 2021-09-13 21:37:11 -07:00
Andrew Kelley
a9a21c5988 stage2: Type/Value use an enum rather than usize
Makes debugging nicer when you want to look at Type/Value
2021-09-13 21:14:40 -07:00
Andrew Kelley
5529febab0 stage2: implement Value.copy for structs and unions
The stage2_os hack inside `@import("builtin")` is no longer needed.
2021-09-13 20:11:35 -07:00
Jakub Konka
a38b636045 Merge remote-tracking branch 'origin/master' into zld-incr 2021-09-13 23:40:38 +02:00
Jakub Konka
760241ce50 macho: use the cache system to know if need to relink objects
This applies to stage2 where we make use of the cache system to work
out if we need to relink objects when performing incremental updates.
When the process is restarted however, while in principle the idea is
to carry on where we left off by reparsing the prelinked binary from
file, the required machinery is not there yet, and therefore we always
fully relink upon restart.
2021-09-13 23:02:21 +02:00
Jakub Konka
46a10401f0 macho: fix logic for updating exports in incremental codepath 2021-09-13 22:11:20 +02:00
Jakub Konka
4c36da1047 macho: fix incremental compilation 2021-09-13 17:00:36 +02:00
Jakub Konka
1965465ced macho: split resolveSymbols into standalone functions 2021-09-13 13:19:08 +02:00
Andrew Gutekanst
62a6d83da1 Address feedback 2021-09-12 19:34:06 -04:00
Jakub Konka
7aa6064638 macho: insert rpaths upon parsing
Also, insert empty data-in-code lc in populateMissingMetadata fn.
2021-09-11 14:18:09 +02:00
Jakub Konka
054fe96bcd macho: enable tracy in more places within the linker 2021-09-11 12:25:00 +02:00
Andrew Gutekanst
6734271eb0 link: fix invalid file path used when cross-compiling for Windows -> Mac
While investigating hexops/mach#8 with @slimsag,
we found that zld is forming invalid file paths (absolute paths concatenated together),
which hits the unreachable `OBJECT_NAME_INVALID` case in `openDirAccessMaskW`:
0c091feb5a/lib/std/fs.zig (L1522)

This is caused by appending `dir` (which is guaranteed to be absolute) to `root`,
an obviously incorrect operation:
0c091feb5a/src/link/MachO.zig (L494-L499)

Fixes hexops/mach#8

Co-authored-by: Stephen Gutekanst <stephen@hexops.com>
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Signed-off-by: Andrew Gutekanst <andrew.gutekanst@gmail.com>
2021-09-10 23:55:13 -04:00
Jakub Konka
31dcb0dde7 macho: change all occurrences of TextBlock into Atom
and unify allocateAtom with allocateTextBlock.
2021-09-11 02:03:25 +02:00
Jakub Konka
6e0c3950b8 macho: rename blocks to atoms in Object.zig 2021-09-10 22:42:39 +02:00
Jakub Konka
8e5f7f5fe8 macho: write adjacent atoms to in-memory buffer
and then commit the large buffer into file.
2021-09-10 15:37:51 +02:00
Martin Wickham
93c6e31cf1 Fix unmatched close brace in zir dump 2021-09-09 15:34:58 -04:00
Jakub Konka
aaacfc0d0a macho: init process of renaming TextBlock to Atom
Initially, internally within the linker.
2021-09-09 18:32:03 +02:00
Jakub Konka
56fdada577 macho: properly adjust section sizes 2021-09-09 16:55:56 +02:00
Jakub Konka
1efdb137d1 macho: don't allocate atoms when parsing objects 2021-09-09 14:18:28 +02:00
Jakub Konka
23be9cae34 macho: padToIdeal each parsed section size before storing
This way, we should not need to grow at all when allocating atoms
representing objects' sections as atoms.
2021-09-09 01:13:07 +02:00
Jakub Konka
9fb44e8e1f macho: precompute total required size when parsing objects
This way, we can preallocate the necessary sizes for segments and
sections upfront rather than doing it per parsed atom.
2021-09-09 00:25:55 +02:00
Jakub Konka
e00b9d6192 macho: use smaller padding until we have branch islands on arm64
Without branch islands, it is impossible to link self-hosted using
the common linker path.
2021-09-08 13:17:43 +02:00
Jonathan Marler
343547d4a4 finalize windows_sdk paths based on snickler suggestions 2021-09-07 21:49:08 -06:00
Jakub Konka
e229202cb8 macho: store source section address of relocs in context
This is particularly relevant for x86_64 and C++ when relocating
StaticInit sections containing static initializers machine code.
Then, in case of SIGNED_X relocations, it is necessary to have the
full image of the VM address layout of the sections in the object
file as this is how the addend needs to be adjusted for non-extern
relocations.
2021-09-07 23:21:08 +02:00
Jonathan Marler
375619820e changes to build zig-bootstrap aarch64-windows 2021-09-07 14:27:50 -06:00
Martin Wickham
3d5ff91441
Fix libc file to check against compilation target instead of native (#9670) 2021-09-07 15:11:28 -04:00
Andrew Kelley
a48e5af69d
Merge pull request #9684 from FnControlOption/astgen-string-table
AstGen: use string index as key for string table
2021-09-07 14:52:45 -04:00
Jakub Konka
159e55dfd9 macho: fix alignment of atoms which begin the section 2021-09-07 20:37:58 +02:00
Jonathan Marler
fd2c1d8605
Fix building aarch64-windows-gnu by adding missing libc files and compiler_rt functions (#9555)
* fix issue 9519

Added some missing files from mingw

* add missing compiler_rt functions

* finish PR

* add aarch64-windows-gnu to test targets

* add more compiler_rt

* add log2

* add pow

* add modti3
2021-09-07 19:44:21 +03:00
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
Alex Rønne Petersen
eb5e4ac495 link: Recognize -z origin|noexecstack|now|relro linker args. 2021-09-04 12:18:38 +03: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
FnControlOption
5672ee4ed7 AstGen: use string index as key for string table 2021-09-03 06:55:38 -07:00