Commit graph

124 commits

Author SHA1 Message Date
Andrew Kelley
a4380a30f5 move zig libc command to be lazily built
part of #19063

This is a prerequisite for doing the same for Resinator.
2024-02-27 22:55:00 -07:00
Andrew Kelley
ed410b9c1e lift artificial restriction on minimum glibc version
Fixes a regression introduced in
c22d1c00a8.

See #17769
2024-01-08 13:43:10 -07:00
Andrew Kelley
362460ec24 minor cosmetic fixups
* fix typos and redundancies in docs
* use Target.isGnuLibc
2024-01-04 17:26:06 -07:00
Pat Tullmann
c22d1c00a8 src/target: Restrict usable glibc versions
At a minimum required glibc is v2.17, as earlier versions do not define
some symbols (e.g., getauxval()) used by the Zig standard library.

Additionally, glibc only supports some architectures at more recent
versions (e.g., riscv64 support came in glibc v2.27).  So add a
`glibc_min` field to `available_libcs` for architectures with stronger
version requirements.

Extend the existing `canBuildLibC` function to check the target against
the Zig minimum, and the architecture/os minimum.

Also filter the list shown by `zig targets`, too:

  $ zig targets | jq -c '.glibc'
  ["2.17.0","2.18.0","2.19.0","2.20.0","2.21.0","2.22.0","2.23.0","2.24.0","2.25.0","2.26.0","2.27.0","2.28.0","2.29.0","2.30.0","2.31.0","2.32.0","2.33.0","2.34.0","2.35.0","2.36.0","2.37.0","2.38.0"]

Fixes #17034
Fixes #17769
2024-01-04 17:12:07 -07:00
Andrew Kelley
e47141a14e frontend: fix incorrect WebAssembly hasDebugInfo=false 2024-01-01 19:49:08 -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
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
a3ff4d9b45 fix entry symbol name on mips 2024-01-01 17:51:20 -07:00
Andrew Kelley
43720be04a frontend: fix stack protector option logic
Commit 97e23896a9 regressed this behavior
because it made target_util.supportsStackProtector *correctly*
notice which zig backend is being used to generate code, while the
logic calling that function *incorrectly assumed* that .zig code is being
compiled, when in reality it might be only C code being compiled.

This commit adjusts the option resolution logic for stack protector so
that it takes into account the zig backend only if there is a zig
compilation unit. A separate piece of logic checks whether clang
supports stack protector for a given target.

closes #18009
closes #18114
closes #18254
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
134e8cf76a move is_libcpp_lib_name and is_libc_lib_name to std.Target 2024-01-01 17:51:18 -07:00
Jakub Konka
f34247c4bc elf: lower TLS data into appropriate TLS section 2023-11-12 18:12:40 -05:00
Andrew Kelley
53f74d6a04 move libssp into libcompiler_rt
closes #7265
2023-11-10 13:12:10 -07:00
Andrew Kelley
e74ced21b7 frontend: fix -fsingle-threaded default detection logic
The logic in 509be7cf1f assumed that
`use_llvm` meant that the LLVM backend would be used, however, use_llvm
is false when there are no zig files to compile, which is the case for
zig cc. This logic resulted in `-fsingle-threaded` which made libc++
fail to compile for C++ code that includes the threading abstractions
(such as LLVM).
2023-11-06 01:16:09 -05:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Michael Dusan
50f2d79582
macos: update libc names for darwin
- dropped incorrect names
- added list of names found in the SDKs
- ios, tvos and watchos filesystems are case-sensitive
2023-09-25 15:53:05 -04:00
Michael Dusan
15fd7cd154
macos: vendored libc: combine headers: part 2
- update include dirs to use combined dir
- use one libSystem.tbd (drop use of libSystem.VERSION.tbd)
- update canBuildLibC to check for minimum os version only
2023-09-25 15:53:05 -04:00
Andrew Kelley
accd5701c2 compiler: move struct types into InternPool proper
Structs were previously using `SegmentedList` to be given indexes, but
were not actually backed by the InternPool arrays.

After this, the only remaining uses of `SegmentedList` in the compiler
are `Module.Decl` and `Module.Namespace`. Once those last two are
migrated to become backed by InternPool arrays as well, we can introduce
state serialization via writing these arrays to disk all at once.

Unfortunately there are a lot of source code locations that touch the
struct type API, so this commit is still work-in-progress. Once I get it
compiling and passing the test suite, I can provide some interesting
data points such as how it affected the InternPool memory size and
performance comparison against master branch.

