307 Commits

Author SHA1 Message Date
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
2d2a18831e linker: rename intermediary_basname to zcu_object_sub_path 2024-01-01 17:51:20 -07:00
Andrew Kelley
2047a6b82d fix remaining compile errors except one 2024-01-01 17:51:20 -07:00
Andrew Kelley
638db680f4 move dll_export_fns and rdynamic to Compilation.Config 2024-01-01 17:51:20 -07:00
Andrew Kelley
b54ad93175 update codegen.llvm references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
c49957dbe8 fix a round of compile errors caused by this branch 2024-01-01 17:51:19 -07:00
Andrew Kelley
f54471b54c compiler: miscellaneous branch progress
implement builtin.zig file population for all modules rather than
assuming there is only one global builtin.zig module.

move some fields from link.File to Compilation
move some fields from Module to Compilation

compute debug_format in global Compilation config resolution

wire up C compilation to the concept of owner modules

make whole cache mode call link.File.createEmpty() instead of
link.File.open()
2024-01-01 17:51:19 -07:00
Andrew Kelley
769dea6e37 Compilation: redo whole vs incremental logic in create and update 2024-01-01 17:51:19 -07:00
Andrew Kelley
33cdf33b95 compiler: update many references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
41a8f5aec3 remove parent_compilation_link_libc 2024-01-01 17:51:19 -07:00
Andrew Kelley
0789e91eeb linkers: update references to "options" field 2024-01-01 17:51:19 -07:00
Andrew Kelley
3b6cb257df update image_base references 2024-01-01 17:51:19 -07:00
Andrew Kelley
b5e2af49a0 linker: update link_mode references 2024-01-01 17:51:19 -07:00
Andrew Kelley
2bef0715c7 move a large chunk of linker logic away from "options"
These options are only supposed to be provided to the initialization
functions, resolved, and then computed values stored in the appropriate
place (base struct or the object-format-specific structs).

Many more to go...
2024-01-01 17:51:18 -07:00
Andrew Kelley
12de7e3472 WIP: move many global settings to become per-Module
Much of the logic from Compilation.create() is extracted into
Compilation.Config.resolve() which accepts many optional settings and
produces concrete settings. This separate step is needed by API users of
Compilation so that they can pass the resolved global settings to the
Module creation function, which itself needs to resolve per-Module
settings.

Since the target and other things are no longer global settings, I did
not want them stored in link.File (in the `options` field). That options
field was already a kludge; those options should be resolved into
concrete settings. This commit also starts to work on that, deleting
link.Options, moving the fields into Compilation and
ObjectFormat-specific structs instead. Some fields were ephemeral and
should not have been stored at all, such as symbol_size_hint.

The link.File object of Compilation is now a `?*link.File` and `null`
when -fno-emit-bin is passed. It is now arena-allocated along with
Compilation itself, avoiding some messy cleanup code that was there
before.

On the command line, it is now possible to configure the standard
library itself by using `--mod std` just like any other module. This
meant that the CLI needed to create the standard library module rather
than having Compilation create it.

There are a lot of changes in this commit and it's still not done. I
didn't realize how quickly this changeset was going to balloon out of
control, and there are still many lines that need to be changed before
it even compiles successfully.

* introduce std.Build.Cache.HashHelper.oneShot
* add error_tracing to std.Build.Module
* extract build.zig file generation into src/Builtin.zig
* each CSourceFile and RcSourceFile now has a Module owner, which
  determines some of the C compiler flags.
2024-01-01 17:51:18 -07:00
Andrew Kelley
77420af9d0 compiler: get the dynamic linker from the target
instead of passing it to Compilation separately and storing it
separately in the linker options.
2024-01-01 17:51:18 -07:00
Andrew Kelley
142471fcc4 zig build system: change target, compilation, and module APIs
Introduce the concept of "target query" and "resolved target". A target
query is what the user specifies, with some things left to default. A
resolved target has the default things discovered and populated.
In the future, std.zig.CrossTarget will be rename to std.Target.Query.
Introduces `std.Build.resolveTargetQuery` to get from one to the other.

