27132 Commits

Author SHA1 Message Date
Luuk de Gram
596d1cd5a8
wasm-linker: support --no-gc-sections
By default we garbage-collect sections for Wasm to reduce size, as well
as finish linking quicker (as we have fewer things to do). However,
when the user specifies `--no-gc-sections` we ensure all resolved symbols
get marked and therefore do not get garbage collected.
This is supported in both incremental-mode and traditional linking.
2023-11-28 16:40:26 +01:00
Luuk de Gram
4be3cd2754
wasm-linker: support gc for wasm backend code
When using the Wasm backend, we will now also perform garbage collection
there, to ensure unreferenced symbols do not get parsed nor emit into
the final binary.
2023-11-28 15:47:07 +01:00
Luuk de Gram
8447d4fb1f
wasm-linker: handle debug info during gc
When we encounter a debug info symbol, we initially have to parse it
into an atom to find its relocations. We then go through its relocations
to find out if any of the target symbols are marked alive. When it
finds an alive symbol, we also mark the debug symbol as alive to ensure
this piece of debug info is emit to the binary. When it does not encounter
any alive symbols, the debug symbol remains dead and will be garbage-
collected during `allocateAtoms`.
2023-11-28 15:47:07 +01:00
Luuk de Gram
f7d4f72fd5
wasm-linker: Only emit name of referenced symbols 2023-11-28 15:47:07 +01:00
Luuk de Gram
6f7a9b3144
wasm-linker: deduplicate aliased functions
When multiple symbols point to the same function, we ensure any
other symbol other than the original will be discarded and point
to the original instead. This prevents emitting the same function
code more than once.
2023-11-28 15:47:07 +01:00
Luuk de Gram
8856ba7505
wasm-linker: parse symbols into atoms lazily
Rather than parsing every symbol into an atom, we now only parse them
into an atom when such atom is marked. This means garbage-collected
symbols will also not be parsed into atoms, and neither are discarded
symbols which have been resolved by other symbols. (Such as multiple
weak symbols).

This also introduces a binary search for finding the start index into
the list of relocations. This speeds up finding the corresponding
relocations tremendously as they're ordered ascended by address.

Lastly, we re-use the memory of atom's data as well as relocations
instead of duplicating it. This means we half the memory usage of
atom's data and relocations for linked object files. As we are
aware of decls and synthetic atoms, we free the memory of those
atoms indepedently of the atoms of object files to prevent double-frees.
2023-11-28 15:47:07 +01:00
Luuk de Gram
c986c6c90a
wasm-linker: do not merge unreferenced symbols
When a symbol is unreferenced and therefore garbage-collected, we do
not merge its specific section into the final binary.
2023-11-28 15:47:07 +01:00
Luuk de Gram
589aef1537
wasm-linker: mark symbols and its references
Symbols which are exported to the host, or contain the `NO_STRIP`
flag, will be marked. All symbols which are referenced by this symbol
are marked likewise. We achieve this by parsing all relocations of a
symbol, and then marking the symbol it points to within the relocation.
2023-11-28 15:47:06 +01:00
Luuk de Gram
f3626eb816
wasm-link: ensure TLS global when resolved
When a linked object contains references to the __tls_base symbol,
we lazily create this symbol. However, we wouldn't create the corresponding
Wasm global. This meant its address wasn't set correctly as well as fail
to output it into the `Names` section.
2023-11-28 15:47:03 +01:00
Andrew Kelley
2a32264533 package fetching: catch relative paths that resolve into cache dir
The logic here already caught the case when a dependency path tried to
escape out of the zig cache directory using up directories. However, it
did not catch the case when the relative path tried to reach into a
different path within the zig-cache. For example, if it asked for
"../../../blah" then it would be caught, but if it asked for "../blah"
then it would try to resolve as "zig-cache/p/blah" and probably result
in file-not-found, or perhaps resolve to a different package if someone
inadvertently used a valid package hash instead of "blah".

Now it correctly gives a "dependency path outside project" error,
however, still allows relative paths with up-dirs that were not fetched
via URL.
2023-11-28 04:14:41 -05:00
Carter Snook
a98d4a66e9 std.net: replace @ptrCast with slice syntax 2023-11-27 23:14:07 -05:00
Carter Snook
a0fbc6815c std.zig.system: remove explicit usize cast
The cast seems to no longer be necessary after changes in interactions
between `u64` and `usize`.
2023-11-27 23:13:30 -05:00
Bogdan Romanyuk
7fbbeae617
value: handle lazy_align and lazy_size in writeToPackedMemory 2023-11-27 12:35:29 +00:00
Andrew Kelley
89572c6342
Merge pull request #18138 from ziglang/fetch-save
`zig fetch`: add `--save` flag
2023-11-27 04:47:44 -05:00
Andrew Kelley
0c0b69891a zig fetch: add --save flag
```
--save        Add the fetched package to build.zig.zon
--save=[name] Add the fetched package to build.zig.zon as name
```
2023-11-26 19:41:00 -07:00
Andrew Kelley
a0c8d54823 add Package.Manifest.copyErrorsIntoBundle 2023-11-26 19:41:00 -07:00
Andrew Kelley
70d51be3a2 std.zig.render: add ability to append strings after nodes 2023-11-26 19:41:00 -07:00
Lauri Tirkkonen
19af8aac82 os: expect ETIMEDOUT, ECONNRESET, ENOTCONN from recvfrom & read family
reads on eg. connected TCP sockets can fail with ETIMEDOUT, and ENOTCONN
happens eg. if you try to read a TCP socket that has not been connected
yet.

