13772 Commits

Author SHA1 Message Date
Andrew Kelley
7fb9f58f85 Compilation: rename before flush during whole cache mode
The linker needs to know the file system path of output in the flush
function because file paths inside the build artifacts reference each
other. Fixes a regression introduced in this branch.
2024-01-01 19:49:08 -07:00
Andrew Kelley
6b2709616e frontend: ignore AccessDenied when writing builtin.zig
This issue already existed in master branch, however, the more
aggressive caching of builtin.zig in this branch made it happen more
often. I added doc comments to AtomicFile to explain when this problem
can occur.

For the compiler's use case, error.AccessDenied can be simply swallowed
because it means the destination file already exists and there is
nothing else to do besides proceed with the AtomicFile cleanup.

I never solved the mystery of why the log statements weren't printing
but those are temporary debugging instruments anyway, and I am already
too many yaks deep to whip out another razor.

closes #14978
2024-01-01 19:49:08 -07:00
Andrew Kelley
a89d6878d2 Compilation: fix cache hash of incremental builds
Without this commit, unrelated test builds using incremental cache mode
(self-hosted, no lld) would end up using the same cache namespace, which
is undesireable since concurrent builds will clobber each other's work.

This happened because of passing the root module to
addModuleToCacheHash. In the case of a test build, the root module
actually does not connect to the rest of the import table. Instead, the
main module needs to be passed, which has "root" in its import table.

The other call to addModuleTableToCacheHash which is in
addNonIncrementalStuffToCacheManifest already correctly passes the main
module.

In the future, I think this problem can be fully addressed by obtaining
an advisory lock on the output binary file. However, even in that case,
it is still valuable to make different compilations use different cache
namespaces lest unrelated compilations suffer from pointless thrashing
rather than being independently edited.
2024-01-01 19:49:08 -07:00
Andrew Kelley
e22102dfc6 Compilation: make create() take an arena allocator
Instead of making its own inside create. 10 out of 10 calls to create()
had already an arena in scope, so this commit means that 10 instances of
Compilation now reuse an existing arena with the same lifetime rather
than creating a redundant one.

In other words, this very slightly optimizes initialization of the
frontend in terms of memory allocation.
2024-01-01 19:49:08 -07:00
Andrew Kelley
c2cc1b3792 frontend: add logging to help troubleshoot builtin.zig write failures 2024-01-01 19:49:08 -07:00
Andrew Kelley
668c0cdeda compiler: Compilation.Config: trivial refactor 2024-01-01 19:49:08 -07:00
Andrew Kelley
196ddf010c frontend: fix populateTestFunctions accessing the wrong module
The test runner reads the list of test function pointers from its own
builtin module, which is the root_mod, not main_mod.
2024-01-01 19:49:08 -07:00
Andrew Kelley
b8674910d4 restore -fno-emit-bin -femit-llvm-ir functionality
Now, link.File will always be null when -fno-emit-bin is specified, and
in the case that LLVM artifacts are still required, the Zcu instance has
an LlvmObject.
2024-01-01 19:49:08 -07:00
Andrew Kelley
92cc2f41e6 CLI: fix compilation on Windows 2024-01-01 19:49:08 -07:00
Andrew Kelley
659e043a34 Compilation: don't add importlib jobs when outputting C code
Fixes "building import libs not included in core functionality" when
bootstrapping on Windows.
2024-01-01 19:49:08 -07:00
Andrew Kelley
3a0b76b855 link.File.Wasm: remove dead condition 2024-01-01 19:49:08 -07:00
Andrew Kelley
e47141a14e frontend: fix incorrect WebAssembly hasDebugInfo=false 2024-01-01 19:49:08 -07:00
Andrew Kelley
6509c492ad move misc_errors from linker to Compilation
So that they can be referenced by getAllErrorsAlloc(). Fixes missing
compile errors.
2024-01-01 19:49:07 -07:00
Andrew Kelley
791e83c223 frontend: make dll_export_fns=false on non-windows
Fixes a regression introduced in this branch.
2024-01-01 19:49:07 -07:00
Andrew Kelley
476484f09c Compilation: inline the flush function
There is only one call to this function and this made it easier to
troubleshoot the logic.
2024-01-01 19:49:07 -07:00
Andrew Kelley
4c3342ed76 glibc: fix crash from not setting owner module 2024-01-01 19:49:07 -07:00
Andrew Kelley
7f13754778 Compilation: fix whole mode cache hash
before this commit it was trying to hash based on resolved bin_file
settings, but bin_file was always null since cache mode is always whole
when this function is called! hash based on the lf_open_opts instead.
2024-01-01 19:49:07 -07:00
Andrew Kelley
5b05e99dd4 Compilation: consolidate module hashing code 2024-01-01 19:49:07 -07:00
Andrew Kelley
372b407740 move eh_frame_hdr from link.File to Compilation
since it's accessed by Compilation. fixes an invalid check of
bin_file==null
2024-01-01 19:49:07 -07:00
Andrew Kelley
435b74acd6 move force_undefined_symbols into Compilation
This field is needed by Compilation regardless of whether a link file is
instantiated.

