Introduce new linker for fat ape binaries

This commit is contained in:
Justine Tunney 2023-08-11 04:37:23 -07:00
parent e3c456d23a
commit 0105e3e2b6
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
44 changed files with 3140 additions and 867 deletions

44
libc/calls/abort.c Normal file
View file

@ -0,0 +1,44 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/sig.h"
/**
* Terminates program abnormally.
*
* This function first tries to trigger your SIGABRT handler. If the
* signal handler returns, then `signal(SIGABRT, SIG_DFL)` is called
* before SIGABRT is raised again.
*
* @asyncsignalsafe
* @noreturn
*/
wontreturn void abort(void) {
sigset_t m;
sigemptyset(&m);
sigaddset(&m, SIGABRT);
sigprocmask(SIG_UNBLOCK, &m, 0);
raise(SIGABRT);
signal(SIGABRT, SIG_DFL);
raise(SIGABRT);
notpossible;
}

View file

@ -32,10 +32,12 @@ kNtSystemDirectory:
.init.start 300,_init_kNtSystemDirectory
#if SupportsWindows()
testb IsWindows()
jz 1f
pushpop BYTES,%rdx
mov __imp_GetSystemDirectoryA(%rip),%rax
call __getntsyspath
#else
add $BYTES,%rdi
jmp 2f
#endif
.init.end 300,_init_kNtSystemDirectory
1: add $BYTES,%rdi
2: .init.end 300,_init_kNtSystemDirectory

View file

@ -32,10 +32,12 @@ kNtWindowsDirectory:
.init.start 300,_init_kNtWindowsDirectory
#if SupportsWindows()
testb IsWindows()
jz 1f
pushpop BYTES,%rdx
mov __imp_GetWindowsDirectoryA(%rip),%rax
call __getntsyspath
#else
add $BYTES,%rdi
jmp 2f
#endif
.init.end 300,_init_kNtWindowsDirectory
1: add $BYTES,%rdi
2: .init.end 300,_init_kNtWindowsDirectory

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/macros.internal.h"
.text.windows
@ -25,7 +26,9 @@ __onntconsoleevent_nt:
.endfn __onntconsoleevent_nt,globl,hidden
.init.start 300,_init_onntconsoleevent
testb IsWindows()
jz 1f
ezlea __onntconsoleevent_nt,cx
pushpop 1,%rdx
ntcall __imp_SetConsoleCtrlHandler
.init.end 300,_init_onntconsoleevent,globl,hidden
1: .init.end 300,_init_onntconsoleevent,globl,hidden

View file

@ -20,6 +20,8 @@
#include "libc/macros.internal.h"
.init.start 300,_init_wincrash
testb IsWindows()
jz 1f
#if !IsTiny()
mov __wincrashearly(%rip),%rcx
ntcall __imp_RemoveVectoredExceptionHandler
@ -27,4 +29,4 @@
pushpop 1,%rcx
ezlea __wincrash_nt,dx
ntcall __imp_AddVectoredExceptionHandler
.init.end 300,_init_wincrash,globl,hidden
1: .init.end 300,_init_wincrash,globl,hidden