16462 Commits

Author SHA1 Message Date
Jakub Konka
4d4bbd7624 stage2: refactor handling of immediates in x86_64 backend
Fixes issues with incorrect operand sizes in a handful of cases
and allows for usage of differently sized integers in Zig sources.
2022-01-15 18:28:39 +01:00
Andrew Kelley
a5c7742ba6 stage2: fix Decl garbage collection not marking enough
It is the job of codegen backends to mark Decls that are referenced as
alive so that the frontend does not sweep them with the garbage. This
commit unifies the code between the backends with an added method on
Decl.

The implementation is more complete than before, switching on the Decl
val tag and recursing into sub-values.

As a result, two more array tests are passing.
2022-01-15 00:17:25 -07:00
Andrew Kelley
41f3799bf0 Sema: fix array_init with runtime element
Previously it emitted an invalid AIR encoding.
2022-01-14 23:08:11 -07:00
Jakub Konka
ba0f72363a
Merge pull request #10576 from schmee/macos-resolve-ip
Use libc if_nametoindex for macOS when parsing IPs
2022-01-15 00:47:12 +01:00
Jakub Konka
b3471ef300 macho: code signature needs to be 16 bytes aligned 2022-01-14 22:32:33 +01:00
Andrew Kelley
1e481dfef5
Merge pull request #10587 from xxxbxxx/master
restore compatibility with glibc<=2.33 for global initializers
2022-01-14 14:40:54 -05:00
Andrew Kelley
3ed0741718 glibc: clean up build logic
also use the common naming convention for glibc versions ("2.33" rather
than "2-33").

I also verified that these files are exactly identical to the previous
files from before zig updated to glibc 2.34.
2022-01-14 12:39:06 -07:00
xavier
3f52132a8f tests: include global initializers in c++ compiler test 2022-01-14 11:48:38 -07:00
xavier
f1b14b91f1 glibc: restore compatibility with glibc<=2.33 for global initializers
__libc_start_main() from glibc.2.33.so or older needs to have a __libc_csu_init function callback parameter.

glibc-2.34 on the other hand has a different __libc_start_main() that does not use it,
and the start.S file from glibc-2.34 no longer construct the init function and pass null when calling __libc_start_main.

So, When targetting an older glibc, use the start.s files as they were in glibc-2.33 and construct the __libc_csu_init function.

fixes #10386 #10512
2022-01-14 11:48:37 -07:00
Marc Tiehuis
a64989ee70 stage1: fix bigint_init_bigfloat for single-limb negative floats
Fixes #10592.
2022-01-14 13:29:58 -05:00
John Schmidt
c992164dc7 Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
Andrew Kelley
ec58ddf46c
Merge pull request #10582 from ziglang/stage2-arrays
stage2: detection of comptime array literals
2022-01-14 00:23:27 -05:00
bryfry
0d45c72d3e Use allocPrintZ to avoid needing assumeSentinel 2022-01-14 00:17:38 -05:00
Andrew Kelley
336d0c97fe stage2: detection of comptime array literals
Introduce `validate_array_init_comptime`, similar to
`validate_struct_init_comptime` introduced in
713d2a9b3883942491b40738245232680877cc66.

`zirValidateArrayInit` is improved to detect comptime array literals and
emit AIR accordingly. This code is very similar to the changes
introduced in that same commit for `zirValidateStructInit`.

The C backend needed some improvements to continue passing the same set
of tests:
 * `resolveInst` for arrays now will add a local `static const` with the
   array value and so then `elem_val` instructions reference that local.
   It memoizes accesses using `value_map`, which is changed to use
   `Air.Inst.Ref` as the key rather than `Air.Inst.Index`.
 * This required a mechanism for writing to a "header" which is lines
   that appear at the beginning of a function body, before everything
   else.
 * dbg_stmt output comments rather than `#line` directives.
   TODO comment reproduced here:

We need to re-evaluate whether to emit these or not. If we naively emit
these directives, the output file will report bogus line numbers because
every newline after the #line directive adds one to the line.
We also don't print the filename yet, so the output is strictly unhelpful.
If we wanted to go this route, we would need to go all the way and not output
newlines until the next dbg_stmt occurs.
Perhaps an additional compilation option is in order?