Fixes an invalid check for bin_file=null.
2024-01-01 19:49:07 -07:00
Andrew Kelley
190f6038bf zig build: reintroduce --prominent-compile-errors
This reintroduced flag makes zig build behave the same as the previous
commit. Without this flag, the default behavior is now changed to
display compilation errors inline with the rest of error messages and
the build tree context.

This behavior is essential for making sense of error logs from projects
that have two or more steps emitting compilation errors which is why it
is now the default.
2024-01-01 19:49:07 -07:00
Andrew Kelley
524dc756b3 Compilation: several branch regression fixes
* move wasi_emulated_libs into Compilation
  - It needs to be accessed from Compilation, which needs to potentially
    build those artifacts.
* Compilation: improve error reporting for two cases
  - the setMiscFailure mechanism is handy - let's use it!
* fix one instance of incorrectly checking for emit_bin via
  `comp.bin_file != null`. There are more instances of this that need to
  be fixed in a future commit.
* fix renameTmpIntoCache not handling the case where it needs to make
  the "o" directory in the zig-cache directory.
  - while I'm at it, simplify the logic for handling the fact that
    Windows returns error.AccessDenied rather than
    error.PathAlreadyExists for failure to rename a directory over
    another one.
* fix missing cache hash additions
  - there are still more to add in a future commit -
    addNonIncrementalStuffToCacheManifest is called when bin_file is
    always null, and then it incorrectly checks if bin_file is non-null
    and only then adds a bunch of stuff to the cache hash. It needs to
    instead add to the cache hash based on lf_open_opts.
2024-01-01 17:51:21 -07:00
Andrew Kelley
57562c8d50 compiler: push entry symbol name resolution into the linker
This is necessary because on COFF, the entry symbol name is not known
until the linker has looked at the set of global symbol names to
determine which of the four possible main entry points is present.
2024-01-01 17:51:21 -07:00
Andrew Kelley
c9fe43679f frontend: remove deprecated field from Compilation 2024-01-01 17:51:21 -07:00
Andrew Kelley
6beae6c061 frontend: avoid spurious error when no zcu
use_llvm=false does not always mean there needs to be a zig compiler
backend available. In particular, when there is no zig compilation unit,
use_llvm=false and yet no zig backend will be used to produce code.
2024-01-01 17:51:21 -07:00
Andrew Kelley
951c5b3f67 frontend: fix "any" default resolution ambiguity
In Compilation.create, update the resolved config to account for the
default resolution of the root module. This makes it so that, for
example, reading comp.config.any_non_single_threaded is valid in order
to determine whether any module has single_threaded=false.
2024-01-01 17:51:21 -07:00
Andrew Kelley
b8a8fb927b link.File.Elf: bump 32-bit image_base default to 64K
Now that we always pass --image-base to LLD, including when Zig chooses
the default value, LLD is complaining about 32-bit architectures because
it requires being at least equal to the max page size, which is 64K.
2024-01-01 17:51:21 -07:00
Andrew Kelley
4c07d41b52 CLI: fix logic for zig test error message
When using the build system to do unit testing, it lowers to --mod
arguments which were incorrectly tripping a "zig test requires a source
file argument" error.
2024-01-01 17:51:21 -07:00
Andrew Kelley
b36659c972 fix MachO linking
* fix relationship between createEmpty/open (similar logic as
  607111aa758002bc51914b7dc800b23927c931b8)
