25356 Commits

Author SHA1 Message Date
Andrew Kelley
c94bbebb91 std.zig.system.NativePaths: simplify and integrate with Darwin SDK 2023-08-03 09:52:15 -07:00
Andrew Kelley
ea0e6e737b CLI: reduce code size bloat
Make a bunch of ArrayList objects use arena instead of gpa, eliminating
the `defer` expressions, which reduces code size of zig1.wasm by 1%
2023-08-03 09:52:15 -07:00
Andrew Kelley
469af67804 CLI: delete redundant logic and use null instead of undef
The `null` value here was missed in
0a4d4eb252a73555a568a532902951a13284d2ef. I hope it is the cause of the
CI failures on Windows.

The fact that libc++ depends on libc is not important for the CLI and
Compilation.create already handles that logic.
2023-08-03 09:52:15 -07:00
Andrew Kelley
d7e74f7cbf CI: fix path to output langref
Apparently tidy doesn't exit with failure status if the input file is
not found? wtf tidy
2023-08-03 09:52:15 -07:00
Andrew Kelley
6ce37845af build.zig: use InstallArtifact Options instead of mutation
I expect this to have no functional change.
2023-08-03 09:52:15 -07:00
Andrew Kelley
aef8bcf776 std.Build.Step.Compile: fine-grained system lib search control
For each library you can specify the preferred mode and search strategy.

The old way of setting global state is eliminated.
2023-08-03 09:52:15 -07:00
Andrew Kelley
a0e94ec576 CLI: add -search_paths_first_static to complete the API
There was no previous way to set preferred mode static, search strategy
paths_first.
2023-08-03 09:52:15 -07:00
Andrew Kelley
986a3d23ab frontend: make SystemLib.path optional
This can be null in two cases right now:
1. Windows DLLs that zig ships such as advapi32.
2. extern "foo" fn declarations where we find out about libraries too late
TODO: make this non-optional and resolve those two cases somehow.
2023-08-03 09:52:14 -07:00
Andrew Kelley
e565ff305a CLI: revert -l behavior
chicken out and make -l match the status quo behavior, where it looks
for dynamic libraries and then falls back to static libraries.

library resolution is still done in the CLI now though, and these
options are added:

-search_static_first           Search for static libs in all library search
                               paths, then dynamic libs.
-search_dylibs_only            Only search for dynamic libs.
-search_static_only            Only search for static libs.

this matches the already existing options below:

-search_paths_first            For each library search path, check for dynamic
                               lib then static lib before proceeding to next path.
-search_dylibs_first           Search for dynamic libs in all library search

So, it is still possible to get the strict behavior by passing
`-search_dylibs_only` or `-search_static_only`.

This commit also makes -dynamic and -static affect the preferred link
mode and search strategy.
2023-08-03 09:52:14 -07:00
Andrew Kelley
9e50f96087 MachO: put system_libs into libs not positionals
Putting them in both causes collisions because the same lib ends up
being linked in twice.

Putting them in positionals instead of libs makes their properties about
needed and weak being ignored.
2023-08-03 09:52:14 -07:00
Andrew Kelley
2725c20a72 coff: always link uuid.lib as part of mingw libc 2023-08-03 09:52:14 -07:00
Andrew Kelley
e477352af3 CLI: Windows: system DLLs no longer trigger native paths detection 2023-08-03 09:52:14 -07:00
Andrew Kelley
c65a061881 CLI: adjust order of operations of system libraries
First, system_libs are collected into a list. This is the same as
before.

Next, system_libs are filtered into external_system_libs, which is the
same list but without any libc, compiler_rt, etc.

At this point, if there are any external system libs, native library
directory paths are detected and added to lib_dirs.

Finally, extern_system_libs are filtered into resolved_system_libs,
which has full paths to all of the libraries. This is the list passed
into Compilation.

This makes the required changes noted by @ifreund in the code review for
this branch.
2023-08-03 09:52:14 -07:00
Andrew Kelley
256074428f frontend: update is_libc_lib_name for mingw-w64 crt files 2023-08-03 09:52:14 -07:00
Andrew Kelley
5c441f7f8a cmake: find LLVM libraries unambiguously
Before, we would end up with the LLVM_LIBRARIES variable containing,
for example, "-lLLVMAnalysis;-lz" and the Zig compiler CLI would be
stuck with ambiguous library names. In this branch, that ambiguity is
not allowed; it will look for a dynamically linked LLVMAnalysis and fail
to find it in the case that the build of LLVM is static.

With this change, LLVM_LIBRARIES will contain, for example,
"/full/path/to/libLLVMAnalysis.a;-lz" and it is unambiguous that the
first library should be linked statically and the second dynamically.

In the case of a dynamically linked system LLVM, it will look like
"/full/path/to/libLLVM.so;-lz" which again is fully unambiguous.