`Value.elemValue` is improved to support `elem_ptr` values.
2022-01-13 22:13:44 -07:00
Andrew Kelley
b019a19b55 Sema: comptime loads and stores for elem_ptr
The index is checked against actual array lengths, and now handles
coerced or casted pointers to single items.
2022-01-13 22:13:44 -07:00
Andrew Kelley
75b6637d60
Merge pull request #10584 from ziglang/macho-rustc-fixes
zld: a couple of fixes which result in better rustc support
2022-01-13 22:09:42 -05:00
joachimschmidt557
7e76aab98a stage2 AArch64: split ldr/str into {ldr,str}_register and _immediate 2022-01-14 00:46:07 +01:00
Jakub Konka
e945619728 macho: remove todo from getMatchingSectionDecl 2022-01-13 21:15:17 +01:00
Jakub Konka
5cde5f947f Introduce LinkObject with must_link field 2022-01-13 20:02:11 +01:00
Jakub Konka
a8564df9ed zld: parse addend from BRANCH reloc on x86_64
As usual, MachO, full of surprises!
2022-01-13 20:02:11 +01:00
Jakub Konka
16c55b15cb zld: support -Wl,-force_load=archive_path flag
This actually enables using `zig cc` as a linker for `cargo test`
with `serde_derive`.
2022-01-13 20:02:11 +01:00
Jakub Konka
f9f792ab70 zld: fix num nlist calc when there's no dynsymtab
Handle `__DATA,.rustc` section containing `rustc` metadata - this
is required to get crates like `serde_derive` link properly.
Note to self: this special section has to be copied __verbatim__
from the relocatable object file - this includes preserving its size
even though unpadded according the section's required alignment.
2022-01-13 20:02:11 +01:00
Andrew Kelley
c5ee73f65b stage2: fix build on 32-bit ISAs
Fixes regression introduced in 93b854eb745ab3294054ae71150fe60f134f4d10.
2022-01-13 10:42:38 -07:00
Andrew Kelley
9bf2bda683 compiler_rt: one less exception for stage2 2022-01-13 00:32:48 -07:00
Andrew Kelley
93b854eb74 stage2: implement @ctz and @clz including SIMD
AIR:
 * `array_elem_val` is now allowed to be used with a vector as the array
   type.
 * New instructions: splat, vector_init

AstGen:
 * The splat ZIR instruction uses coerced_ty for the ResultLoc, avoiding
   an unnecessary `as` instruction, since the coercion will be performed
   in Sema.
 * Builtins that accept vectors now ignore the type parameter. Comment
   from this commit reproduced here:

   The accepted proposal #6835 tells us to remove the type parameter from
   these builtins. To stay source-compatible with stage1, we still observe
   the parameter here, but we do not encode it into the ZIR. To implement
   this proposal in stage2, only AstGen code will need to be changed.

Sema:
 * `clz` and `ctz` ZIR instructions are now handled by the same function
   which accept AIR tag and comptime eval function pointer to
   differentiate.
 * `@typeInfo` for vectors is implemented.
 * `@splat` is implemented. It takes advantage of `Value.Tag.repeated` 😎
 * `elemValue` is implemented for vectors, when the index is a scalar.
   Handling a vector index is still TODO.
 * Element-wise coercion is implemented for vectors. It could probably
   be optimized a bit, but it is at least complete & correct.
 * `Type.intInfo` supports vectors, returning int info for the element.
 * `Value.ctz` initial implementation. Needs work.
 * `Value.eql` is implemented for arrays and vectors.

LLVM backend:
 * Implement vector support when lowering `array_elem_val`.
 * Implement vector support when lowering `ctz` and `clz`.
 * Implement `splat` and `vector_init`.
2022-01-12 23:53:26 -07:00
John Schmidt
66fe5bb0d8 Use libc if_nametoindex if available when parsing IPs
Fixes https://github.com/ziglang/zig/issues/10521 and makes a couple of
additional tests pass when linking libc.
2022-01-12 19:32:46 +01:00
riverbl
c4681b4889 translate-c: Fix macro define of float constant using scientific notation
Fixes compiler attempting to use null value when translating macro define of float constant using scientific notation with no decimal point
2022-01-12 13:25:50 -05:00
Jimmi Holst Christensen
a5ac138ae2 Allow BoundArray to be default initialized 2022-01-12 13:17:01 -05:00
Jimmi Holst Christensen
349a7cc272 Make prominent_compile_errors also work for test steps 2022-01-12 00:13:30 -05:00
Andrew Kelley
1a7c47d966
Merge pull request #10572 from Luukdegram/wasm-linker-stack
Stage2: wasm-linker - Place stack at the beginning of the linear memory
2022-01-11 19:41:18 -05:00
Luuk de Gram
975049e96e
wasm-ld: Append --stack-first by default
By placing the stack at the start of the memory section, we prevent the runtime
from silently overwriting the global declarations and instead trap.