I also couldn't resist migrating over a bunch of alignment API over to
use the log2 Alignment type rather than a mismash of u32 and u64 byte
units with 0 meaning something implicitly different and special at every
location. Turns out you can do all the math you need directly on the
log2 representation of alignments.
2023-09-21 14:48:40 -07: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
256074428f frontend: update is_libc_lib_name for mingw-w64 crt files 2023-08-03 09:52:14 -07:00
kcbanner
661028a907 target: emit unwind tables if the platform supports unwinding 2023-07-26 20:58:29 -04:00
kcbanner
ec96095efd compilation: pass omit_frame_pointer through to builtin.zig
Renamed dwarf_unwinding -> stack_iterator to better reflect that it's not just DWARF unwinding.
Added a test for unwinding with a frame pointer.
2023-07-20 22:58:16 -04:00
kcbanner
891fa3b8b5 debug: fix initialization of the optional fields on StackIterator
dwarf: documentation fixups
target: enable unwind tables on macho
2023-07-20 22:58:15 -04:00
Luuk de Gram
87b8a0567b
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build
as threads are still experimental. The user however can enable a multi-
threaded build by specifying '-fno-single-threaded'. It's a compile-error
to enable this flag, but not also enable shared-memory.
2023-06-26 20:00:58 +02:00
Luuk de Gram
062eb6f3c0
Compilation: allow threads for Wasm when shared-memory is enabled
When the user enabled the linker-feature 'shared-memory' we do not force
a singlethreaded build. The linker already verifies all other CPU features
required for threads are enabled. This is true for both WASI and
freestanding.
2023-06-26 20:00:57 +02:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
Andrew Kelley
17882162b3 stage2: move function types to InternPool 2023-06-10 20:47:53 -07:00
Andrew Kelley
9aec2758cc stage2: start the InternPool transition
Instead of doing everything at once which is a hopelessly large task,
this introduces a piecemeal transition that can be done in small
increments at a time.

This is a minimal changeset that keeps the compiler compiling. It only
uses the InternPool for a small set of types.

Behavior tests are not passing.

Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but
compile-time verified to have the same fields in the same order.

The large set of changes is mainly to deal with the fact that most Type
and Value methods now require a Module to be passed in, so that the
InternPool object can be accessed.
2023-06-10 20:40:03 -07:00
Jacob Young
d56c6c7791 cbe: implement 128-bit atomics support
* Disable 128-bit atomics for x86_64 generic (currently also baseline)
   because they require heavy abi agreement to correctly lower.
   ** This is a breaking change **
 * Enable 128-bit atomics for aarch64 in Sema since it just works.
2023-04-21 16:36:31 -04:00
Eric Rowley
a774f93344 Do not use -fPIC when compiling a UEFI application 2023-04-21 08:22:27 +03:00
Piotr Sikora
cb54e9a3c2 glibc: allow linking against external libcrypt.
Support for the built-in libcrypt was removed in commit 6b7ddfba,
but the -lcrypt flag remained ignored, preventing linking against
external libcrypt.

Fixes #5990.

Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2023-04-10 20:04:29 -04:00
Robin Voetter
ba60d456b4
spirv: cannot build libc
SPIR-V cannot build libc, ssp, compiler-rt, etc at the time of this commit, so
prevent trying to build them.
2023-04-09 01:51:48 +02:00
Andrew Kelley
df4cfc2ecf Merge remote-tracking branch 'origin/master' into llvm16 2023-03-03 12:08:18 -07:00
Eckhart Köppen
6be5946ed8 sema: Place functions on AVR in flash addrspace
- Use .flash as the default address space for functions on AVR
- Return .flash as the address space for function pointers on AVR
  without explicit address space
2023-03-03 15:20:31 +02:00
Andrew Kelley
d399f8a489 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-27 16:10:48 -07:00
Jacob Young
a0d7fd162b CBE: support call attributes
* Support always_tail and never_tail/never_inline with a comptime callee using clang
 * Support never_inline using gcc
 * Support never_inline using msvc

Unfortunately, can't enable behavior tests because of the conditional support.
2023-02-23 10:54:26 -05:00
Andrew Kelley
0ca3582a86 update CPU features to LLVM 16 2023-01-26 16:36:14 -07:00
Andrew Kelley
34887cf136 powerpc does not have a red zone
This will prevent unused argument warnings when compiling C objects
targeting powerpc.
2022-12-29 00:19:00 -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
Frank Denis
817cf6a82e
Update wasi-libc to 8b7148f69ae241a2749b3defe4606da8143b72e0 (#13793) 2022-12-06 22:48:35 +00:00
Andrew Kelley
4ec27a4e25 C backend: implement vector reduce and overflow intrinsics 2022-11-22 23:33:58 -07:00
Andrew Kelley
78389af552 LLVM: add valgrind integration for x86 and aarch64
This also modifies the inline assembly to be more optimizable - instead of
doing explicit movs, we instead communicate to LLVM which registers we
would like to, somehow, have the correct values. This is how the x86_64
code already worked and thus allows the code to be unified across the
two architectures.

As a bonus, I threw in x86 support.
2022-11-19 19:32:45 -07:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Jakub Konka
453a2d2fad darwin: remove 10.15.7 as available libc from src/target.zig 2022-10-26 08:53:33 +02:00
Jakub Konka
98285b17b3 darwin: bump max macOS version to 13.0 2022-10-25 20:31:31 +02:00
Guillaume Wenzek
577f0aa54b addrSpaceCastIsValid nvptx 2022-10-15 10:39:19 -07:00
Guillaume Wenzek
aad983cf40 sanitize qualified name for nvptx backend 2022-10-15 10:39:19 -07:00
Guillaume Wenzek
b3dc80a1e3 disable debug info for ptx<7.5 2022-10-15 10:39:19 -07:00
Robin Voetter
9f14681473
stage2: check address space cast validity 2022-10-12 20:36:14 +02:00