This fixes building Zig from source.
2023-08-03 09:52:14 -07:00
Andrew Kelley
8e687cb0d9 CLI: remove --ambiguous-static-library
Reverts 6232e63ca4460a953ca8453a6f7583eb910e87c8, but keeps the usage
text cleanup.

Let's resist adding this as long as possible.
2023-08-03 09:52:14 -07:00
Andrew Kelley
89c605d140 CLI: add --ambiguous-static-library
I hate this, gonna revert it in the next commit
2023-08-03 09:52:14 -07:00
Andrew Kelley
a1e21ceec8 frontend: fix linking to Windows DLLs as system libs 2023-08-03 09:52:14 -07:00
Andrew Kelley
a08cc7d2ae compiler: resolve library paths in the frontend
search_strategy is no longer passed to Compilation at all; instead it is
used in the CLI code only.

When using Zig CLI mode, `-l` no longer has the ability to link
statically; use positional arguments for this.

The CLI has a small abstraction around library resolution handling which
is used to remove some code duplication regarding static libraries, as
well as handle the difference between zig cc CLI mode and zig CLI mode.

Thanks to this, system libraries are now included in the cache hash, and
thus changes to them will correctly cause cache misses.

In the future, lib_dirs should no longer be passed to Compilation at
all, because it is a frontend-only concept.

Previously, -search_paths_first and -search_dylibs_first were
Darwin-only arguments; they now work the same for all targets. Same
thing with --sysroot.

Improved the error reporting for failure to find a system library. An
example error now looks like this:

```
$ zig build-exe test.zig -lfoo -L. -L/a -target x86_64-macos --sysroot /home/andy/local
error: unable to find Dynamic system library 'foo' using strategy 'no_fallback'. search paths:
  ./libfoo.tbd
  ./libfoo.dylib
  ./libfoo.so
  /home/andy/local/a/libfoo.tbd
  /home/andy/local/a/libfoo.dylib
  /home/andy/local/a/libfoo.so
  /a/libfoo.tbd
  /a/libfoo.dylib
  /a/libfoo.so
```

closes #14963
2023-08-03 09:52:14 -07:00
Andrew Kelley
f887b02518
Merge pull request #16359 from g-w1/plan9-more-std
Plan 9: more standard library support
2023-08-03 09:41:20 -07:00
Fabio Arnold
31979b1006 Fix compile error in addVcpkgPaths 2023-08-03 09:37:26 -07:00
mlugg
88fb4dab81 std.target: mark helper functions inline
This was discussed in #16597. It makes sense for most of the functions
in this file to be marked inline: many are simple helper functions so
inlining is likely a strict win, and having the return values be
comptime-known may improve userspace code in some cases by preventing it
from unintentionally checking properties of the target at runtime.

This changeset is somewhat conservative: the functions marked inline are
generally returning booleans or simple integers, and many are simple
one-line checks.
2023-08-03 09:37:10 -07:00
Andrew Kelley
22662773b2 LibCInstallation: no longer depends on LLVM
Reverts 4fa8cc736966544da381c90a6111158179fc550b. This check was added
because it depended on C++ code, but after
77b96231a6bc195cc482d05599e8c20ee01645a6, this functionality no longer
depends on C++ code.
2023-08-03 02:58:08 -07:00
Andrew Kelley
e85a46cb84
Merge pull request #16656 from ziglang/issue-16628
macho: track unwind/dwarf cfi records by symbol rather than atom
2023-08-02 22:28:02 -07:00
Jacob Young
a61495a988 cmake: fix early issues when bootstrapping on mingw
This gets all the way to the final link, where `libssp` symbols are
undefined, referenced by `libzstd.a`.
2023-08-02 22:13:04 -07:00
Mitchell Hashimoto
76f7b40e15 build: dupe library, rpath, and framework LazyPaths
Without duping, users could get some unexpected behavior if they used a
string with a lifetime that didn't persist throughout the full build,
i.e. if it wasn't heap allocated, or if it was explicitly freed.
2023-08-02 20:20:48 -07:00
Jacob Young
89d660c3eb Sema: improve new error messages related to naked functions
* pass a source location to all safety checks
 * add notes about what is disallowed in naked functions

Closes #16651
2023-08-02 16:12:30 -07:00
Jacob G-W
d0fbfd3c9f Plan 9: add more features to std.os.plan9
* Replaces the exit assembly with the function from std.
* Reads the top-of-stack struct at program startup that can get information
  like the pid.
* Changes the read and write functions to use the Pread and Pwrite syscalls
  instead of the depreciated _READ and _WRITE
* Changes the openat function to use flags instead of perms.
  Plan9 does not support perms when opening, just when creating.
* Adds an errstr function to read the errstr buf created by the kernel
2023-08-02 18:19:07 -04:00
Jakub Konka
26adbf2cb7 macho: set first and last atom indexes to 0 when marking section for pruning 2023-08-03 00:12:30 +02:00
Jacob G-W
841b54f5e3 std: add SbrkAllocator and use it for Plan 9
Implements issue #6451.
This was needed to support allocation on Plan 9 and now other operating
systems like DOS can also use it.

