236 Commits

Author SHA1 Message Date
Pat Tullmann
120c4789c3 sigset_t: sigemptyset() and sigfillset() are functions that return sigset_t
By returning an initialized sigset (instead of taking the set as an output
parameter), these functions can be used to directly initialize the `mask`
parameter of a `Sigaction` instance.
2025-04-30 20:32:04 -07:00
Pat Tullmann
f0aefa625b posix: remove empty_sigset
When linking a libc, Zig should defer to the C library for sigset
operations.  The pre-filled constants signal sets (empty_sigset,
filled_sigset) are not compatible with C library initialization, so remove
them and use the runtime `sigemptyset` and `sigfillset` methods to
initialize any sigset.
2025-04-30 20:32:04 -07:00
Alex Rønne Petersen
4b5941c54b
start: Reduce stack alignment for hexagon.
The ABI requires 8-byte alignment, not 16.
2025-04-07 13:09:10 +02:00
Alex Rønne Petersen
d3bf6c518f
start: Align the stack on m68k. 2025-04-07 13:09:10 +02:00
Stefan Weigl-Bosker
8fea9f68e8
start: fix pc register syntax for m68k 2025-04-07 13:09:10 +02:00
Carmen
9720bade7a
std.start: allow return uefi error union in main (#23425) 2025-04-01 17:10:10 +00:00
Andrew Kelley
284de7d957 adjust runtime page size APIs
* fix merge conflicts
* rename the declarations
* reword documentation
* extract FixedBufferAllocator to separate file
* take advantage of locals
* remove the assertion about max alignment in Allocator API, leaving it
  Allocator implementation defined
* fix non-inline function call in start logic

The GeneralPurposeAllocator implementation is totally broken because it
uses global state but I didn't address that in this commit.
2025-02-06 14:23:23 -08:00
Archbirdplus
439667be04 runtime page size detection
heap.zig: define new default page sizes
heap.zig: add min/max_page_size and their options
lib/std/c: add miscellaneous declarations
heap.zig: add pageSize() and its options
switch to new page sizes, especially in GPA/stdlib
mem.zig: remove page_size
2025-02-06 14:23:23 -08:00
Alex Rønne Petersen
4de661ef18
start: Don't emit CFI directives if unwind tables are disabled. 2025-01-19 02:15:30 +01:00
Alex Rønne Petersen
7d00877076
start: Extend DWARF unwinding protection to more architectures.
The function is not marked .cantunwind for Arm/Thumb because of an LLVM
assembler bug: https://github.com/llvm/llvm-project/issues/115891
2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
43b6bd4243
start: Zero the link and frame pointer registers on all architectures. 2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
3054486d1d
Merge pull request #21843 from alexrp/callconv-followup
Some follow-up work for #21697
2024-11-03 14:27:09 +01:00
Alex Rønne Petersen
c9e67e71c1
std.Target: Replace isARM() with isArmOrThumb() and rename it to isArm().
The old isARM() function was a portability trap. With the name it had, it seemed
like the obviously correct function to use, but it didn't include Thumb. In the
vast majority of cases where someone wants to ask "is the target Arm?", Thumb
*should* be included.

There are exactly 3 cases in the codebase where we do actually need to exclude
Thumb, although one of those is in Aro and mirrors a check in Clang that is
itself likely a bug. These rare cases can just add an extra isThumb() check.
2024-11-03 09:29:30 +01:00
Alex Rønne Petersen
82e82b6267
start: Fix callconv for the wWinMainCRTStartup symbol.
This just uses the C calling convention in the vcruntime sources.
2024-11-02 10:44:18 +01:00
Alex Rønne Petersen
8a2d960627
start: Fix a calling convention check to use eql().
Also modernize some callconv uses.

Closes #21813.
2024-11-02 10:44:18 +01:00
Robin Voetter
9b42bc1ce5
spirv: start.zig support for vulkan
* Use builtin.zig_backend instead of builtin.cpu.arch, the latter
  does not yet compile under VK.
* Don't call regular _start for either opencl or vulkan. We might
  even want to disable these completely.
2024-10-27 14:20:52 +01:00
mlugg
bc797a97b1
std: update for new CallingConvention
The old `CallingConvention` type is replaced with the new
`NewCallingConvention`. References to `NewCallingConvention` in the
compiler are updated accordingly. In addition, a few parts of the
standard library are updated to use the new type correctly.
2024-10-19 19:15:23 +01:00
Michael Dusan
665d0157d5
std ppc64: add nop to start inline-asm
fixes ld.lld error: call to save_start.posixCallMainAndExit lacks nop, can't restore toc
2024-10-05 10:27:13 -04:00
Alex Rønne Petersen
038e002b1c
Merge pull request #21527 from alexrp/elf-emulations
`link.Elf`: Make `getLDMOption()` exhaustive with regards to LLD's `parseEmulation()`.
2024-10-02 23:22:44 +02:00
Michael Ortmann
3b465ebec5
std.start: dont query stack limit for wanted stack size 0 (#21533) 2024-09-28 23:06:28 -07:00
Alex Rønne Petersen
59ae51199e
std.Target: Return EM_ARC_COMPACT instead of EM_ARC_COMPACT2 for arc.
Also fix an incorrect related comment in start.zig.
2024-09-26 21:45:49 +02:00
Alex Rønne Petersen
b56a667ecd start: Rewrite arm code to work for thumb1 too.
0ecc6332b4eb1ced547ffa38f57471134aaa4d13 improved things for thumb2, but thumb1
has a much smaller permissible instruction set. This commit makes that work.
2024-09-12 20:10:45 -07:00
Alex Rønne Petersen
0ecc6332b4
start: Fix arm stack alignment code to work for thumb too. 2024-08-31 03:38:35 +02:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Jacob Young
f289b82d0e Dwarf: implement .eh_frame 2024-08-27 03:55:56 -04:00
mlugg
a3a737e9a6
lib,test,tools,doc: update usages of @export 2024-08-27 00:44:35 +01:00
Alex Rønne Petersen
ab9628dd2c
start: Avoid concatenating strings for inline asm.
For csky, we can just always do the gb initialization. For riscv, the gp code is
temporarily pulled above the main switch until the blocking issue is resolved.
2024-08-15 10:56:32 +02:00
Jacob Young
5d080e25d5 start: fix passing comptime-only value to inline asm
Also fix fmt directive typo.
2024-08-15 04:42:04 -04:00
Andrew Kelley
8184912a98
Merge pull request #20925 from alexrp/windows-tls
`std`: Some Windows TLS cleanup and fixes
2024-08-07 01:12:11 -07:00
Alex Rønne Petersen
c0681d6b6e start: Add sparc32 support. 2024-08-07 01:09:18 -07:00
Alex Rønne Petersen
8056a85151
std: Move start_windows_tls.zig to os/windows/tls.zig.
Just to be consistent with Linux.
2024-08-03 20:35:08 +02:00
Alex Rønne Petersen
a9c7818512
start: Fix an isARM() check to use isArmOrThumb() instead. 2024-08-01 20:58:08 +02:00
Andrew Kelley
7a0da805a8
Merge pull request #20797 from alexrp/start-more-arches
`start`: Add POSIX arc, csky, and hexagon support
2024-08-01 01:34:33 -07:00
Andrew Kelley
91163b44dd
Merge pull request #20857 from alexrp/tls-porting
`std.os.linux.tls`: Refactor, improve documentation, fix a bug, and port to more architectures
2024-08-01 01:15:17 -07:00
Andrew Kelley
63aa85e7af
Merge pull request #20872 from alexrp/riscv-gp
start: Initialize `gp` to `__global_pointer$` on riscv.
2024-08-01 00:47:05 -07:00
David Rubin
2b8a71489a
start: remove riscv condition 2024-07-31 13:40:00 -07:00
Alex Rønne Petersen
653eb75355
start: Disable the gp initialization code for the self-hosted riscv64 backend. 2024-07-31 02:06:57 +02:00
Alex Rønne Petersen
982510f8d5
start: Initialize gp to __global_pointer$ on riscv. 2024-07-31 02:05:17 +02:00
Alex Rønne Petersen
78e581b86f
start: Copy the mips64 comment about gp to the mips32 code.
Also, don't incorrectly claim that it's only needed for dynamic linking/PIC.
2024-07-30 17:58:22 +02:00
Alex Rønne Petersen
108c682df0
start: Add POSIX csky support. 2024-07-30 17:47:46 +02:00
Andrew Kelley
f219286573
Merge pull request #20852 from ziglang/init-array-start-code
start code: implement __init_array_start, __init_array_end
2024-07-29 18:40:27 -07:00
Alex Rønne Petersen
b52e054261
std.os.linux.tls: Refactor and improve documentation.
* Elaborate on the sub-variants of Variant I.
* Clarify the use of the TCB term.
* Rename a bunch of stuff to be more accurate/descriptive.
* Follow Zig's style around namespacing more.
* Use a structure for the ABI TCB.

No functional change intended.
2024-07-30 02:32:32 +02:00
Andrew Kelley
38e0f049c5
Merge pull request #20389 from alexrp/riscv32
Some `riscv32-linux` porting work
2024-07-29 16:13:35 -07:00
Andrew Kelley
7342017404
Merge pull request #20822 from alexrp/start-mips-fixes
`start`: A handful of MIPS fixes
2024-07-29 12:02:59 -07:00
Andrew Kelley
3f2d1b17fc disable the new code for self-hosted riscv backend 2024-07-29 11:38:11 -07:00
Alex Rønne Petersen
d633b35f35
start: Always inline the call to std.os.linux.pie.relocate().
At this stage, we're not ready to make calls yet on some architectures (e.g. MIPS).
2024-07-29 10:08:34 +02:00
Alex Rønne Petersen
d6c637c36b
start: Set std.os.linux.elf_aux_maybe after PIE relocations.
Accesses to this global variable can require relocations on some platforms (e.g.
MIPS). If we do it before PIE relocations have been applied, we'll crash.
2024-07-29 10:05:28 +02:00
Alex Rønne Petersen
e33af8e902
start: Perform the posixCallMainAndExit() call with jalr on mips.
It's actually important for the ABI that r25 (t9) contains the address of the
called function, so that this standard prologue sequence works:

    lui $2, %hi(_gp_disp)
    addiu $2, $2, %lo(_gp_disp)
    addu $gp, $2, $t9

(This is a bit similar to the ToC situation on powerpc that was fixed in
7bc78967b400322a0fc5651f37a1b0428c37fb9d.)
2024-07-29 10:05:25 +02:00
Alex Rønne Petersen
77fc3b88fb
start: Set up the gp register on mips and mips64. 2024-07-29 10:04:54 +02:00
Alex Rønne Petersen
8b176ab303
start: Implement _start() for riscv32. 2024-07-29 09:50:09 +02:00