20767 Commits

Author SHA1 Message Date
Veikka Tuominen
12a2ccfb45 make C ABI tests compile on powerpc 2022-10-22 11:31:41 +03:00
Veikka Tuominen
031c768cc8 add C ABI tests for simd vectors 2022-10-22 11:31:41 +03:00
Jakub Konka
086cee844a macho: refactor dead code stripping conditions
1. If an object file was not compiled with `MH_SUBSECTIONS_VIA_SYMBOLS`
   such a hand-written ASM on x86_64, treat the entire object file as
   not suitable for dead code stripping aka a GC root.
2. If there are non-extern relocs within a section, treat the entire
   section as a root, at least temporarily until we work out the exact
   conditions for marking the atoms live.
2022-10-22 07:59:24 +02:00
Jakub Konka
0cc4d54781 macho: do not skip over SUBTRACTOR reloc when dead stripping 2022-10-22 07:59:24 +02:00
Jakub Konka
f8cbe29a17 macho: fix incorrect lookup of symbols when calculating subtractors 2022-10-22 07:59:24 +02:00
Jakub Konka
93cc5496e1 macho: rewrite movq to leaq when TLV is not external pointer 2022-10-22 07:59:24 +02:00
Jakub Konka
5823f19c5e macho: gracefully handle uninitialized symtabs in objects 2022-10-22 07:59:24 +02:00
Jakub Konka
2c2ff4558f macho: fix handling of lack of subsections and tracking of inner symbols 2022-10-22 07:59:24 +02:00
Jakub Konka
5edb8e0b8f macho: relax SUBTRACTOR assumption it not being a defined global 2022-10-22 07:59:23 +02:00
Jakub Konka
bc1e714de6 macho: revert changes to file descriptors mgmt 2022-10-22 07:59:23 +02:00
Jakub Konka
15f1e6a60c macho: fix silly error where we would incorrectly skip a valid binding 2022-10-22 07:59:23 +02:00
Jakub Konka
c15e03ac79 macho: fix bug in incorrectly splicing nodes in trie 2022-10-22 07:59:23 +02:00
Jakub Konka
5b9eaf2938 macho: do not assume __la_symbol_ptr was created 2022-10-22 07:59:23 +02:00
Jakub Konka
33d1942f27 macho: always create __TEXT segment 2022-10-22 07:59:23 +02:00
Jakub Konka
e70adc7f1a macho: skip parsing __eh_frame until we know how to handle it 2022-10-22 07:59:23 +02:00
Jakub Konka
baceaf65f2 macho: fix incorrectly erroring out with multiple sym definition 2022-10-22 07:59:23 +02:00
Jakub Konka
a32bc0e39c macho: fix 32bit build 2022-10-22 07:59:23 +02:00
Jakub Konka
04a590a171 macho: remove unused nlist flags 2022-10-22 07:59:23 +02:00
Jakub Konka
d57639a308 macho: upstream rewritten traditional linker, zld
kubkon/zld gitrev 5733ed87abe2f07e1330c3232a252e9defec638a
2022-10-22 07:59:23 +02:00
Andrew Kelley
09236d29b7
Merge pull request #12837 from topolarity/err-ret-trace-improvements-1923
stage2: Pop error trace frames for handled errors (#1923)
2022-10-21 20:24:37 -07:00
Andrew Kelley
b9103bd514 CI: drone: skip ReleaseSafe std lib tests that link libc
To save a little bit of time and keep under the 2 hour mark.
2022-10-21 19:28:46 -07:00
Louis Pearson
8d4778b4f9
Support compiling for the android NDK (#13245) 2022-10-21 18:32:56 -04:00
Andrew Kelley
3b2f0c3eee Revert "ci: make directory structure in releases consistent"
This reverts commit 28054d96f0ed5280660811612732cb000f9c09e8.

This caused CI failures.
2022-10-21 13:18:37 -07:00
Cody Tapscott
c36a2c27a5 Change how Block propagates (error return) trace index
Instead of adding 3 fields to every `Block`, this adds just one. The
function-level information is saved in the `Sema` struct instead,
which is created/copied more rarely.
2022-10-21 12:46:46 -07:00
Cody Tapscott
74b9cbd895 stage2: Skip test exposing #13175
This PR (#12873) in combination with this particular test exposed
a pre-existing bug (#13175).

This means that the test for #13038 has regressed
2022-10-21 12:40:33 -07:00
Cody Tapscott
a4523a2d4a builtin.zig: Do not overwrite error frames when trace full
Previously, we'd overwrite the errors in a circular buffer. Now that
error return traces are intended to follow a stack discipline, we no
longer have to support the index rolling over. By treating the trace
like a saturating stack, any pop/restore code still behaves correctly
past-the-end of the trace.

As a bonus, this adds a small blurb to let the user know when the trace
saturated and x number of frames were dropped.
2022-10-21 12:40:33 -07:00
Cody Tapscott
d060cbbec7 stage2: Keep error return traces alive when storing to const
This change extends the "lifetime" of the error return trace associated
with an error to continue throughout the block of a `const` variable
that it is assigned to.

This is necessary to support patterns like this one in test_runner.zig:
```zig
const result = foo();
if (result) |_| {
    // ... success logic
} else |err| {
    // `foo()` should be included in the error trace here
    return error.TestFailed;
}
```

To make this happen, the majority of the error return trace popping logic
needed to move into Sema, since `const x = foo();` cannot be examined
syntactically to determine whether it modifies the error return trace. We
also have to make sure not to delete pertinent block information before it
makes it to Sema, so that Sema can pop/restore around blocks correctly.

* Why do this only for `const` and not `var`? *

There is room to relax things for `var`, but only a little bit. We could
do the same thing we do for const and keep the error trace alive for the
remainder of the block where the *assignment* happens. Any wider scope
would violate the stack discipline for traces, so it's not viable.

In the end, I decided the most consistent behavior for the user is just
to kill all error return traces assigned to a mutable `var`.
2022-10-21 12:40:29 -07:00
Cody Tapscott
597ead5318 stage2: Fix usage of getError()
Despite the old doc-comment, this function cannot be valid for all types
since it operates with only a value and Error (Union) types have
overlapping Value representations with other Types.
2022-10-21 11:22:49 -07:00
Cody Tapscott
b529d8e48f stage2: Propagate error return trace into fn call
This change extends the "lifetime" of the error return trace associated
with an error to include the duration of a function call it is passed
to.

This means that if a function returns an error, its return trace will
include the error return trace for any error inputs. This is needed to
support `testing.expectError` and similar functions.

If a function returns a non-error, we have to clean up any error return
traces created by error-able call arguments.
2022-10-21 11:22:49 -07:00
Cody Tapscott
77720e30aa Re-factor: Change AstGen.ResultLoc to be a struct
This re-factor is intended to make it easier to track what kind of
operator/expression consumes a result location, without overloading the
ResultLoc union for this purpose.

This is used in the following commit to keep track of initializer
expressions of `const` variables to avoid popping error traces
pre-maturely. Hopefully this will also be useful for implementing
RLS temporaries in the future.
2022-10-21 11:22:46 -07:00
Cody Tapscott
724d753638 stage2: Add .save_err_return_trace_index AIR op
This is encoded as a primitive AIR instruction to resolve one corner
case: A function may include a `catch { ... }` or `else |err| { ... }`
block but not call any errorable fn. In that case, there is no error
return trace to save the index of and codegen needs to avoid
interacting with the non-existing error trace.

By using a primitive AIR op, we can depend on Liveness to mark this
unused in this corner case.
2022-10-21 10:44:20 -07:00
Cody Tapscott
3007fdde45 stage2: Pop error trace when storing error to var/const
In order to enforce a strict stack discipline for error return traces,
we cannot track error return traces that are stored in variables:

  ```zig
  const x = errorable(); // errorable()'s error return trace is killed here

  // v-- error trace starts here instead
  return x catch error.UnknownError;
  ```

In order to propagate error return traces, function calls need to be passed
directly to an error-handling expression (`if`, `catch`, `try` or `return`):

  ```zig
  // When passed directly to `catch`, the return trace is propagated
  return errorable() catch error.UnknownError;

  // Using a break also works
  return blk: {
      // code here
      break :blk errorable();
  } catch error.UnknownError;
  ```

Why do we need this restriction? Without it, multiple errors can co-exist
with their own error traces. Handling that situation correctly means either:
  a. Dynamically allocating trace memory and tracking lifetimes, OR
  b. Allowing the production of one error to interfere with the trace of another
     (which is the current status quo)

This is piece (3/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:20 -07:00
Cody Tapscott
0c3a50fe1c stage2: Do not pop error trace if result is an error
This allows for errors to be "re-thrown" by yielding any error as the
result of a catch block. For example:

```zig
fn errorable() !void {
    return error.FallingOutOfPlane;
}

fn foo(have_parachute: bool) !void {
    return errorable() catch |err| b: {
        if (have_parachute) {
            // error trace will include the call to errorable()
            break :b error.NoParachute;
        } else {
            return;
        }
    };
}

pub fn main() !void {
    // Anything that returns a non-error does not pollute the error trace.
    try foo(true);

    // This error trace will still include errorable(), whose error was "re-thrown" by foo()
    try foo(false);
}
```

This is piece (2/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:19 -07:00
Cody Tapscott
eda3eb1561 stage2: "Pop" error trace for break/return within catch
This implement trace "popping" for correctly handled errors within
`catch { ... }` and `else { ... }` blocks.

When breaking from these blocks with any non-error, we pop the error
trace frames corresponding to the operand. When breaking with an error,
we preserve the frames so that error traces "chain" together as usual.

```zig
fn foo(cond1: bool, cond2: bool) !void {
    bar() catch {
    	if (cond1) {
	    // If baz() result is a non-error, pop the error trace frames from bar()
	    // If baz() result is an error, leave the bar() frames on the error trace
            return baz();
	} else if (cond2) {
	    // If we break/return an error, then leave the error frames from bar() on the error trace
	    return error.Foo;
	}
    };

    // An error returned from here does not include bar()'s error frames in the trace
    return error.Bar;
}
```

Notice that if foo() does not return an error it, it leaves no extra
frames on the error trace.

This is piece (1/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:43:42 -07:00
Veikka Tuominen
5316a00a18 stage2: properly reset error return trace index 2022-10-21 10:43:42 -07:00
Veikka Tuominen
3981250b84 aarch64 C ABI: return union instead of array of two enums
The result is much cleaner and the second element was unused most of the time.
2022-10-21 20:30:45 +03:00
Eric Joldasov
28054d96f0 ci: make directory structure in releases consistent 2022-10-21 12:51:04 -04:00
Veikka Tuominen
9ae78a5890 stage2: implement ARM C ABI
Six new passing tests and the previously incorrectly passing
complex tests are now skipped.
2022-10-21 18:07:11 +03:00
Veikka Tuominen
7622078127 aarc64 C ABI: fix handling of packed structs and unions
* Packed unions were not handled at all previously.
* Packed unions and structs are integers so their floats should not be counted.
2022-10-21 17:51:54 +03:00
David Gonzalez Martin
680d3cd1fc UEFI: Querying memory map size with no allocation
This makes possible to query the memory map size from EFI firmware
without making any allocation beforehand. This makes possible to be
precise about the size of the allocation which will own a copy of
the memory map from the UEFI application.
2022-10-21 12:17:41 +02:00
Veikka Tuominen
972c39e2c0
Merge pull request #13219 from Vexu/stage2-fixes
Stage2 bug fixes
2022-10-21 12:11:49 +02:00
Joachim Schmidt
41575b1f55
Merge pull request #13236 from joachimschmidt557/stage2-aarch64
stage2 AArch64: move to new allocRegs mechanism
2022-10-21 09:17:56 +02:00
Andrew Kelley
0f00766661 Revert "add std.debug.todo"
This reverts commit 80ac022c4667e1995ccdf70fff90e5af26b6eb97.

I changed my mind on this one, sorry. I don't think this belongs in the
standard library.
2022-10-20 18:34:40 -07:00
Veikka Tuominen
2609e33ab0 make C ABI tests compile on arm, mips and riscv
x86_64      24/25
x86         15/25
aarch64     25/25 - all
arm         18/25
mips        10/24
riscv64     13/25
wasm32      25/25 - all
2022-10-20 20:11:12 +03:00
Veikka Tuominen
646d927c79 stage2: fix handling of aarch64 C ABI float array like structs
Closes #11702
Closes #13125
2022-10-20 20:11:12 +03:00
Veikka Tuominen
07b6173cb8 delete failing recursive test
Don't forget to add these back when solving #12973
2022-10-20 20:11:12 +03:00
Veikka Tuominen
7e946bc790 make C ABI tests compile on i386 2022-10-20 20:11:12 +03:00
Veikka Tuominen
51491186cb stage2: fix x86_64 C ABI of struct with array member
Closes #12185
2022-10-20 20:11:12 +03:00
Veikka Tuominen
ce95cc170b Value: handle runtime_int in hashPtr
Closes #12702
2022-10-20 20:11:12 +03:00
Veikka Tuominen
9a52abf3b4 Sema: add missing calls to wip_captures.finalize
Closes #13171
2022-10-20 20:11:12 +03:00