It is a modified version of the WasmAllocator since wasm also uses a
sbrk-esque allocation system.

This commit also adds the necessary system bits for sbrk to work on plan 9.
2023-08-02 17:39:52 -04:00
Jacob G-W
4d711e8edd Plan 9 linker: don't try to calculate the vaddr before we know it
Previously, this worked on small codebases, but it is not correct.
Unconditionally emitting a reloc fixes it (and it might be more performant).
2023-08-02 17:39:52 -04:00
Jacob G-W
b9aa1dcaf1 plan 9: filesystem support 2023-08-02 17:39:52 -04:00
Jacob G-W
6293a646e3 Plan9: support linking to external 'special' symbols 2023-08-02 17:39:52 -04:00
Jacob G-W
4d22bae27e langref: fix documentation for @extern 2023-08-02 17:39:52 -04:00
Jakub Konka
16f09127b5 link-test: add matching test case for unwind info when MH_SUBSECTIONS_VIA_SYMBOLS is not set 2023-08-02 22:12:26 +02:00
Jakub Konka
d6e095de2c macho: track unwind/dwarf cfi records by symbol rather than atom
This solves the nuance case of compiling hand-crafted assembly files
which do not feature `MH_SUBSECTIONS_VIA_SYMBOLS` flag resulting in
input `Atom`s encompassing multiple symbols each with unique unwind
information.
2023-08-02 21:45:33 +02:00
Adam Goertz
9e19969e09 Remove math.ln in favor of @log 2023-08-02 12:00:14 -07:00
Andrew Kelley
4d7dd1689f CLI: stop special-casing LLVM, LLD, and Clang
Before:

-fLLVM, -fLLD, -fClang, -flibLLVM
-fno-LLVM, -fno-LLD, -fno-Clang, -fno-libLLVM

After:

-fllvm, -flld, -fclang, -flibllvm
-fno-llvm, -fno-lld, -fno-clang, -fno-libllvm
2023-08-01 20:32:54 -07:00
Kitty-Cricket Piapiac
d370005d34 std.process.totalSystemMemory: return correct error type on FreeBSD 2023-08-01 19:27:04 -07:00
Jacob Young
9e0a34f329 llvm: fix data layout calculation for experimental llvm targets
Closes #16616
2023-08-01 19:20:22 -07:00
Andrew Kelley
4f6013bf50 add behavior test for sub-aligned field access
The workaround in std.zig.Server remains because the C backend is not
passing the new test.

see #14904
2023-08-01 00:39:30 -07:00
Andrew Kelley
e84cda0ebf
Merge pull request #16622 from jacobly0/cbe-asm-compat
CBE: fix regressions and get new targets passing behavior tests
2023-07-31 15:34:32 -07:00
Andrew Kelley
8f5c333ebe
Merge pull request #16636 from ziglang/audit-devnexen
audit all contributions by @devnexen for correctness and delete unnecessary libc ABI bits
2023-07-31 15:33:54 -07:00
antlilja
928d43f61a Fix integer overflow in field padding calculation
The old code was iterating and generating symbols
for fields in their declared order instead of the
memory optimized order while getting offsets in
the memory optimized order.
2023-07-31 15:14:31 -07:00
Andrew Kelley
04d5e07d40 std.c.openbsd: remove "msg_" prefixes from structs
Reapplies 8f14431bc883898aaf78cc985e2d90716187e882 which was reverted in
95e2605d30c15963c4d6bc9e39751031b0f52007.
2023-07-31 11:57:48 -07:00
Andrew Kelley
479fd2f721 std.c.openbsd: add PTHREAD_STACK_MIN
@semarie audited this definition.
2023-07-31 11:54:27 -07:00
Andrew Kelley
b1bde35651 std.c.openbsd: add ucontext_t for aarch64
Reapplies 1585ed637d101ed16adb6b9ebdfa465299bfdb13 which was reverted in
f3adbe249b0dfad91318916142a33619232a968f.

I removed use of `usingnamespace` in this commit.

@semarie audited this struct definition.
2023-07-31 11:51:08 -07:00
Andrew Kelley
235b9fc28a Revert "std: add FreeBSD's procctl api."
This reverts commit 2e2d37917d4227d6ab9c8e43b3619bc47ce56417.
2023-07-31 11:24:21 -07:00
Andrew Kelley
99c70ec24f Revert "std: add kinfo_vmentry for FreeBSD"
This reverts commit 4a0508e56c06456c367c57a7565b9f757f2ff663.
2023-07-31 11:24:14 -07:00
Andrew Kelley
68134e56cb Revert "std add getrandom to solato solaris based systems"
This reverts commit 56d800ff7e65897d8ff9ede8e8194af4d08f0df5.
2023-07-31 11:24:09 -07:00