The concept of `main_mod_path` is gone, no longer supported. You have to
put the root source file at the module root now.

* remove deprecated API
* update build.zig for the breaking API changes in this branch
* move std.Build.Step.Compile.BuildId to std.zig.BuildId
* add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions,
  std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and
  std.Build.TestOptions.
* remove `std.Build.constructCMacro`. There is no use for this API.
* deprecate `std.Build.Step.Compile.defineCMacro`. Instead,
  `std.Build.Module.addCMacro` is provided.
  - remove `std.Build.Step.Compile.defineCMacroRaw`.
* deprecate `std.Build.Step.Compile.linkFrameworkNeeded`
  - use `std.Build.Module.linkFramework`
* deprecate `std.Build.Step.Compile.linkFrameworkWeak`
  - use `std.Build.Module.linkFramework`
* move more logic into `std.Build.Module`
* allow `target` and `optimize` to be `null` when creating a Module.
  Along with other fields, those unspecified options will be inherited
  from parent `Module` when inserted into an import table.
* the `target` field of `addExecutable` is now required. pass `b.host`
  to get the host target.
2024-01-01 17:51:18 -07:00
Andrew Kelley
225fe6ddbf Compilation: remove parent_compilation_link_libc
This option is not needed since the link_libc flag can be set directly
when creating compiler_rt.

This fixes a problem where an immutable flag was being mutated in Sema.
2023-12-13 11:28:42 -08:00
Lauri Tirkkonen
19af8aac82 os: expect ETIMEDOUT, ECONNRESET, ENOTCONN from recvfrom & read family
reads on eg. connected TCP sockets can fail with ETIMEDOUT, and ENOTCONN
happens eg. if you try to read a TCP socket that has not been connected
yet.

interestingly read() was already handling CONNRESET & TIMEDOUT, but
readv(), pread(), and preadv() were somewhat inconsistent.
2023-11-26 21:35:36 -05:00
Meghan Denny
2549de80b2 move Module.Decl.Index and Module.Namespace.Index to InternPool 2023-11-26 02:24:40 -05:00
Robin Voetter
b4b1c4df64
spirv: add -fstructured-cfg option
This enables the compiler to generate a structured cfg even in opencl,
even if it is not strictly required by the SPIR-V Kernel specification.
2023-11-24 11:40:18 +01:00
Andrew Kelley
4bc88dd116 link: support exporting constant values without a Decl
The main motivating change here is to prevent the creation of a fake
Decl object by the frontend in order to `@export()` a value.

Instead, `link.updateDeclExports` is renamed to `link.updateExports` and
accepts a tagged union which can be either a Decl.Index or a
InternPool.Index.
2023-10-26 20:32:16 -07:00
Jacob Young
c4fcf0e22a codegen: implement lowering aligned anon decls 2023-10-21 21:38:41 -04:00
Jacob Young
4d106076c3 link: initialize llvm before calling the llvm API 2023-10-19 16:51:11 -04:00
Jakub Konka
8b4e3b6aee comp: add support for -fdata-sections 2023-10-04 11:21:56 -07:00
Jakub Konka
0134e5d2a1 codegen: separate getAnonDeclVAddr into lowerAnonDecl and the former
Implement the stub for Elf.

