12508 Commits

Author SHA1 Message Date
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
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
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
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
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
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
6293a646e3 Plan9: support linking to external 'special' symbols 2023-08-02 17:39:52 -04: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
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
Jacob Young
9e0a34f329 llvm: fix data layout calculation for experimental llvm targets
Closes #16616
2023-08-01 19:20:22 -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
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
Jacob Young
228c956377 std: finish cleanup up asm
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-31 03:49:21 -04:00
Jacob Young
2ba787e303 Sema: restrict what can appear in a naked function
* Disable runtime calls, since it is not possible to know the proper
   stack adjustment to follow the callee abi.
 * Disable runtime returns, since it is not possible to know where the
   return address is stored in general.
 * Allow implicit returns regardless of the return type, which allows
   naked functions with a non-void return type to be written.
2023-07-31 01:58:10 -04:00
Jacob Young
9831f27238 cbe: get behavior tests running on arm
Specifically without linking libc.
2023-07-31 01:58:10 -04:00
Jacob Young
817fa3af86 std: cleanup asm usage
After fixing some issues with inline assembly in the C backend, the std
cleanups have the side effect of making these functions compatible with
the backend, allowing it to be used on linux without linking libc.
2023-07-31 01:58:10 -04:00
Andrew Kelley
6393928d50 link: add more respect for -fno-emit-bin
closes #16347
2023-07-30 11:19:36 -07:00
Jacob Young
6f0a613b6f
Merge pull request #16611 from xxxbxxx/packed-struct
codegen: fix various packed struct issues

Closes #16609
Closes #15337
2023-07-29 23:49:14 -04:00
Frank Denis
7ad4aede7a Remove obsolete comment in wasi_libc.zig
The referenced bug in LLD has been fixed:
https://reviews.llvm.org/D85567
2023-07-29 20:33:29 -07:00
Jacob Young
dc8a80a191 llvm: support read-write output constraints in assembly
Closes #15227
2023-07-29 09:49:04 -07:00
Andrew Kelley
b8dda2dbe1
Merge pull request #16594 from squeek502/windows-sdk-com
windows_sdk.zig: Reinstate COM ISetupEnumInstances logic
2023-07-29 09:47:39 -07:00
AdamGoertz
796927b900
Allow zero-sized fields in extern structs (#16404)
This change allows the following types to appear in extern structs:
* Zero-bit integers
* void
* zero-sized structs and packed structs
* enums with zero-bit backing integers
* arrays of any length with zero-size elements
2023-07-29 12:45:01 -04:00
Xavier Bouchoux
8c367ef99a codegen: fix access to byte-aligned nested packed struct elems
When acessing a packed struct member via a byte aligned ptr (from the optimisation in Sema.structFieldPtrByIndex())
the codegen must apply the parent ptr packed_offset in addition to the field offset itself.

resolves https://github.com/ziglang/zig/issues/16609
2023-07-29 18:16:13 +02:00
Xavier Bouchoux
46abf20454 llvm: partial fix of store undefined to packed result location
prefer marking too few undefined bits, rather than too many that may overwrite nearby values.
partially resolves https://github.com/ziglang/zig/issues/15337
2023-07-29 11:56:27 +02:00
Ryan Liptak
41aaf1e6e8 windows_sdk: Get the latest installed version when using COM
Before, iteration would stop whenever an installation with vcruntime.lib was found, but that may not be the most recent installed version. Instead, we now iterate all installed instances and choose the one with the newest version.
2023-07-28 23:36:04 -07:00
mlugg
417b92f085 package manager: don't show progress indicator on dumb terminals
This mirrors the behavior of the progress indicator for the actual
compilation. Not doing this was causing sporadic CI failures due to the
(non-existent) fetches taking long enough to appear in stderr.
2023-07-28 21:45:00 -07:00
xdBronch
2826f78a61
suggest using else when '_' is used for exhaustive enums (#16583) 2023-07-28 22:28:55 -04:00
Ryan Liptak
8579f720b0 windows_sdk.zig: Reinstate COM ISetupEnumInstances logic
The C++ version of this code used this logic, and it turns out it is able to find some setups that the current registry/Vs7 methods cannot.

For example, if only the "Build Tools for Visual Studio" are installed but not Visual Studio itself, then only the ISetupEnumInstances method seems to find it.

Follow up to #15657, fixes a regression caused by moving from the C++ version to the Zig version
2023-07-28 19:19:32 -07:00
Jacob Young
125b453c58 llvm: fix SysV C abi for structs smaller than two eightbytes
Closes #16038
Closes #16288
2023-07-28 19:27:08 -04:00
Jacob Young
c80609dfec Sema: don't reorder tuple fields
This conflicts with anon structs which can be in-memory coercible but
are never reordered.

Closes #16242
2023-07-28 19:27:08 -04:00
Andrew Kelley
282cb5ee5d
Merge pull request #16559 from kcbanner/improve_compiler_rt_stack_trace
Unwinding follow up: Don't strip compiler_rt symbols, enable unwind tables on supported platforms
2023-07-27 11:07:10 -07:00
Andrew Kelley
e66190025f frontend: make fn calls byval; fix false positive isNonErr
This commit does two things which seem unrelated at first, but,
together, solve a miscompilation, and potentially slightly speed up
compiler perf, at the expense of making #2765 trickier to implement in
the future.

Sema: avoid returning a false positive for whether an inferred error set
is comptime-known to be empty.

AstGen: mark function calls as not being interested in a result
location. This prevents the test case "ret_ptr doesn't cause own
inferred error set to be resolved" from being regressed. If we want to
accept and implement #2765 in the future, it will require solving this
problem a different way, but the principle of YAGNI tells us to go ahead
with this change.

Old ZIR looks like this:

  %97 = ret_ptr()
  %101 = store_node(%97, %100)
  %102 = load(%97)
  %103 = ret_is_non_err(%102)

New ZIR looks like this:

  %97 = ret_type()
  %101 = as_node(%97, %100)
  %102 = ret_is_non_err(%101)

closes #15669
2023-07-27 10:12:08 -07:00
Andrew Kelley
0f21d3d4d1 LLVM: always add argument attributes to calls
These are needed for correctness. There's no reason to only add them for
function pointers.

closes #16290
2023-07-27 00:49:25 -07:00
Jacob Young
7201e69454 AstGen: fix missing deferred ref
Closes #16524
2023-07-26 22:19:30 -07:00
kcbanner
661028a907 target: emit unwind tables if the platform supports unwinding 2023-07-26 20:58:29 -04:00
kcbanner
f2aab12a86 compilation: change compiler_rt to inherit strip and want_unwind_tables from the parent compilation 2023-07-26 20:58:29 -04:00
Jacob Young
f9717f87f5 llvm: fix data layout on ios
Closes #16549
2023-07-26 16:49:32 -07:00
Jakub Konka
f821543e4b
Merge pull request #16553 from ziglang/issue-11896
macho: fix parsing of TBDv3 dylib stubs
2023-07-26 18:22:59 +02:00
Jakub Konka
59284a1085 macho: create export trie root explicitly with Trie.init 2023-07-26 13:37:37 +02:00
kcbanner
a8a2f2b58b Add --verbose-generic-instances to provide visibility on the number of generic function instantiations 2023-07-26 02:20:29 -07:00