10229 Commits

Author SHA1 Message Date
InKryption
bc72ae5e4e Sema: Prevent coercion from tuple pointer to mutable slice.
Also fix some stdlib code affected by this.

Co-authored by: topolarity <topolarity@tapscott.me>
2022-10-27 22:00:47 -04:00
Andrew Kelley
1d1c7ae5de
Merge pull request #13257 from topolarity/ctype-fixes
stage 2: Update `CType` size/alignment
2022-10-27 21:15:22 -04:00
Veikka Tuominen
d03c47bf85 Sema: use runtime_value instead of creating allocs 2022-10-27 21:08:25 -04:00
Andrew Kelley
710e2e7f10 libcxx: only pass -DHAVE___CXA_THREAD_ATEXIT_IMPL for glibc
This definition communicates to libcxxabi that the libc will provide the
`__cxa_thread_atexit_impl` symbol. This is true for glibc but not
true for other libcs, such as musl.
2022-10-27 01:03:11 -04:00
Hadrien Dorio
9db293492b make a .rsp file for zig clang
same as std.build.LibExeObjStep.make() for `zig build-exe`
closes #12419
2022-10-26 23:50:51 +02:00
Luuk de Gram
875e98a57d
Merge pull request #13287 from Luukdegram/wasm-features
wasm-linker: feature compatibility validation
2022-10-26 14:04:16 +02:00
Jakub Konka
453a2d2fad darwin: remove 10.15.7 as available libc from src/target.zig 2022-10-26 08:53:33 +02:00
Luuk de Gram
c0710b0c42
use fixed-size arrays for feature lists
Considering all possible features are known by the linker during
compile-time, we can create arrays on the stack instead of
dynamically allocating hash maps. We use a simple bitset to determine
whether a feature is enabled or not, and from which object file
it originates. This allows us to make feature validation slightly
faster and use less runtime memory.
In the future this could be enhanced further by having a single
array instead with a more sophisticated bitset.
2022-10-25 21:16:51 +02:00
Luuk de Gram
3d1d19f387
wasm-linker: seperate linker -and cpu features
The list of features a Wasm object/binary file can emit can differ
from the list of cpu features. The reason for this is because the
"target_features" section also contains linker features. An example
of this is the "shared-mem" feature, which is a feature for the linker
and not that of the cpu target as defined by LLVM.
2022-10-25 20:48:09 +02:00
Luuk de Gram
777bcbf968
wasm-linker: emit target_features section
When the result is not being stripped, we emit the `target_features`
section based on all the used features. This includes features
inferred from linked object files.
Considering we know all possible features upfront, we can use an
array and therefore do not have to dynamically allocate memory.
Using this trick we can also easily order all features based
the same ordering as found in `std.Target.wasm` which is the same
ordering used by LLVM and the like.
2022-10-25 20:48:08 +02:00
Luuk de Gram
85b669d497
wasm-linker: validate feature compatibility
Verifies disallowed and used/required features. After verifying,
all errors will be emit to notify the user about incompatible
features. When the user did not define any featureset, we infer
the features from the linked objects instead.
2022-10-25 20:48:05 +02:00
Jakub Konka
98285b17b3 darwin: bump max macOS version to 13.0 2022-10-25 20:31:31 +02:00
Andrew Kelley
b3cd38ea4a link: add an explicit error set for flush() and flushModule()
This makes it easier to understand how control flow should happen in
various cases; already just by doing this it is revealed that
UndefinedSymbol and UndefinedSymbolReference should be merged, and that
MissingMainEntrypoint should be removed in favor of the ErrorFlags
mechanism thath we already have for missing the main entrypoint.

The main motivation for this change, however, is preventing a compile
error when there is conditional compilation inside linker
implementations, causing the flush() error set to depend on compilation
options. With this change, the error set is fixed, and, notably, the
`-Donly-c` flag no longer has compilation errors due to this error set.
2022-10-24 23:30:57 -07:00
Cody Tapscott
4ecc384f99 Fix long double on x86_64-windows
The larger alignment on this platform means that long double reports
a sizeof 16 bytes, but it's underlying size is really just the 10
bytes of `f80`

