Commit graph

71 commits

Author SHA1 Message Date
Jakub Konka
fa30458e84 Merge pull request #13701 from ziglang/arm-win-more-features
Improve aarch64 feature detection based on the readouts from privileged system registers
2023-01-09 14:46:09 -07:00
Jakub Konka
1f61a00a41 Merge pull request #13659 from ziglang/arm-win-cpu-features
windows: add native CPU and features detection for Armv8 chips
2023-01-09 14:45:21 -07:00
Andrew Kelley
06dfa88d3f fix CPU model detection for neoverse_n1 on aarch64-linux
see #10086
2023-01-09 14:34:40 -07:00
Andrew Kelley
a0ac10d903 Merge pull request #13389 from jacobly0/fix-only-c
cbe: enough fixes for `-Donly-c` to be able to produce an executable
2022-11-02 14:11:31 -07:00
Ali Chraghi
d6943f87f9 NativeTargetInfo: remove unused error 2022-10-28 13:58:28 +02:00
Andrew Kelley
c7772dd694 std.zig.system.NativePaths: avoid calling std.os.getenv on Windows 2022-10-18 16:52:43 -07:00
dan
ca1c185eb6
std.zig: search include dir and lib dir from environment variables (#13145)
* minor fix based on feedback from @marler8997

Co-authored-by: dan <i@dan.games>
2022-10-16 11:37:35 -04:00
Ali Chraghi
0799e98562 std: update NativeTargetInfo.detect doc comments
`detect` doesn't take allocator anymore
2022-09-21 20:14:39 +03:00
Andrew Kelley
68e61bbc0c std.zig.system.NativeTargetInfo: more headroom for libc.so.6 .dynstr 2022-09-09 09:27:02 -07:00
Andrew Kelley
c7d6048081 std.zig.system.NativeTargetInfo: add fallback check
After failing to find RUNPATH in the ELF of /usr/bin/env, not finding
the answer in a symlink of the dynamic interpreter, and not finding
libc.so.6 in the same directory as the dynamic interpreter, Zig will
check `/lib/$triple`.

This fixes incorrect native glibc version detected on Debian bookworm.
2022-09-09 00:07:02 -07:00
Andrew Kelley
9f40f34501 std.zig.system.NativeTargetInfo: restore symlink logic
This is a partial revert of the previous commit, fixing a regression on
Debian. However, the commit additionally improves the
detectAbiAndDynamicLinker function to read more than 1 byte at a time
when detecting a shebang line.
2022-09-08 20:52:49 -07:00
Andrew Kelley
c668396941 std.zig.system.NativeTargetInfo: handle missing DT_RUNPATH
This commit removes the check that takes advantage of when the dynamic
linker is a symlink. Instead, it falls back on the same directory as the
dynamic linker as a de facto runpath. Empirically, this gives correct
results on Gentoo and NixOS.

Unfortunately it is still falling short for Debian, which has libc.so.6
in a different directory as the dynamic linker.
2022-09-08 20:52:49 -07:00
Andrew Kelley
1b6fa1965a stage2: fix building for 32-bit targets 2022-09-08 20:52:49 -07:00
Andrew Kelley
3ee01c14ee std.zig.system.NativeTargetInfo: detection ignores self exe
Before, native glibc and dynamic linker detection attempted to use the
executable's own binary if it was dynamically linked to answer both the
C ABI question and the dynamic linker question. However, this could be
problematic on a system that uses a RUNPATH for the compiler binary,
locking it to an older glibc version, while system binaries such as
/usr/bin/env use a newer glibc version. The problem is that libc.so.6
glibc version will match that of the system while the dynamic linker
will match that of the compiler binary. Executables with these versions
mismatching will fail to run.

Therefore, this commit changes the logic to be the same regardless of
whether the compiler binary is dynamically or statically linked. It
inspects `/usr/bin/env` as an ELF file to find the answer to these
questions, or if there is a shebang line, then it chases the referenced
file recursively. If that does not provide the answer, then the function
falls back to defaults.

This commit also solves a TODO to remove an Allocator parameter to the
detect() function.
2022-09-08 20:52:49 -07:00
Andrew Kelley
fa940bafa2 std.zig.system.NativeTargetInfo: improve glibc version detection
Previously, this code would fail to detect glibc version because it
relied on libc.so.6 being a symlink which revealed the answer. On modern
distros, this is no longer the case.

This new strategy finds the path to libc.so.6 from /usr/bin/env, then
inspects the .dynstr section of libc.so.6, looking for symbols that
start with "GLIBC_2.". It then parses those as semantic versions and
takes the maximum value as the system-native glibc version.

closes #6469
   see #11137
closes #12567
2022-09-08 20:52:49 -07:00
Martin Stuurwold
a7661f115d NativeTargetInfo.zig: fix typo 2022-09-08 01:53:32 -04:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Andrew Kelley
b975f7a56f std.Target gains ObjectFormat field 2022-08-18 18:58:28 -07:00
Eric Joldasov
b97ae88898 std.zig.system.NativeTargetInfo: look for a shebang line in /usr/bin/env, if any 2022-08-18 19:57:50 +03:00
Techatrix
79757f233d fix memory leak in NativePaths.zig 2022-08-17 19:05:39 -04:00
Veikka Tuominen
a463dc7d6c AstGen: disable null bytes and empty stings in some places
Namely:
 * test names
 * identifiers
 * library names
 * import strings
2022-07-26 12:14:59 +03:00
Jakub Konka
eb1b2f5c58 macos: add /usr/local/* paths conditional on macOS major version
`/usr/local/include`, `/usr/local/lib` and `/Library/Frameworks`
have been deprecated since approximately macOS 11, and so to avoid
redundant and misinformed warning messages generated by the linker,
add those dirs only when natively targeting macOS 10.x.x or below.
2022-07-22 14:11:23 -07:00
LeRoyce Pearson
c26d9f6287 Read dynstr starting at rpath offset
Since we know the offset, we may as well read starting there. Still expects
rpath to fit in 4096 bytes; that might be worth fixing in the future.

Fixes issue #12112
2022-07-19 14:01:35 -04:00
Andrew Kelley
d55d98919d update CPU features to LLVM 14
Notable changes:

`_i386`, `_i486`, and `_i686` are renamed to `i386`, `i486`,
and `i686` respectively. `std.zig.fmtId` is enhanced to support
formatting `i386` as `@"i386"`.

Some CPU features which are actually CPU models have been
properly flattened, such as `apple_a12`, `apple_a13`, `apple_a7`,
`cortex_a78c`, `exynos_m4`, `neoverse_e1`, `neoverse_n1`,
`neoverse_n2`, `neoverse_v1`.

Some CPU features have been added and some have been removed, following
LLVM's lead.

CSky CPU features support is added.
2022-07-01 21:35:19 -07:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Jakub Konka
9985699943 libstd: map sparcv9 to qemu-sparc64 for test-runner 2022-05-05 20:00:13 +02:00
Tom Read Cutting
cdcb34cdf4
Pull elf magic string out to re-used constant 2022-04-04 15:33:24 +03:00
Cody Tapscott
58f961f4cb stdlib: Add emulated CWD to std.os for WASI targets
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the
current working directory. The `*at(...)` functions look for this and
resolve relative paths against the stored CWD. Absolute paths are
dynamically matched against the stored Preopens.

"os.initPreopensWasi()" must be called before std.os functions will
resolve relative or absolute paths correctly. This is asserted at
runtime.

Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`,
`fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`,
and `faccessat`.

This also includes limited support for `getcwd()` and `realpath()`.
These return an error if the CWD does not correspond to a Preopen with
an absolute path. They also do not currently expand symlinks.
2022-03-03 14:31:49 -07:00
Meghan
c08b190c69
lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
Andrew Kelley
5d1aab72d9 std.zig.system: improve native glibc version detection
When the Zig compiler is statically linked, it inspects the
/usr/bin/env ELF file to determine the native glibc version, by checking
the DT_RUNPATH, and then calling readlink() on the libc.so file, because
typically the symlink will have e.g. libc-2.33.so in the name, revealing
the glibc version.

Fortunately, this information is also in readlink() of ld.so, which is
available as the "INTERP" file path. This commit looks for e.g.
`ld-2.33.so` on the symlink data for the dynamic linker.

In theory a more complete solution would also look at `/etc/ld.so.cache`
if necessary, and finally fall back to some hard coded paths, in order
to resolve the location of libc.so, in order to do this readlink() trick
on the resulting path. You can find that flow chart with `man ld.so`.
But I think this logic will be enough to get a correct answer in all real
world cases.

This has been tested on Debian Buster and glibc-based Void Linux.

Fixes #6469
2021-12-13 18:05:02 -07:00
Andrew Kelley
a3d9cd1c1d std.os: handle ETXTBSY from open() 2021-12-06 16:29:39 -07:00
Andrew Kelley
f3edff439e improve detection of how to execute binaries on the host
`getExternalExecutor` is moved from `std.zig.CrossTarget` to
`std.zig.system.NativeTargetInfo.getExternalExecutor`.

The function also now communicates a bit more information about *why*
the host is unable to execute a binary. The CLI is updated to report
this information in a useful manner.

`getExternalExecutor` is also improved to detect such patterns as:
 * x86_64 is able to execute x86 binaries
 * aarch64 is able to execute arm binaries
 * etc.

Added qemu-hexagon support to `getExternalExecutor`.

`std.Target.canExecBinaries` of is removed; callers should use the more
powerful `getExternalExecutor` instead.

Now that `zig test` tries to run the resulting binary no matter what,
this commit has a follow-up change to the build system and docgen to
utilize the `getExternalExecutor` function and pass `--test-no-exec`
in some cases to avoid getting the error.

Additionally:

 * refactor: extract NativePaths and NativeTargetInfo into their own
   files named after the structs.
 * small improvement to langref to reduce the complexity of the `callconv`
   expression in a couple examples.
2021-12-02 21:51:14 -07:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Jakub Konka
e2b6dfa608 macos: do not trigger CLT installation popup when using zig cc
On a bare macOS, when there is no CLT/Xcode installed, do not
trigger the CLT installation popup when building with zig cc.
2021-11-26 18:09:14 +01:00
Jakub Konka
8317dbd1cb macos: detect SDK path and version, then pass to the linker
Since we are already detecting the path to the native SDK,
if available, also fetch SDK's version and route that to the linker.
The linker can then use it to correctly populate LC_BUILD_VERSION
load command.
2021-11-26 16:26:44 +01:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
f8dd4b13d6 std.os reorg: more fixes caught by CI 2021-09-01 17:54:07 -07:00
jdmichaud
49c9975484
zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Jakub Konka
e9bee08f88 Try audodetecting sysroot when building Darwin on Darwin
This is now no longer limited to targeting macOS natively but also
tries to detect the sysroot when targeting different Apple platforms
from macOS; for instance targeting iPhone Simulator from macOS. In
this case, Zig will try detecting the SDK path by invoking
`xcrun --sdk iphonesimulator --show-sdk-path`, and if the command
fails because the SDK doesn't exist (case when having CLT installed only)
or not having either Xcode or CLT installed, we simply return null
signaling that the user has to provide the sysroot themselves.
2021-08-10 13:41:10 +02:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Isaac Freund
5b850d5c92
Run zig fmt on src/ and lib/std/
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-20 17:14:18 +02:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
LemonBoy
3eed613407 std: Add two more ARM CPUs to the known CPU list
Modeled after GCC's description.
2021-05-03 12:32:13 +02:00
LemonBoy
e2d2295382 std: Add many more vendors and cpus to the ARM detection list
Hand-picked from GCC and LLVM lists.
2021-05-03 12:32:13 +02:00
LemonBoy
b10d40b89b stage2: Implement CPU host detection for ARM/AArch64 targets 2021-05-03 12:32:13 +02:00
LemonBoy
da9da76e3f stage1: Implement CPU host detection for PowerPC targets
Untested but should work well on both 32 and 64 bit systems.
2021-04-27 13:11:39 -04:00
LemonBoy
7e6cc4c505 stage2: Ensure the features set is populated 2021-04-26 18:28:17 +02:00