I believe that separating the concerns, namely, having an interface
function that is responsible for signalling the linker to lower
the anon decl only, and a separate function to obtain the decl's
vaddr is preferable since it allows us to handle codegen errors
in a simpler way.
2023-10-03 12:49:12 -07:00
Andrew Kelley
0483b4a512 link: stub out getAnonDeclVAddr 2023-10-03 12:12:51 -07:00
Jakub Konka
7a43f45908
Merge pull request #17284 from ziglang/elf-tests
elf: link against musl libc, add ELF test harness, dynamically allocate misc SHF_ALLOC sections
2023-09-27 07:39:58 +02:00
LinuxUserGD
ceaae42e90 Add '--compress-debug-sections=zstd' 2023-09-26 14:18:01 -07:00
Jakub Konka
e30f396b73 elf: properly close the output file when linking 2023-09-26 21:07:47 +02:00
Michael Dusan
ebd0776b28
kubkon review changes: 3
- make vendored settings failure unreachable
- rename field `darwinSdkLayout` → `darwin_sdk_layout`
- make `darwin_sdk_layout` optional
2023-09-25 17:07:41 -04:00
Michael Dusan
9357973912
kubkon review changes: 1
general:
- rename `DarwinSdkLayout` → `DarwinSdkLayout`
- drop `DarwinSdkLayout.installation` (not needed for darwin)
- document struct

inferSdkVersion:
- use explicit allocator
- avoid trying to infer SDK ver from vendored path
2023-09-25 15:53:05 -04:00
Michael Dusan
5d6521d281
macos: better SDK version detection
SDK version detection:
- read SDKSettings.json before inferral from SDK path
- vendored libc: add SDKSettings.json for SDK version info

resolveLibSystem:
- adjust search order to { search_dirs, { sysroot or vendored }}
- previous search order was { sysroot, search_dirs, vendored }
2023-09-25 15:53:05 -04:00
mlugg
fb6fff2561 resinator: do not include in only_core_functionality builds
This prevents resinator from being included in zig1 and zig2.
2023-09-24 06:57:11 +01:00
Ryan Liptak
2a56fe1175 Add a .rc -> .res compiler to the Zig compiler 2023-09-17 03:09:45 -07:00
Jakub Konka
65b9597c07 elf: report undefined symbols as errors 2023-09-11 16:02:21 +02:00
Jakub Konka
7a9eba2f85 elf: emit relocation to an extern function 2023-09-11 10:52:30 +02:00
Jakub Konka
a7240f0c99 macho: remove error.UnhandledDwFormValue from link.File
Eventually, we will validate DWARF info upfront and report errors
to the user but this will require a rewrite of several parts of
the linker so leaving as a TODO for the near future.
2023-08-30 22:29:27 +02:00
Jakub Konka
ebe371b757 macho: report basic __eh_frame problems as errors 2023-08-30 21:48:24 +02:00
Jakub Konka
ba710ec09d macho: remove obsolete error.FailedToResolveRelocationTarget 2023-08-30 20:34:16 +02:00
Jakub Konka
5144132320 macho: report formatted error for unhandled symbol types 2023-08-30 20:16:37 +02:00
Jakub Konka
5806e761bb macho: improve error reporting for re-exports mismatch 2023-08-30 19:02:25 +02:00
Jakub Konka
22c81740ef macho: convert error.TODOImplementWritingStaticLibFiles into an actual error 2023-08-30 12:37:05 +02:00
Jakub Konka
1b01715a73 link: remove unused darwin_sdk_version field 2023-08-29 12:02:58 +02:00
Jakub Konka
05c9d6c00b macho: add simple error reporting for misc errors 2023-08-29 11:39:34 +02:00
Jakub Konka
b73ef34289 frontend: directly pass resolved frameworks container to the linker
We can infer the framework name from the included resolved framework
path.

Fix hash implementation, and bump linker hash value from 9 to 10.
2023-08-21 08:07:44 +02:00
Jakub Konka
4793dafa04 frontend: move framework path resolution from the linker to frontend 2023-08-20 10:43:20 +02:00
Zachary Raineri
0461a64a93
change uses of std.builtin.Mode to OptimizeMode (#16745)
std.builtin.Mode is deprecated.
2023-08-09 14:39:34 -04:00
Andrew Kelley
da91ef5c28 zig libc: restore functionality on macOS
Regressed in 2006add8496c47804ee3b6c562f420871cb4ea0a.

References to native_darwin_sdk are no longer kept in the frontend.
Instead the darwin SDK is detected as part of NativePaths and as part of
LibCInstallation.
2023-08-03 09:52:15 -07:00