5660 Commits

Author SHA1 Message Date
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
Dan Ellis Echavarria
924679abc4
std.simd: change T to u16
The `element_bit_size` would break if `T` was signed due to `ceilPowerOfTwo` only working on unsigned numbers.
2022-09-07 15:22:30 +03:00
Yujiri
ae3a5ff7f9 Fix #12440: std.math.big.Rational order/orderAbs 2022-09-04 18:45:20 +03:00
yujiri8
10e11b60e5
zig fmt: don't delete container doc comments
Fixes #12617
2022-09-02 20:12:20 +02:00
riChar
0d96f1f4fb
zig fmt: remove trailing comma at the end of assembly clobber 2022-09-02 12:52:33 +03:00
John Schmidt
36f4f32fad
Add AFNOSUPPORT error to bind (#12560) 2022-09-01 15:13:07 -05:00
Jakub Konka
540d8cd809 coff: add import table definitions 2022-08-31 19:30:51 +02:00
Hashi364
973b440561 Using comptime level.asText() in log example
Some recent change makes slice concatenation runtime (merge #12368), so the example needs to be explicitly made comptime.
2022-08-31 16:01:35 +03:00
Evan Haas
fdb8870852 translate-c: promote large integer macros to unsigned long long if necessary
Closes #10793

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-31 15:52:53 +03:00
biexelar
59e33b447b
std.Thread: fix freeAndExit on x86_64-linux (#12693)
Previously, this function used incorrect registers for the munmap syscall, leading to detached threads not cleaning up.

closes #12690

Co-authored-by: bxlr <biexelar@diroot.org>
2022-08-30 22:31:47 -04:00
Jakub Konka
d3eaabd285 coff: add base relocation related types 2022-08-30 23:07:28 +02:00
Jakub Konka
aa5568beb6 coff: move Symtab and Strtab out of coff.Coff
This should ease interfacing with different std.coff functionalities.
2022-08-30 15:51:49 +02:00
Jakub Konka
7ef0c9d298
Merge pull request #12677 from ziglang/coff-linker
coff: initial rewrite of the COFF/PE linker
2022-08-30 14:29:41 +02:00
Jakub Konka
69d6931be7
Merge pull request #12662 from wsengir/coff-fix
coff: fix reading COFF header offset
2022-08-30 12:26:35 +02:00
Veikka Tuominen
e6be6d9768 std.rand: make weightedIndex proportions param a const slice
The function does not mutate the proportions and the signature should reflect that.
2022-08-30 13:02:17 +03:00
Jakub Konka
db1a3bb0e7 coff: fallback to _start as default entry point for now
This is not technically correct, but given that we are not yet able
to link against the CRT, it's a good default until then.

Add basic logging of generated symbol table in the linker.
2022-08-30 10:42:21 +02:00
Jakub Konka
30baba899c coff: add missing bits required for minimal PE example 2022-08-30 10:42:21 +02:00
Jakub Konka
ed481e3837 coff: write headers to file 2022-08-30 10:42:21 +02:00
Jakub Konka
90b3599c68 coff: reorganize the linker 2022-08-30 10:42:21 +02:00
Jakub Konka
06371950cf start: allow for explicitly defined entry point for Win 2022-08-30 10:42:21 +02:00
William Sengir
91b9f295d3
coff: publicize and flesh out more image constants 2022-08-28 06:20:18 -07:00
Justin Whear
5bb8c03697
std.random: add weightedIndex function
`weightedIndex` picks from a selection of weighted indices.
2022-08-28 14:19:51 +03:00
William Sengir
3860e664c5
coff: fix reading COFF header offset 2022-08-28 03:10:39 -07:00
antlilja
ae8d26a6a0 Sema: add error for non-comptime param in comptime func
Adds error for taking a non comptime parameter in a function returning a
comptime-only type but not when that type is dependent on a parameter.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-27 11:17:48 +03:00
Sébastien Marie
8bcb962ada openbsd: fix sigcontext struct and avoid defining fxsave64
`sc_fpstate` member of `struct sigcontext` is a `struct fxsave64 *`.
use *anyopaque to represent it.

avoid to defining `fxsave64` as it is a packed struct with some arrays.
2022-08-26 17:30:07 +02:00
Jakub Konka
02e6960966 coff: do not pull in std.log into coff.zig definitions 2022-08-26 16:14:44 +02:00
Motiejus Jakštys
9038528187 copy_file_range: fix zigification of TXTBSY
From `copy_file_range(2)` errors:

    ETXTBSY
           Either fd_in or fd_out refers to an active swap file.

Same error will be used in the upcoming `ioctl_ficlonerange(2)`:

    ETXTBSY
           One of the files is a swap file.  Swap files cannot share storage.
2022-08-26 15:36:40 +03:00
Andrew Kelley
7453f56e67 stage2: explicitly tagged enums no longer have one possible value
Previously, Zig had inconsistent semantics for an enum like this:

`enum(u8){zero = 0}`

Although in theory this can only hold one possible value, the tag
`zero`, Zig no longer will treat the type this way. It will do loads and
stores, as if the type has runtime bits.

Closes #12619

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-24 22:20:31 -07:00
Jonas Gollenz
07afd5bdba docs: remove confusion about align[For|Back]ward 2022-08-24 17:18:29 -04:00
max
d8e22fcb20 fix coff.zig with const qualifier convert problem 2022-08-24 22:49:47 +02:00
Sébastien Marie
397099b7ee pthread_key_create: make it build with stage2 2022-08-24 16:35:01 -04:00
Andrew Kelley
2a96209c40
Merge pull request #12574 from Vexu/remove-bit-op-type-param
stage2+stage1: remove type parameter from bit builtins
2022-08-24 15:57:44 -04:00
Felix "xq" Queißner
b466f8c817 Enables std.build.TranslateCStep to use stage1/stage2 selectively. Unbreaks projects using stage1 and manual TranslateC 2022-08-24 15:41:27 -04:00
Felix "xq" Queißner
5696cc8ab6 Adds std.meta.FnPtr for easier stage1/stage2 compatibility 2022-08-24 03:13:44 -04:00
Andrew Kelley
5db80a051f Revert "std.os: add INVALID_SOCKET (#12081)"
This reverts commit 0f01e812ff054ea83661272bf0a96af228f2ffe3.

This does not belong in `std.posix`, and it is already provided at
`std.os.windows.ws2_32.INVALID_SOCKET`.

See related issue #5019.
2022-08-23 21:30:23 -07:00
Andrew Kelley
60722261fa std.debug: DWARFv5 fixes
handle str_offsets_base and addr_base correctly.
handle data16
fix compilation on 32-bit hosts
remove stray debug print statement

closes #12120
2022-08-23 21:11:02 -07:00
yyny
0f01e812ff
std.os: add INVALID_SOCKET (#12081)
This constant returns an invalid `socket_t` that can be used as a sentinel
value.
2022-08-23 19:44:42 -05:00
Jakub Konka
f907f74282 coff: fix compile errors in std.debug 2022-08-23 22:01:05 +02:00
Jakub Konka
cf9f6fd7f0 macho: fix compile errors in std.debug 2022-08-23 22:01:05 +02:00
Andrew Kelley
1ce71c86bf std.debug: implement support for DWARFv5 2022-08-23 00:28:45 -07:00
Jakub Konka
c84e5ee878 coff: improve default COFF/PE object parser
We now do not allocate memory for headers and other metadata unless
requested by the caller. Instead, we read-in the entire contents
of the image into memory and operate on pointers and casts wherever
possible. I have a left a TODO to hook up Windows' memory-mapped API
here in-place of standard `readToEndAlloc` which should be more memory
proof on memory constrained hosts.

This commit also supplements our `std.coff` with a lot missing basic
extern structs required to make our COFF linker.
2022-08-23 08:55:04 +02:00
Ryan Liptak
95c43e20b4 Windows: Fix incorrect output when .pdb file is not found during stack trace
This `pdb.Pdb.init` call can return `error.FileNotFound`, which was previously resulting in:

    Unable to print stack trace: FileNotFound

which also aborts the stack trace printing (so any deeper stack traces are not printed).

It makes more sense to treat it as `MissingDebugInfo` which then gets printed as:

    ???:?:?: 0x7fffa8817033 in ??? (???)

and allows the stack trace to continue printing.

Note: locally, the error.FileNotFound was being triggered for me when looking for kernel32.pdb and ntdll.pdb
2022-08-22 20:51:55 -04:00
Keith Chambers
96737ef499
Dwarf: Added stroffsetsptr support (#12270)
* Added support for stroffsetsptr class in Dwarf stdlib

* Proper initializion of debug_str_offsets in DwarfInfo

* Added missing null initializer to DwarfInfo in Macho

* Added missing is_64 field to getAttrString in DwarfInfo

* Fixed formatting

* Added missing is_64 param to getAttrString

* Added required cast to usize

* Adding missing .debug_str_offsets initialization

* getAttrString now uses the str_offsets_base attr
2022-08-22 20:50:06 -04:00
Andrew Kelley
ecdd4a9fe8 build system: add flag for -fstack-protector 2022-08-22 15:11:34 -07:00
Veikka Tuominen
8667d6d61e
Merge pull request #12563 from Vexu/stage2-fixes
Stage2 fixes
2022-08-22 14:32:31 +03:00
InKryption
f1999712b0 std.io.Reader: bounded array functions
* Add readIntoBoundedBytes
 * Add readBoundedBytes
2022-08-22 14:07:22 +03:00
Justas Zabulionis
24d718e7eb
std.valgrind.callgrind: fix string type
Fixes the error when using std.vallgrind.callgrind:
error: expected type '[2]u8', found '*const [2:0]u8'
2022-08-22 13:55:00 +03: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