Commit Graph

20161 Commits

Author SHA1 Message Date
Shane Kennedy
c97d64b677 chore: Remove unused constants 2022-09-11 23:18:43 -04:00
Andrew Kelley
349df40d14
Merge pull request #12814 from ziglang/native-libc-integration
stage2: no condition on system libs to link native libc
2022-09-11 23:12:50 -04:00
Andrew Kelley
65bea514ae Compilation: handle system C compiler not found
When linking libc and compiling natively, Zig tries to integrate with
the system C compiler. However, this caused Zig to fail when no system C
compiler is installed, despite the fact that Zig is perfectly capable of
compiling & linking libc without one.

This commit makes Zig fall back to using its own ability to provide libc
in the case that no C compiler is installed. For glibc, it means
sometimes getting the warning "zig cannot build new glibc version abc,
providing instead xyz".

Ideally, Zig would do some more validation about the system libraries
being linked against, and report an error in case it could not provide
the exact correct libc version of the system libraries (or that the
system libraries themselves conflict with each other), however, I think
it is fair to call that a separate enhancement.
2022-09-11 16:37:03 -07:00
Loris Cro
60678f5baf autodoc: fix regression in frontend rendering of values 2022-09-11 23:45:18 +02:00
Andrew Kelley
aec0e595f2 stage2: no condition on system libs to link native libc
Before, Zig tried to use its own libc files (e.g. glibc) when there were
no system libs being linked. This prevented building against native
glibc on systems that have newer glibc than the ones Zig provides.

Closes #12797
2022-09-11 13:39:58 -07:00
Loris Cro
2a96f80d03 autodoc: reduce json payload size
this commit removes whitespace and changes Decl, AstNode and Type to be
json arrays instead of json objects. This change reduces json payload
size for the stdlib from 25mb to < 10mb.
2022-09-11 21:35:01 +02:00
Loris Cro
81939a4939 autodoc: remove unnecessary string copy 2022-09-10 17:31:42 +02:00
Jakub Konka
4fd4c733d4 x86_64: pass more behavior tests 2022-09-10 09:23:26 +02:00
Jakub Konka
5778077f9f
Merge pull request #12799 from joachimschmidt557/stage2-arm
stage2 ARM: introduce allocRegs mechanism and other improvements
2022-09-10 09:13:08 +02:00
Jakub Konka
69da56b36c
Merge pull request #12802 from ziglang/macho-refactor
Self-hosted backends and linkers refactor: x86_64 + aarch64 + macho + coff
2022-09-10 09:07:07 +02:00
Jakub Konka
a1b8545265 coff: remove unused function 2022-09-10 00:59:46 +02:00
Jakub Konka
0824808444 macho: refactor direct use of locals container in favour of helpers 2022-09-10 00:58:16 +02:00
Jakub Konka
485d8819b3 aarch64: update codegen to using a global index rather than local index 2022-09-10 00:57:54 +02:00
Jacob Young
5b9c5191ab type: print comptime on fn type params
This avoids the following confusing error message:

    error: expected type 'fn(i32, i32) void', found 'fn(i32, i32) void'
2022-09-10 01:55:52 +03:00
Evan Haas
8e631ee3e7 translate-c: Escape non-ASCII characters that appear in macros
Macro definitions are simply a slice of bytes, which may not be
UTF-8 encoded. If they are not UTF-8 encoded, escape non-printable
and non-ASCII characters as `\xNN`.

Fixes #12784
2022-09-10 01:50:17 +03:00
Jakub Konka
fc5a6e0e32 x86_64: combine got_load, direct_load and imports_load into linker_load MCV 2022-09-10 00:18:39 +02:00
Jakub Konka
d8f2103545 macho+coff: return index into global table from getGlobalSymbol 2022-09-09 23:30:31 +02:00
Jakub Konka
bac065c7cf coff: use global accessor abstractions from MachO 2022-09-09 22:29:50 +02:00
Jakub Konka
8d44e03161 macho: use globals free list like in COFF linker 2022-09-09 22:10:27 +02:00
joachimschmidt557
94499898e5
stage2 ARM: implement basic array_elem_val 2022-09-09 20:26:04 +02:00
joachimschmidt557
b976997e16
stage2 ARM: implement ptr_elem_val 2022-09-09 19:17:18 +02:00
joachimschmidt557
a0a7d15142
stage2 ARM: support larger function stacks
This is done by introducing a new Mir pseudo-instruction
2022-09-09 19:17:18 +02:00
joachimschmidt557
3794f2c493
stage2 ARM: implement struct_field_val for registers 2022-09-09 19:17:18 +02:00
joachimschmidt557
25729d6155
stage2 ARM: fix multiple uses of reuseOperand
- add missing checks whether destination fits into the operand
- remove reuseOperand invocations from airIsNullPtr and similar
  functions as we need to load the operands into temporary locations
