564 Commits

Author SHA1 Message Date
Jakub Konka
5de2aae63c link: decouple DI atoms from linker atoms, and manage them in Dwarf linker 2023-02-01 15:03:55 +01:00
Veikka Tuominen
220020599c
Merge pull request #13670 from mlugg/fix/astgen-ambiguous-package
AstGen: detect and error on files included in multiple packages
2023-01-23 14:25:42 +02:00
Andrew Kelley
8484df5bd2 zig cc: add -Wno-overriding-t-option to clang on darwin
This avoids a warning that sometimes occurs when providing both a
-target argument that contains a version as well as the
-mmacosx-version-min argument. Zig provides the correct value in both
places, so it doesn't matter which one gets overridden.
2023-01-22 12:27:18 -07:00
mlugg
5f9186d0ce
AstGen: detect and error on files included in multiple packages
Previously, if a source file was referenced from multiple packages, it
just became owned by the first one AstGen happened to reach; this was a
problem, because it could lead to inconsistent behaviour in the compiler
based on a race condition. This could be fixed by just analyzing such
files multiple times - however, it was pointed out by Andrew that it
might make more sense to enforce files being part of at most a single
package. Having a file in multiple packages would not only impact
compile times (due to Sema having to run multiple times on potentially a
lot of code) but is also a confusing anti-pattern which more often than
not is a mistake on the part of the user.

Resolves: #13662
2023-01-22 19:00:03 +00:00
mlugg
6d71d79dc2
Package: store package name directly
By @Vexu's suggestion, since fetching the name from the parent package
is error-prone and complex, and optimising Package for size isn't really
a priority.
2023-01-22 19:00:03 +00:00
Motiejus Jakštys
6b3f59c3a7 zig run/cc: recognize "-x language"
This commit adds support for "-x language" for a couple of hand-picked
supported languages. There is no reason the list of supported languages
to not grow (e.g. add "c-header"), but I'd like to keep it small at the
start.

Alternative 1
-------------

I first tried to add a new type "Language", and then add that to the
`CSourceFile`. But oh boy what a change it turns out to be. So I am
keeping myself tied to FileExt and see what you folks think.

Alternative 2
-------------

I tried adding `Language: ?[]const u8` to `CSourceFile`. However, the
language/ext, whatever we want to call it, still needs to be interpreted
in the main loop: one kind of handling for source files, other kind of
handling for everything else.

Test case
---------

*standalone.c*

    #include <iostream>

    int main() {
        std::cout << "elho\n";
    }

Compile and run:

    $ ./zig run -x c++ -lc++ standalone.c
    elho
    $ ./zig c++ -x c++ standalone.c -o standalone && ./standalone
    elho

Fixes #10915
2023-01-13 21:38:11 -05:00
Frank Denis
6ad92108e2 ELF linker: support common-page-size and max-page-size lld opts
These linker flags are required to build static ELF binaries that
can run under the Blink emulator:

https://github.com/jart/blink/issues/14
2023-01-05 19:39:17 -07:00
kcbanner
9c0a41f88a rebase fixup 2023-01-04 21:45:06 -05:00
kcbanner
b42442f5b4 windows: fixes to support using zig cc/c++ with CMake on Windows
Using zig cc with CMake on Windows was failing during compiler
detection. -nostdinc was causing the crt not to be linked, and Coff/lld.zig
assumed that wWinMainCRTStartup would be present in this case.

-nostdlib did not prevent the default behaviour of linking libc++ when
zig c++ was used. This caused libc++ to be built when CMake ran
ABI detection using zig c++, which fails as libcxxabi cannot compile
under MSVC.

- Change the behaviour of COFF -nostdinc to set /entry to the function that the
default CRT method for the specified subsystem would have called.
- Fix -ENTRY being passed twice if it was specified explicitly and -nostdlib was present.
- Add support for /pdb, /version, /implib, and /subsystem as linker args (passed by CMake)
- Remove -Ddisable-zstd, no longer needed
- Add -Ddisable-libcpp for use when bootstrapping on msvc
2023-01-04 21:45:06 -05:00
kcbanner
a03c8ef4bf fixup formatting 2023-01-04 21:45:06 -05:00
kcbanner
b97a68c529 windows: supporting changes for boostrapping via msvc
- add support for passing through .def files to the linker,
  required for building libLTO.dll in LLVM
- fixup libcpp linking conditionals
- add option to skip linking zstd for use in bootstrapping (when
  building against an LLVM with LLVM_ENABLE_ZSTD=OFF)
2023-01-04 21:45:06 -05:00
kcbanner
0471eea0e2 build: first pass on geting stage3 building under x64_64-windows-msvc 2023-01-04 21:45:05 -05:00
Casey Banner
a3e2ee0911
Fix another LockViolation case on Windows (#14162)
- Add an assert that an exclusive lock is help to writeManifest
- Only call writeManifest in updateCObject if an exclusive lock is held
- cache: fixup test to verify hits don't take an exclusive lock, instead of writing the manifest
2023-01-04 14:51:43 -05:00
Veikka Tuominen
83fd45d820
Merge pull request #13786 from ziglang/tty-detection
stage2: make --color on affect progress bar too
2023-01-04 16:54:46 +02:00
Andrew Kelley
a31ff072d1 stage2: make --color on affect progress bar too
Before, --color on would affect colored compile error printing but not
affect terminal progress bar printing. It was intended for this option
to affect both; now it does.

This causes a failure when building the language reference, which
contains code for parsing terminal output and rendering HTML. Now it
must be expanded to handle 'K' and 'D' codes to simulate a terminal
cursor moving, and the CI will fail until that capability is added in a
later commit of this branch.

I extracted this change from #13560 so that the idea is not lost but we
can solve this issue separately.
2023-01-03 13:46:47 +02:00
Guillaume Wenzek
a44085dc2a
add -fopt-bisect-limit 2023-01-03 13:05:09 +02:00
Andrew Kelley
ebcfc86bb9 Compilation: better error message for file not found 2023-01-02 16:57:15 -07:00
Andrew Kelley
c1f404ad53 Compilation: fix merge conflict with previous commit 2023-01-02 16:41:13 -07:00
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