We do however, allow users to overwrite this behavior by setting the global-base,
which puts the stack at the end of the memory section and the static data at the base that was specified.
The reason a user would want to do this, is when they are sure the stack will not overflow and they want
to decrease the binary size as the offsets to the static memory are generally smaller.
(Having the stack in front, means that accessing the memory after the stack has a bigger offset when loading/storing from memory).
2022-01-11 20:35:44 +01:00
Luuk de Gram
f767f8e3dc
wasm: Place the stack at the start of memory 2022-01-11 20:21:22 +01:00
afranchuk
7c4c49ff07
Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538)
* Fix FUTEX usage in std.Thread.Condition - It was using an old name.
2022-01-11 13:04:24 -05:00
Andrew Kelley
64363b10f5
Merge pull request #10566 from fifty-six/master
std.os.uefi improvements/fixes
2022-01-11 13:02:28 -05:00
Andrew Kelley
3d89ff5130 std.fs.path: revert recent public API change
41fd343508880ffdfbc83c7b053237da09199f02 made a breaking change to the
public API; this commit reverts the API changes but keeps the
improved logic.
2022-01-11 11:00:19 -07:00
fifty-six
b65a884169 std/os/uefi: Add pool_allocator and raw_pool_allocator 2022-01-11 10:49:40 -07:00
fifty-six
c78a108d10 std/os/uefi: Add create_file_device_path
This allows users to add file paths to device paths, which is often used
in methods like `boot_services.loadImage` and `boot_services.startImage`,
which take a device path with an additional file path appended to locate
the image.
2022-01-11 10:49:40 -07:00
fifty-six
73e4571b4c std/os/uefi: Add methods next() and size() to DevicePathProtocol
These are used for more easily dealing with a series of Device Path
nodes.
2022-01-11 10:49:40 -07:00
fifty-six
608fceffc4 std/os/uefi: Add FileSystemInfo 2022-01-11 10:49:40 -07:00
fifty-six
b6e1613e58 std/os/uefi: Move FileInfo guid from FileProtocol to FileInfo
The GUID on FileProtocol was for EFI_FILE_INFO, FileProtocol itself doesn't
have a GUID, there are only those for the requested information types.
2022-01-11 10:49:40 -07:00
fifty-six
41fd343508 std: fix path joining on UEFI
UEFI uses `\` for paths exclusively. This changes std.fs.path to use `\`
for UEFI path joining. Also adds a few tests regarding it, specifically
in making sure double-separators do not result from path joining, as the
UEFI spec says to convert any that result from joining into single
separators (UEFI Spec Version 2.7, pg. 448).
2022-01-11 10:49:40 -07:00
Evan Haas
f4b3f1d602 translate-c: Handle typedef'ed void return type for functions.
Fixes #10356
2022-01-11 12:42:23 -05:00
Jakub Konka
6d9c02a54f
zig cc: integration with sysroot arg (#10568)
Prior to this change, even if the use specified the sysroot on the
compiler line like so

```
zig cc --sysroot=/path/to/sdk
```

it would only be used as a prefix to include paths and not as a prefix
for `zig ld` linker.
2022-01-11 12:41:26 -05:00
Jakub Konka
48731ccea9 Merge branch 'Luukdegram-linker-eport-symbols' 2022-01-11 13:34:43 +01:00
Jakub Konka
014e55e761 dupe sym name from stage1 before passing to stage2 2022-01-11 13:33:53 +01:00
Jakub Konka
a615425b51 Merge branch 'linker-eport-symbols' of github.com:Luukdegram/zig into Luukdegram-linker-eport-symbols 2022-01-11 11:30:53 +01:00
djg
4731a6e5d5
std: hash_map: optimize isFree/isTombstone (#10562)
- Add an `Metadata.isFree` helper method.
- Implement `Metadata.isTombstone` and `Metadata.isFree` with `@bitCast` then comparing to a constant. I assume `@bitCast`-then-compare is faster than the old method because it only involves one comparison, and doesn't require bitmasking.
- Summary of benchmarked changes (`gotta-go-fast`, run locally, compared to master):
  - 3/4 of the hash map benchmarks used ~10% fewer cycles
  - The last one (project Euler) shows 4% fewer cycles.
2022-01-10 23:54:45 -05:00
Jakub Konka
ada8e17137
Merge pull request #10565 from Luukdegram/wasm-cast
Stage2: wasm - Implement optional equality, casts and more
2022-01-10 23:43:06 +01:00
Jakub Konka
97c6d4fb3e Build fs/filesystem libcxx module when targeting GNU Win 2022-01-10 23:40:15 +01:00
Luuk de Gram
bf46aee878
wasm: Basic 128bit integer support
This implements storing, loading and comparing 128bit integers.
TODO: Make all >64 bit integers make a call to compiler-rt for binary operations.
2022-01-10 21:03:37 +01:00