6663 Commits

Author SHA1 Message Date
Robin Voetter
e77fcf1730 Address Spaces: Implement right address space for slicing 2021-09-20 02:29:04 +02:00
Robin Voetter
538f1bbcb3 Address Spaces: Return proper address space for &x.y 2021-09-20 02:29:03 +02:00
Robin Voetter
497c0d3783 Allow x.y when x is a pointer 2021-09-20 02:29:03 +02:00
Robin Voetter
64c328a717 Address Spaces: Default align, linksection & addrspace for anon decls 2021-09-20 02:29:03 +02:00
Robin Voetter
e182c17187 Address Spaces: Disallow coercing pointers to different address spaces 2021-09-20 02:29:03 +02:00
Robin Voetter
0e6dc64a6f Address Spaces: Return proper address space for &x[y] 2021-09-20 02:29:03 +02:00
Robin Voetter
cd9f6001af Address Spaces: decl_ref, *?T => *T, and *(E!T) -> *T 2021-09-20 02:29:03 +02:00
Robin Voetter
cfbe9a6f61 Address spaces: Forbid addrspace and linksection for local variables 2021-09-20 02:29:03 +02:00
Robin Voetter
805e1bffbd Address Spaces: Sema basics 2021-09-20 02:29:03 +02:00
Robin Voetter
7da9fa6fe2 Address spaces: AstGen
Adds AST generation for address spaces on pointers, function prototypes,
function declarations and variable declarations. In the latter two cases,
declaration properties were already stored more efficiently in a declaration
structure. To accomodate these for address spaces, the bit indicating presence
of a linksection attribute has been extended to include either linksection,
address space, or both.
2021-09-20 02:29:03 +02:00
Robin Voetter
ccc7f9987d Address spaces: addrspace(A) parsing
The grammar for function prototypes, (global) variable declarations, and
pointer types now accepts an optional addrspace(A) modifier.
2021-09-20 02:29:03 +02:00
Andrew Kelley
9fa723ee50 stage2: implement @atomicStore 2021-09-19 15:08:38 -07:00
Ryan Liptak
59f5053bed Update all ensureCapacity calls to the relevant non-deprecated version 2021-09-19 13:52:56 +02:00
Andrew Kelley
b58d8aa05f stage2: improve LLVM backend for enums
* support lowering enum types and constants to LLVM IR
 * fix cmp instruction to support enum operands
2021-09-16 21:57:46 -07:00
Andrew Kelley
091a98f524 stage2: fix global variables with inferred type
Also, when a global variable does have a type, perform coercion on it.
2021-09-16 21:43:01 -07:00
Andrew Kelley
dbe9a5114e stage2: implement @setAlignStack and 128-bit cmpxchg
* test runner is improved to respect `error.SkipZigTest`
 * start code is improved to `@setAlignStack(16)` before calling main()
 * the newly passing behavior test has a workaround for the fact that
   stage2 cannot yet call `std.Target.x86.featureSetHas()` at comptime.
   This is blocking on comptime closures. The workaround is that there
   is a new decl `@import("builtin").stage2_x86_cx16` which is a `bool`.
 * Implement `@setAlignStack`. This language feature should be re-evaluated
   at some point - I'll file an issue for it.
 * LLVM backend: apply/remove the cold attribute and noinline attribute
   where appropriate.
 * LLVM backend: loads and stores are properly annotated with alignment
   and volatile attributes.
 * LLVM backend: allocas are properly annotated with alignment.
 * Type: fix integers reporting wrong alignment for 256-bit integers and
   beyond. Once you get to 16 byte aligned, there is no further
   alignment for larger integers.
2021-09-16 21:03:55 -07:00
Andrew Kelley
d11f42c2b2 zig cc: support -S and -emit-llvm CLI parameters
closes #6425
2021-09-16 16:39:04 -07:00
Žiga Željko
6f85a67987 stage2 Module: fix for 32 bit 2021-09-16 20:55:13 +03:00
Jakub Konka
983d6dcd9e macho: implement object relinking in stage2
* In watch mode, when changing the C source, we will trigger complete
  relinking of objects, dylibs and archives (atoms coming from the
  incremental updates stay put however). This means, we need to undo
  metadata populated when linking in objects, archives and dylibs.
* Remove unused splitting section into atoms bit. This optimisation
  will probably be best rewritten from scratch once self-hosted
  matures so parking the idea for now. Also, for easier management
  of atoms spawned from the Object file, keep the atoms subgraph as
  part of the Object file struct.
* Remove obsolete ref to static initializers in object struct.
* Implement handling of global symbol collision in updateDeclExports.
2021-09-16 12:38:47 +02:00
Andrew Kelley
d5c1d24964 stage2: fix "cmpxchg with ptr" test case
* Sema: fix atomic operand checking to allow pointers.
 * LLVM backend: implement pointer-like optional constants.
 * LLVM backend: fix `is_non_null` and `optional_payload` instructions
   to support pointer-like optionals.
 * Type: introduce `isPtrAtRuntime` method.
 * Type: fix `isPtrLikeOptional` to get the correct answer for allowzero
   pointers and slices.
2021-09-15 19:55:57 -07:00
Andrew Kelley
b67d1810be stage2: implement @atomicRmw and @atomicLoad
* langref: add some more "see also" links for atomics
 * Add the following AIR instructions
   - atomic_load
   - atomic_store_unordered
   - atomic_store_monotonic
   - atomic_store_release
   - atomic_store_seq_cst
   - atomic_rmw
 * Implement those AIR instructions in LLVM and C backends.
 * AstGen: make the `ty` result locations for `@atomicRmw`, `@atomicLoad`,
   and `@atomicStore` be `coerced_ty` to avoid unnecessary ZIR
   instructions when Sema will be doing the coercions redundantly.
 * Sema for `@atomicLoad` and `@atomicRmw` is done, however Sema for
   `@atomicStore` is not yet implemented.
   - comptime eval for `@atomicRmw` is not yet implemented.
 * Sema: flesh out `coerceInMemoryAllowed` a little bit more. It can now
   handle pointers.
2021-09-15 19:00:35 -07:00
Andrew Kelley
19691c0b17 stage2: implement @fence 2021-09-15 12:37:32 -07:00
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