C doesn't give us a way to see the "underlying" size of a type, so
this has to be caught by hand or by monitoring runtime memory. Luckily,
x86 and x86-64 are the only platforms that seem to use a non-power-of-two
type like this.
2022-10-23 23:18:50 -07:00
Andrew Kelley
4f04759c87 build: add -Donly-c option
This option can be used to produce a C backend build of the self-hosted
compiler, which only has the C backend enabled. Once the C backend is
capable of self-hosting, this will be a way for us to replace our stage1
codebase with a C backend build of self-hosted, which we can then use
for bootstrapping. See #5246 for more details.

Using this option right now results in a crash because the C backend is
not yet passing all the behavior tests.
2022-10-23 20:05:12 -07:00
Jakub Konka
828735ac03 macho: handle majority of DW_FORM_ values for DWARF4 in the linker 2022-10-23 21:53:36 +02:00
Andrew Kelley
04472af328
Merge pull request #13251 from Vexu/c-abi
implement ARM C ABI, separate C ABI tests from standalone tests
2022-10-23 12:16:58 -07:00
Andrew Kelley
a3033c7bd9
Merge pull request #13267 from ziglang/macho-threaded-sha256
link.MachO: multi-thread first round of sha256 hashing
2022-10-23 11:35:03 -07:00
Jakub Konka
2f37278540 macho: temp hash buffer has to live as long as pread error resolution 2022-10-23 10:15:42 +02:00
Jakub Konka
1bbafbc65f macho: increment temp buffer when calculating hashes 2022-10-23 09:58:47 +02:00
Andrew Kelley
0ae60f7236 CMake: detect use of CMAKE_PREFIX_PATH env var
CMake recognizes the CMAKE_PREFIX_PATH environment variable for some
things, and also the CMAKE_PREFIX_PATH cache variable for other things.
However, it does not relate these two things, i.e. if the environment
variable is set, CMake does not populate the cache variable in a
corresponding manner. Some package systems, such as Homebrew, set the
environment variable but not the cache variable. Furthermore, the
environment variable follows the system path separator, such as ':' on
POSIX and ';' on Windows, but the cache variable follows CMake's array
behavior, i.e. always ';' for a separator.

Closes #13242
2022-10-22 20:30:08 -07:00
Cody Tapscott
c96f85852e CType: Add preferredAlignment
This value corresponds to clang/gcc's `__alignof` (rather than
`_Alignof` which reports the minimum alignment). We don't use this
information yet, but it might be useful for implementing ABIs so it
is included here.
2022-10-22 17:25:02 -07:00
Andrew Kelley
4a2f1e748e link.MachO: multi-thread first round of sha256 hashing
when computing the adhoc code signature
2022-10-22 16:03:59 -07:00
Veikka Tuominen
f2a7aba586 x86_64 llvm: correct lowering of ptr sized float struct
Closes #13211
2022-10-22 22:00:59 +03:00
Veikka Tuominen
be10f95994 ARM C ABI: workaround i128 issues 2022-10-22 19:32:56 +03:00
Jakub Konka
593b75b109 macho: some docs 2022-10-22 14:53:53 +02:00
Veikka Tuominen
5e0b4836a1 stage2: implement RISCV C ABI 2022-10-22 14:52:26 +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
Cody Tapscott
94945864b9 Type.zig: Add nvcl/cuda CType definitions 2022-10-21 20:16:00 -07:00
Cody Tapscott
f0e66ac4d0 std.Target: Remove longDoubleIs
This function is redundant with CType.sizeInBits(), and until the
previous commit they disagreed about the correct long double type
for several targets. Although they're all synced up now, it's much
simpler just to have a single source of truth.
2022-10-21 19:20:58 -07:00
Cody Tapscott
ddbdb83c86 stage 2: Update C types' size/alignment
These updates were made by testing against the `sizeof/_Alignof` reported
by Clang for all supported arch-OS-ABI combinations and correcting any
discrepancies.

This is bound to have a few errors (the recent long double fix for i386
Android is one example), but Clang is certainly not a bad place to start,
especially for our most popular targets.
2022-10-21 19:11:47 -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
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