* still resolve the start symbol when linking libc because when zig is
  the linker it still needs to know the entry symbol.
* make use_llvm=false when there is no zig compilation unit.
2024-01-01 17:51:21 -07:00
Andrew Kelley
944b0ef518 link.File.Coff: fix relationship between createEmpty/open
similar commit to b0c433c80f2e4edd7b60e444b4ea56dacb727051
2024-01-01 17:51:21 -07:00
Andrew Kelley
98dd4f7847 frontend: skip astgen for builtin.zig
since it's already done ahead of time and always unchanging
2024-01-01 17:51:21 -07:00
Andrew Kelley
4f8a44cd0f compiler: fix UAF when writing builtin.zig 2024-01-01 17:51:21 -07:00
Andrew Kelley
44e2dbe117 fix logic for default entry point
when linking libc, the entry point is within libc.
when producing C code, the entry point is decided when compiling the C
code and does not need to be known up front.

fixes a false positive "error: unknown target entry point" when using
-ofmt=c.
2024-01-01 17:51:21 -07:00
Andrew Kelley
1edcea9ec8 link.Wasm: fix relationship between createEmpty/open 2024-01-01 17:51:21 -07:00
Andrew Kelley
981166e33f link.Elf: truncate=true in createEmpty 2024-01-01 17:51:21 -07:00
Andrew Kelley
4d28db7329 Zcu: mark outdated decl handling as unreachable from only_c builds
This way we don't drag in linker code into only_c builds that doesn't
need to be there.
2024-01-01 17:51:21 -07:00
Andrew Kelley
edccd68adf Package.Module: fix typo in default red-zone setting
oops, this was supposed to return true, not false.
2024-01-01 17:51:21 -07:00
Andrew Kelley
41ab64c3eb Compilation.Config.resolve: explicit error set
Some logic has comptime-known conditions, causing the inferred error set
to be different on different compiler build configurations.
2024-01-01 17:51:21 -07:00
Andrew Kelley
24eec48f60 CLI: update main usage text
* Organize and reword some stuff
* Add missing usage for `zig reduce`
2024-01-01 17:51:21 -07:00
Andrew Kelley
9141e1a29c CLI: fix logic for sending output file path
via the compiler protocol
2024-01-01 17:51:21 -07:00
Andrew Kelley
e12e296306 CLI: fix not respecting module remappings 2024-01-01 17:51:21 -07:00
Andrew Kelley
3262e9ccee zig build: fix logic for extracting executable file from Compilation 2024-01-01 17:51:21 -07:00
Andrew Kelley
3b36c4d0b3 zig build: pass resolved_target to Module.create
it's now required to pass this for the root module
2024-01-01 17:51:21 -07:00
Andrew Kelley
056f04c1ff CLI: rename clang_argv to cc_argv
The args apply to Aro as well.
2024-01-01 17:51:21 -07:00
Andrew Kelley
fad35835aa CLI: better error messages for bad args 2024-01-01 17:51:20 -07:00
Andrew Kelley
529d01c2ba resolve error tracing logic at module creation time
rather than checking multiple conditions in Sema
2024-01-01 17:51:20 -07:00
Andrew Kelley
8944dea23f CLI: fix regressed logic for any_dyn_libs
This value needs access to the fully resolved set of system libraries,
which required restructuring a bunch of CLI logic.
2024-01-01 17:51:20 -07:00
Andrew Kelley
db2ca2ca00 CLI: mark any_dyn_libs=true when encountering a shared object 2024-01-01 17:51:20 -07:00
Andrew Kelley
4b667e7362 fix compilations without zig compilation units 2024-01-01 17:51:20 -07:00
Andrew Kelley
fe87bae7e3 frontend: fix handling of special builtin module
it's allocated differently and imported differently
2024-01-01 17:51:20 -07:00