interestingly read() was already handling CONNRESET & TIMEDOUT, but
readv(), pread(), and preadv() were somewhat inconsistent.
2023-11-26 21:35:36 -05:00
Daniel A.C. Martin
280140595f fix: Prevent segfault when using add.Module()
This duplicates the source file string (as is done in other places such
as `addAssemblyFile()`) in order to prevent a segfault when the supplied
string is freed by the caller. This is still seen when the caller makes
use of a defer statement.
2023-11-26 21:33:28 -05:00
Meghan Denny
f29302f915 build.zig: remove an unneeded 'else unreachable'
removed a TODO 🎊
2023-11-26 14:29:34 -05:00
Michael Dusan
50bbb9d960 bsd: debitrot atomic and debug
closes #18119
2023-11-26 14:28:22 -05:00
David Rubin
069a079ddc complete todo 2023-11-26 14:27:39 -05:00
Meghan Denny
2549de80b2 move Module.Decl.Index and Module.Namespace.Index to InternPool 2023-11-26 02:24:40 -05:00
Andrew Kelley
7103088e4a
Merge pull request #18105 from Vexu/translate-c
Use Aro's tokenizer in `translate-c`
2023-11-26 02:22:51 -05:00
Bogdan Romanyuk
2ff707be78
AstGen: check allowed non-function builtins with declarative field (#18120) 2023-11-26 02:21:58 -05:00
Bogdan Romanyuk
2252dcc508
Compiler: move checking function-scope-only builtins to AstGen 2023-11-25 17:29:07 +00:00
Bogdan Romanyuk
bece97ef24
Sema: ensure tuple fields is resolved and fix internal out-of-bounds access 2023-11-25 14:05:51 +00:00
Tw
2fefc0b5c7
Zir: add missing extra index for linksection_or_addspace
Closes #18052
Closes #18104

Signed-off-by: Tw <tw19881113@gmail.com>
2023-11-25 11:39:37 +00:00
Veikka Tuominen
74010fecc7 translate-c: use Aro's tokenizer 2023-11-25 12:28:19 +02:00
Andrew Kelley
648f592db1
Merge pull request #18109 from nektro/std-compiler
compiler: move BuiltinFn and AstRlAnnotate to std.zig namespace
2023-11-25 04:11:46 -05:00
Techatrix
18608223ef convert toType and toValue to Type.fromInterned and Value.fromInterned 2023-11-25 04:09:53 -05:00
Andrew Kelley
e834e95d71 Revert "std.SinglyLinkedList: add sort function"
This reverts commit 8b10970836480a43a3bbb1276cb258c2a8b613f2.

This implementation has the following problems:

* It does not provide context to the less than function. This will be an
  API break in order to fix.
* It uses recursion, causing unbounded stack memory usage - likely
  depending on user input, which is extra problematic.
* Sorting linked lists is generally an inefficient operation;
  encouraging it by having a standard library function for it may
  lead to suboptimal software being written in Zig.

Furthermore, there is almost no benefit to providing a sort function as
a method, when a third party implementation can easily be passed a
linked list to then be sorted.
2023-11-24 22:33:50 -07:00
Veikka Tuominen
d2a8660d04 sync Aro dependency
ref: 9d538ea0253bb63c0b35ec907a3a734d1e22fc32
2023-11-25 04:52:21 +02:00
Meghan Denny
c6e02044da cmake: fix location of AstRlAnnotate.zig 2023-11-24 18:17:28 -08:00
Meghan Denny
121d995fcb frontend: move AstRlAnnotate to std.zig namespace 2023-11-24 17:09:08 -08:00
Meghan Denny
84d58aaa1f frontend: move BuiltinFn to std.zig namespace 2023-11-24 17:04:52 -08:00
Meghan Denny
2b2c13926d AstGen: remove calls to tracy 2023-11-24 17:04:03 -08:00
Justus Klausecker
8b10970836
std.SinglyLinkedList: add sort function 2023-11-24 23:49:12 +00:00
Garrett
a277181c66
translate-c: use struct_init_one for empty struct initializer 2023-11-24 22:44:33 +00:00
Robin Voetter
608b5d06ea
Merge pull request #18097 from Snektron/spirv-structured-codegen
spirv: structured codegen
2023-11-24 23:01:32 +01:00
Robin Voetter
decff51238
spirv: structured control flow 2023-11-24 17:50:11 +01:00
Luca Ivaldi
3acb0e30a0
std.fmt: fix overflow when formatting comptime_float 2023-11-24 18:31:12 +02:00
Robin Voetter
b4b1c4df64
spirv: add -fstructured-cfg option
This enables the compiler to generate a structured cfg even in opencl,
even if it is not strictly required by the SPIR-V Kernel specification.
2023-11-24 11:40:18 +01:00
Robin Voetter
cb026c5d59
spirv: always emit mask constants even if no bits are set
A parameter like this is not always optional, even if that is
usually implied. SPIR-V tools fail to parse a module with an
OpLoopMerge instruction where the loop control parameter is
left out.
2023-11-24 01:11:15 +01:00
Robin Voetter
255737ea57
spirv: fix memory leak in SpvModule 2023-11-24 01:11:14 +01:00
Robin Voetter
28e1d82857
spirv: disable failing tests 2023-11-24 01:11:12 +01:00
John Benediktsson
54f4abae2f
Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011) 2023-11-23 15:06:32 -05:00
Andrew Kelley
464ce8ac67
Merge pull request #18091 from squeek502/no-shell32-no-ole32
Remove Zig's internal depedency on `shell32.dll` and `ole32.dll`
2023-11-23 14:49:56 -05:00
David Rubin
6f8c597fff fix spelling 2023-11-23 17:32:48 +02:00
Ryan Liptak
0bc4ee1792 Remove std.os.windows.ole32/shell32 2023-11-23 03:06:47 -08:00