546 Commits

Author SHA1 Message Date
Andrew Kelley
9bcd48e40e Revert "make a .rsp file for zig clang"
This reverts commit 9db293492bbbc5b8d70638bd9c59dea19d13596c.

It's not OK to call `realpath` in the compiler.

Reopens #12419
2023-01-02 16:31:45 -07:00
Luuk de Gram
4aab8118a7
WebAssembly: don't append --export for functions
No longer automatically append the `--export` flag for each exported
function unconditionally. This was essentially a hack to prevent
binary bloat caused by compiler-rt symbols being always included in
the final binary as they were exported and therefore not garbage-
collected. This is no longer needed as we now support the ability to
set the visibility of exports.
This essentially reverts 6d951aff7e32b1b0252d341e66517a9a9ee98a2d
2022-12-28 14:41:27 +01:00
Frank Denis
7802c26449 WebAssembly: do not link with --allow-undefined unconditionally
In #1622, when targeting WebAsembly, the --allow-undefined flag
became unconditionally added to the linker.

This is not always desirable.

First, this is error prone. Code with references to unkown symbols
will link just fine, but then fail at run-time.

This behavior is inconsistent with all other targets.

For freestanding wasm applications, and applications that only use
WASI, undefined references are better reported at compile-time.

This behavior is also inconsistent with clang itself. Autoconf and
cmake scripts checking for function presence think that all tested
functions exist, but then resulting application cannot run.

For example, this is one of the reasons compilation of Ruby 3.2.0
to WASI fails with zig cc, while it works out of the box with clang.
But all applications checking for symbol existence before compilation
are affected.

This reverts the behavior to the one Zig had before #1622, and
introduces an `import_symbols` flag to ignore undefined symbols,
assuming that the webassembly runtime will define them.
2022-12-25 22:32:21 +01:00
Veikka Tuominen
0c1d8659c5 Sema: print notes and reference traces when using --debug-compile-errors 2022-12-19 17:01:44 +02:00
Veikka Tuominen
bc97a5662d Sema: display cimport errors from clang 2022-12-14 14:08:22 +02:00
r00ster91
d8b4588d5f fix(terminal): handle some possible errors and resolve TODOs 2022-12-13 09:11:30 +01:00
Andrew Kelley
ac0488430f Compilation: revert asking for exclusive locks on cache hits
We definitely want a shared lock on a cache hit. Without this, we get a
deadlock when Zig is asked to compile the same C source file multiple
times as part of the same compilation.

This is a partial revert of 8ccb9a6ad327a4d7fbc321b33d4aa66a27a1f5ee.