2022-09-09 19:17:18 +02:00
joachimschmidt557
261fec8036
stage2 ARM: amend implementation of various AIR instructions
- unwrap_errunion_err for registers
- unwrap_errunion_payload for registers
- ptr_slice_len_ptr for all MCValues
- ptr_slice_ptr_ptr for all MCValues
2022-09-09 19:17:17 +02:00
joachimschmidt557
e2b029e2c8
stage2 ARM: implement field_parent_ptr 2022-09-09 19:17:17 +02:00
joachimschmidt557
481bd4761a
stage2 ARM: remove remaining uses of binOp{Register,Immediate} 2022-09-09 19:17:17 +02:00
joachimschmidt557
95b8a5f157
stage2 ARM: extract remaining operations out of binOp 2022-09-09 19:17:17 +02:00
joachimschmidt557
fdb2c80bdc
stage2 ARM: extract mul, div, and mod out of binOp 2022-09-09 19:17:17 +02:00
joachimschmidt557
ed4be06883
stage2 ARM: extract add+sub from binOp
This commit also lays the groundwork for further extractions from
binOp.
2022-09-09 19:17:17 +02:00
joachimschmidt557
86dd123392
stage2 ARM: move cmp to new allocReg mechanism; remove from binOp 2022-09-09 19:17:17 +02:00
joachimschmidt557
0414ef591a
stage2 ARM: introduce allocRegs
This new register allocation mechanism which is designed to be more
generic and flexible will replace binOp.
2022-09-09 19:17:16 +02:00
joachimschmidt557
28cc363947
stage2 ARM: improve Mir representation of mov and cmp 2022-09-09 19:17:13 +02:00
Andrew Kelley
9e070b653c
Merge pull request #12788 from ziglang/detect-native-glibc
std.zig.system.NativeTargetInfo: improve glibc version and dynamic linker detection
2022-09-09 12:28:25 -04:00
Andrew Kelley
68e61bbc0c std.zig.system.NativeTargetInfo: more headroom for libc.so.6 .dynstr 2022-09-09 09:27:02 -07:00
Yusuf Bham
c9f145a50b std.os.uefi: mark BlockIoProtocol and EfiBlockMedia as public 2022-09-09 16:48:54 +03:00
Jakub Konka
56b96cd61b
Merge pull request #12772 from ziglang/coff-basic-imports
coff: implement enough of the incremental linker to pass behavior and incremental tests on Windows
2022-09-09 13:08:58 +02: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
Jakub Konka
5006fb6846 macho: fix compilation for 32bit targets 2022-09-09 08:30:27 +02: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
Motiejus Jakštys
a833bdcd7e [ld] add --print-* for diagnostics
This adds the following for passthrough to lld:
- `--print-gc-sections`
- `--print-icf-sections`
- `--print-map`

I am not adding these to the cache manifest, since it does not change
the produced artifacts.

Tested with an example from #11398: it successfully prints the resulting
map and the GC'd sections.
2022-09-08 22:30:32 -04:00
Jakub Konka
8378cde743 macho: prefill any space between __DATA and __LINKEDIT with 0s if required
If there are zerofill sections, the loader may copy the contents of
the physical space in file directly into memory and attach that to
the zerofill section. This is a performance optimisation in the loader
but requires us, the linker, to properly zero-out any space between
__DATA and __LINKEDIT segments in file. This is of course completely
skipped if there are no zerofill sections present.
2022-09-09 00:01:22 +02:00
Luuk de Gram
ab4b26d8a6
Merge pull request #12770 from Luukdegram/wasm-dwarf
wasm-linker: implement linking debug-information
2022-09-08 16:57:23 +02:00
Veikka Tuominen
6a62a15ecd
Merge pull request #12773 from Vexu/stage2-fixes
Sema: fix UAF in zirClosureGet
2022-09-08 16:43:54 +03:00
Jakub Konka
0ae2ea671b wasm: temporarily save curr file pointer before pwriting on Win
This is a temporary workaround to an unclear platform-dependence
behavior we have in libstd for `std.fs.File` abstraction. See
https://github.com/ziglang/zig/issues/12783 for more information.
2022-09-08 14:29:54 +02:00
Veikka Tuominen
c7e45aebaf llvm: handle pointers in packed structs in more places
Closes #12776
2022-09-08 12:51:40 +03:00