cc @kcbanner
2022-12-10 14:34:30 -05:00
Jakub Konka
182751ba27 Revert "coff: specify default base path for relative source paths in pdb" 2022-12-09 14:16:44 +01:00
Andrew Kelley
53a9ee699a
Merge pull request #13799 from ziglang/close-stage1-issues
close stage1 issues
2022-12-07 03:06:10 -05:00
Casey Banner
8ccb9a6ad3
cache: Fix LockViolation during C compilation paths (#13591)
- C compilation flows didn't hold an exclusive lock on the cache manifest file when writing to it in all cases
- On windows, explicitly unlock the file lock before closing it
2022-12-06 23:15:54 -05:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Andrew Kelley
a3fadd2813 stage2: revert change to handling of --color on
This change has been extracted to #13786 and can be solved separately
than this branch.
2022-12-06 12:15:05 -07:00
Andrew Kelley
3dcdd5544f stage2: make --color override apply to std.Progress 2022-12-06 12:15:04 -07:00
Andrew Kelley
3ba916584d actually remove stage1 2022-12-06 12:15:04 -07:00
Andrew Kelley
db023b98a4 build: introduce -Dwasi-bootstrap option
Also, make -Donly-c prevent Autodoc from being included in the binary.

This produces a 2.6 MiB zig.wasm file. 781 KB if piped through zstd.
2022-12-06 12:15:04 -07:00
Andrew Kelley
28514476ef remove -fstage1 option
After this commit, the self-hosted compiler does not offer the option to
use stage1 as a backend anymore.
2022-12-06 12:15:04 -07:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Veikka Tuominen
e60db701d1 Sema: add option to disable formatted panics
Closes #13174
2022-11-29 21:44:08 +02:00
Andrew Kelley
58d3ee2a08 Compilation: avoid Cache hash dependency on zig lib path
* Update for the breaking changes to std.fs.path.resolve. This had a
   happy side effect of deleting some error handling code which is no
   longer needed.
 * Introduce cache_exempt_flags field to CSourceFile. This is used only
   for include directories when building libc++ and libc++abi which
   depend only on the zig lib path.
 * libc_include_dir_list is only added to the cache hash when it
   contains directories which have been obtained from system probing. It
   is exempt when the directories depend only on the zig lib path.
2022-11-22 20:57:56 -07:00
Andrew Kelley
21bd13626d Cache: introduce prefixes to manifests
Before, cache manifest files would have absolute file paths. This is
problematic for two reasons:

 * Absolute file paths are not portable. Some operating systems such as
   WASI have trouble with them. The files themselves are less portable;
   they cannot be migrated from one user's home directory to another's.
   And finally they can break due to file paths exceeding maximum path
   component size.
 * They would prevent some advanced use cases of Zig, where the lib dir
   has a different path in a different invocation but is ultimately the
   same Zig version and lib directory as before.

This commit adds a new column that specifies the prefix directory for
each file. 0 is an escape hatch and has the previous behavior. The other
two prefixes introduced are zig lib directory, and the cache directory.
This means files in zig-cache manifests can reference files local to
these directories.

In practice, this means it is possible to use a different file path for
the zig lib directory in a subsequent run of zig and have it still take
advantage of the global cache, provided that the files inside remain
unchanged.

closes #13050
2022-11-22 20:57:56 -07:00
Casey Banner
f746e11879
linker: fail the compilation if there were linker errors
There was no check for linker errors after flushing,
which meant that if the link failed the build would
continue and try to copy the non-existant exe, and
also write the manifest as if it had succeeded.

Also adds parsing of lld output, which is surfaced at the
end of the compilation with the other errors instead
of via stderr
2022-11-19 15:57:08 +02:00
Veikka Tuominen
8082323dfd
Merge pull request #13411 from dweiller/custom-test-runner
Custom test runner
2022-11-18 14:47:21 +02:00
kcbanner
88a0f3d0e5 windows: fix _tls_index not being defined if libc wasn't linked, and fix x86 name mangling 2022-11-17 11:08:21 -05:00
Veikka Tuominen
fb09093d95 Module: call ensureDeclAnalyzed on builtin.test_functions
Previously the compiler would crash on branching on undefined values
if you tried using `zig test` with a freestanding target since there
was no start code referencing `builtin.test_functions`.

Closes #12554
2022-11-16 01:12:28 +02:00
Jakub Konka
1357790ec9 win: combine PDB fixes into one changeset 2022-11-10 14:03:11 +01:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
dweiller
55c91fc42d stage2: add test_runner_path for user provided test runner 2022-11-02 12:54:35 +11:00
Andrew Kelley
30b8b29f88 re-apply "Fix C include files not being in whole cache (#11365)"
This reverts commit 06310e3d4eb47fed88b175891cb5865bb050f020, reapplying
commit a430630002bf02162ccbf8d3eb10fd73e490cefd.

I deeply apologize to @moosichu and those affected by this bug. The
original fix was actually fine. When I reverted it, I misremembered
how the Cache API works. I thought the fix was going to introduce
nondeterminism into the hash, but I forgot that the order of files in
the manifest doesn't actually matter when checking for a cache hit.

Actually, it does matter a little bit. This fix has a subtle downside
which is that it does introduce the possibility of false negatives when
checking for cache hits of 2+ iterations ago. For example, if the code
goes from "foo", to "bar", and then back to "foo", it may look like a
cache miss when it should have been a hit because 2 iterations ago the
code was the same. However, this is an uncommon use case, and all it
does is cause a bit of wasted time and disk space. That said, my
suggestion from earlier still applies and would be a nice follow-up
enhancement to this fix:

The proper solution to this is to, in whole cache mode, append the hash
inputs to some data structure, and then after the compilation is
complete, do some kind of sorting on the hash inputs so that they will
be the same order every time, then apply them in sequence. No lock on
the Cache object is needed for this scheme.

closes #11063
2022-10-30 17:04:09 -07:00
Andrew Kelley
5f5a20ebaf
Merge pull request #13093 from jacobly0/backend-fixes
C backend fixes
2022-10-29 23:06:59 -04:00
Andrew Kelley
28dc208f65
Merge pull request #13082 from g-w1/unnamed-decls-and-relocs-p9
Plan9: Fix The Backend
2022-10-29 17:45:00 -04:00
Jacob Young
48a2783969 cbe: implement optional slice representation change 2022-10-29 05:58:41 -04:00
Andrew Kelley
84e0c148b1 CLI: report error when -fstage1 requested but not available 2022-10-28 15:30:04 -07: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
Jacob Young
6a4266d62a cbe: fix infinite recursion on recursive types 2022-10-25 05:11:28 -04:00
Jacob G-W
5aef54cbc8 additional fixes for Plan9
with this, the tests should pass
2022-10-24 17:01:26 -04:00
yujiri8
a99d465f62
Fix #12091: Error message with TERM=dumb is missing info 2022-10-20 13:57:57 +03:00
Andrew Kelley
cb635e084b stage2: better handling of CacheMode.whole on Windows
Windows gives AccessDenied if you delete a directory which contains open
file handles. This could be triggered when using CacheMode.whole when
cross compiling macho test binaries.
2022-10-18 16:52:43 -07:00
Andrew Kelley
caddbbc315 build: avoid compiling self-hosted twice
build.zig: add a 'compile' step to compile the self-hosted compiler
without installing it.
Compilation: set cache mode to whole when using the LLVM backend and
--enable-cache is passed.

This makes `zig build` act the same as it does with stage1. Upside is
that a second invocation of `zig build` on an unmodified source tree
will avoid redoing the compilation again. Downside is that it will
proliferate more garbage in the project-local cache (same as stage1).

This can eventually be fixed when Zig's incremental compilation is more
robust; we can go back to having LLVM use CacheMode.incremental and rely
on it detecting no changes and avoiding doing the flush() step.
2022-10-18 16:52:43 -07:00
Ali Chraghi
d086b371f0 Compilation: strip debug info from ReleaseSmall by default 2022-10-11 17:51:25 +02:00
Ryan Liptak
6ac0d2d9d6 Fix all std lib tests being run for any file within the std package
Before this commit:

```
$ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib
2170 passed; 37 skipped; 0 failed.
```

After this commit:

```
$ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib
All 45 tests passed.
```

This matches stage1 behavior:

```
$ zig test -fstage1 lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib
All 45 tests passed.
```

All tests are still run if `zig test` is run directly on `lib/std/std.zig`:

```
$ zig test lib/std/std.zig --main-pkg-path lib/std --zig-lib-dir lib
2170 passed; 37 skipped; 0 failed.
```

`zig build test-std` is unaffected by this change.

Closes #12926
2022-10-05 04:21:16 -04:00
Jacob Young
0d92c2ca5b stage2: add support for assembly debug info
Pulls out the -g cc flag addition to the common area so that it is also
applied to assembly files.
2022-10-03 22:48:26 -04:00
Veikka Tuominen
31daea74d2 stage2: implement referenced by trace for error messages
Closes #7668
Closes #12141
2022-09-15 00:50:18 +03:00
Veikka Tuominen
349d78a443 validate number literals in AstGen 2022-09-13 20:26:04 -04:00
Andrew Kelley
f79824f946 libcxx: define _LIBCPP_ABI_VERSION and _LIBCPP_ABI_NAMESPACE
The changes from https://reviews.llvm.org/D119173 mean that __config no
longer defaults the libc++ ABI to 1, relying on external configuration.
This means Zig must provide the external configuration.

This fixes static libraries built with zig with -lc++ to have the
standard __1 namespace prefix, which had previously regressed in the
llvm15 branch.
2022-09-12 15:56:31 -07:00
Andrew Kelley
65bea514ae Compilation: handle system C compiler not found
When linking libc and compiling natively, Zig tries to integrate with
the system C compiler. However, this caused Zig to fail when no system C
compiler is installed, despite the fact that Zig is perfectly capable of
compiling & linking libc without one.

This commit makes Zig fall back to using its own ability to provide libc
in the case that no C compiler is installed. For glibc, it means
sometimes getting the warning "zig cannot build new glibc version abc,
providing instead xyz".

Ideally, Zig would do some more validation about the system libraries
being linked against, and report an error in case it could not provide
the exact correct libc version of the system libraries (or that the
system libraries themselves conflict with each other), however, I think
it is fair to call that a separate enhancement.
2022-09-11 16:37:03 -07:00
Andrew Kelley
aec0e595f2 stage2: no condition on system libs to link native libc
Before, Zig tried to use its own libc files (e.g. glibc) when there were
no system libs being linked. This prevented building against native
glibc on systems that have newer glibc than the ones Zig provides.

Closes #12797
2022-09-11 13:39:58 -07:00
Motiejus Jakštys
a833bdcd7e [ld] add --print-* for diagnostics
This adds the following for passthrough to lld:
- `--print-gc-sections`
- `--print-icf-sections`
- `--print-map`

I am not adding these to the cache manifest, since it does not change
the produced artifacts.

Tested with an example from #11398: it successfully prints the resulting
map and the GC'd sections.
2022-09-08 22:30:32 -04:00
Andrew Kelley
7377dce368 avoid exposing supportsTailCall in the standard library
This is problematic because in practice it depends on whether the
compiler backend supports it too, as evidenced by the TODO comment about
LLVM not supporting some architectures that in fact do support tail
calls.

Instead this logic is organized strategically in src/target.zig, part of
the internal compiler source code, and the behavior tests in question
duplicate some logic for deciding whether to proceed with the test.

The proper place to expose this flag is in `@import("builtin")` - the
generated source file - so that third party compilers can advertise
whether they support tail calls.
2022-08-30 12:50:15 -07:00
Jakub Konka
93127a615b coff: set some defaults for PE headers 2022-08-30 10:42:21 +02:00
Andrew Kelley
e8edc4cf83 link: add force_undefined_symbols to cache hash
Follow-up for d5233ee85ce13cba3dd03e4c0c938cee193b9b19.
2022-08-29 14:52:18 -07:00