Make progress towards aarch64 build

This commit is contained in:
Justine Tunney 2023-05-01 19:43:59 -07:00
parent 08ff26c817
commit ca2860947f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
15428 changed files with 25694 additions and 23138 deletions

View file

@ -126,6 +126,7 @@ include third_party/zlib/zlib.mk # │
include third_party/double-conversion/dc.mk # │
include libc/elf/elf.mk # │
include ape/ape.mk # │
include libc/aarch64/aarch64.mk # │
include libc/fmt/fmt.mk # │
include libc/vga/vga.mk #─┘
include libc/calls/calls.mk #─┐
@ -200,6 +201,7 @@ include tool/build/emucrt/emucrt.mk
include tool/build/emubin/emubin.mk
include tool/build/build.mk
include tool/curl/curl.mk
include third_party/qemu/qemu.mk
include examples/examples.mk
include examples/pyapp/pyapp.mk
include examples/pylife/pylife.mk

View file

@ -47,17 +47,17 @@
#define USE_SYMBOL_HACK 1
.section .text,"ax",@progbits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
.previous
.section .rodata,"a",@progbits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
__ro: .endobj __ro,globl,hidden # for gdb readability
.previous
.section .data,"aw",@progbits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
.previous
.section .bss,"aw",@nobits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
.previous
.section .rodata.str1.1,"a",@progbits
cstr: .endobj cstr,globl,hidden # for gdb readability
@ -179,7 +179,7 @@ ape_mz:
.byte 1 # 6: elf v1.o
.byte ELFOSABI_FREEBSD # 7: FreeBSD
.byte 0 # 8: os/abi ver.
.align 8,0 # 9: padding
.balign 8,0 # 9: padding
.short ET_EXEC # 10: εxεcµταblε
.short EM_NEXGEN32E # 12: NexGen32e
.long 1 # 14: elf v1.o
@ -780,11 +780,11 @@ emush: .ascii "\n@\n#'\"\n"
.endobj emush
#ifdef APE_LOADER
.section .ape.loader,"a",@progbits
.align 64
.balign 64
ape_loader:
.incbin APE_LOADER
.endobj ape_loader,globl
.align 64
.balign 64
ape_loader_end:
nop
.endobj ape_loader_end,globl
@ -858,7 +858,7 @@ openbsd.ident:
.long 4f-3f
.long 1
1: .asciz "OpenBSD"
2: .align 4
2: .balign 4
3: .long 0
4: .size openbsd.ident,.-openbsd.ident
.type openbsd.ident,@object
@ -872,7 +872,7 @@ netbsd.ident:
.long 4f-3f
.long 1
1: .asciz "NetBSD"
2: .align 4
2: .balign 4
3: .long 901000000
4: .size netbsd.ident,.-netbsd.ident
.type netbsd.ident,@object
@ -912,7 +912,7 @@ netbsd.ident:
#if SupportsXnu()
.section .macho,"a",@progbits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
ape_macho:
.long 0xFEEDFACE+1
@ -1095,7 +1095,7 @@ PEIMPS = 0b11000000000000000000000001000000
#if SupportsWindows() || SupportsMetal()
.section .pe.header,"a",@progbits
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
ape_pe: .ascin "PE",4
.short kNtImageFileMachineNexgen32e
.stub ape_pe_shnum,short # NumberOfSections
@ -1198,7 +1198,7 @@ ape_idata_idtend:
.previous
.section .piro.data.sort.metal_gdt,"aw",@progbits
.align 8
.balign 8
_gdt:
// G:granularity (1 limit *= 0x1000)
// D/B:default operation size (0 = 16|64bit, 1 = 32-bit)
@ -1289,7 +1289,7 @@ sconf: .short 1843200/*hz*/ / 16/*wut*/ / 9600/*baud*/
.endobj sconf,global,hidden
// Global Descriptor Table
.align 8
.balign 8
_gdtrlo:
.short 2f-_gdtlo-1 # table byte length
.long REAL(_gdtlo) # table address (base memory space)
@ -1298,7 +1298,7 @@ _gdtr:
.short _gdt_end-_gdt-1 # table byte length
.quad _gdt # table address (final virtual space)
.endobj _gdtr,global,hidden
.align 8
.balign 8
// Partial GDT with descriptors for switching to unreal mode or long mode.
_gdtlo = .-GDT_LEGACY_DATA
.quad 0b0000000011001111100100100000000000000000000000001111111111111111 #32
@ -1715,7 +1715,7 @@ long: movabs $BANE+PHYSICAL(0f),%rax
#define GRUB_CHECKSUM(FLAGS) (-(GRUB_MAGIC + (FLAGS)) & 0xffffffff)
// Grub Header.
.align 4
.balign 4
ape_grub:
.long GRUB_MAGIC # Magic
.long GRUB_AOUT # Flags
@ -1730,7 +1730,7 @@ ape_grub:
// Grub Entrypoint.
// Takes CPU out of legacy mode and jumps to normal entrypoint.
// @noreturn
.align 4
.balign 4
ape_grub_entry:
.code32
// cmp $GRUB_EAX,%eax
@ -1874,7 +1874,7 @@ ape_pad_text:
.type ape_pad_privileged,@object
.hidden ape_pad_privileged
ape_pad_privileged:
.align 4096
.balign 4096
.previous
.section .ape.pad.rodata,"a",@progbits

View file

@ -32,6 +32,7 @@
// @see ape/ape.lds
// @see winimp
.macro .imp dll:req fn:req actual:req hint
#ifdef __x86_64__
.dll "\dll"
.section ".piro.data.sort.iat.2.\dll\().2.\actual","aw",@progbits
.type \fn,@object
@ -49,18 +50,28 @@
.previous
.section ".idata.ro.hnt.\dll\().2.\actual","a",@progbits
"\dll\().\actual":
.ifnb \hint # hint i.e. guess function ordinal
.ifnb \hint // hint i.e. guess function ordinal
.short \hint
.else
.short 0
.endif
.asciz "\actual"
.align 2 # documented requirement
.align 2 // documented requirement
.globl "\dll\().\actual"
.hidden "\dll\().\actual"
.type "\dll\().\actual",@object
.size "\dll\().\actual",.-"\dll\().\actual"
.previous
#else
.section ".text.nt.\actual","ax",@progbits
.globl "\actual"
"\actual":
ret
.section ".data.nt.\actual","aw",@progbits
.globl "\fn"
.balign 8
"\fn": .quad "\actual"
#endif
.endm
// Defines DLL import.
@ -68,11 +79,11 @@
.macro .dll name:req
.section ".idata.ro.idt.2.\name","aG",@progbits,"\name",comdat
.equ ".Lidata.idt.\name",.
.long RVA("idata.ilt.\name") # ImportLookupTable
.long 0 # TimeDateStamp
.long 0 # ForwarderChain
.long RVA(".Lidata.str.\name") # DllNameRva
.long RVA("idata.iat.\name") # ImportAddressTable
.long RVA("idata.ilt.\name") // ImportLookupTable
.long 0 // TimeDateStamp
.long 0 // ForwarderChain
.long RVA(".Lidata.str.\name") // DllNameRva
.long RVA("idata.iat.\name") // ImportAddressTable
.type ".Lidata.idt.\name",@object
.size ".Lidata.idt.\name",.-".Lidata.idt.\name"
.previous

View file

@ -25,7 +25,7 @@
// APE Loader Executable Structure
// Linux, FreeBSD, NetBSD, OpenBSD
.align 8
.balign 8
ehdr: .ascii "\177ELF"
.byte ELFCLASS64
.byte ELFDATA2LSB
@ -47,7 +47,7 @@ ehdr: .ascii "\177ELF"
.word 0 # e_shstrndx
.endobj ehdr,globl
.align 8
.balign 8
phdrs: .long PT_LOAD # p_type
.long PF_R|PF_X # p_flags
.quad 0 # p_offset
@ -89,18 +89,18 @@ note: .long 2f-1f
.long 4f-3f
.long 1
1: .asciz "OpenBSD"
2: .align 4
2: .balign 4
3: .long 0
4: .long 2f-1f
.long 4f-3f
.long 1
1: .asciz "NetBSD"
2: .align 4
2: .balign 4
3: .long 901000000
4: .endobj note
notesize = . - note
.align 64,0 # for ape.S dd
.balign 64,0 # for ape.S dd
.org 0x180 # for ape.S dd
// APE Loader XNU Header
@ -197,7 +197,7 @@ macho: .long 0xFEEDFACE+1
60:
.endobj macho
.align 64,0 # for ape.S dd
.balign 64,0 # for ape.S dd
.org 0x400 # for ape.S dd
// Ape Loader Entrpoint

View file

@ -23,7 +23,7 @@
// APE Loader Executable Structure for XNU
.align 4096
.balign 4096
macho: .long 0xFEEDFACE+1
.long MAC_CPU_NEXGEN32E
.long MAC_CPU_NEXGEN32E_ALL
@ -112,7 +112,7 @@ macho: .long 0xFEEDFACE+1
60:
.endobj macho,globl
.align 64
.balign 64
_start:
// Hack for detecting M1 Rosetta environment.

View file

@ -74,11 +74,12 @@ IGNORE := $(shell $(MKDIR) o/tmp)
ifneq ("$(wildcard o/third_party/gcc/bin/x86_64-pc-linux-gnu-*)","")
PREFIX = o/third_party/gcc/bin/x86_64-pc-linux-gnu-
PREFIX_AARCH64 = o/third_party/gcc/bin/aarch64-pc-linux-gnu-
else
IGNORE := $(shell build/bootstrap/unbundle.com)
PREFIX = o/third_party/gcc/bin/x86_64-linux-musl-
PREFIX_AARCH64 = o/third_party/gcc/bin/aarch64-linux-musl-
endif
ifeq ($(MODE), aarch64)
PREFIX = o/third_party/gcc/bin/aarch64-linux-musl-
endif
AS = $(PREFIX)as
@ -93,18 +94,6 @@ OBJCOPY = $(PREFIX)objcopy
OBJDUMP = $(PREFIX)objdump
ADDR2LINE = $(PWD)/$(PREFIX)addr2line
AS_AARCH64 = $(PREFIX_AARCH64)as
CC_AARCH64 = $(PREFIX_AARCH64)gcc
CXX_AARCH64 = $(PREFIX_AARCH64)g++
CXXFILT_AARCH64 = $(PREFIX_AARCH64)c++filt
LD_AARCH64 = $(PREFIX_AARCH64)ld.bfd
NM_AARCH64 = $(PREFIX_AARCH64)nm
GCC_AARCH64 = $(PREFIX_AARCH64)gcc
STRIP_AARCH64 = $(PREFIX_AARCH64)strip
OBJCOPY_AARCH64 = $(PREFIX_AARCH64)objcopy
OBJDUMP_AARCH64 = $(PREFIX_AARCH64)objdump
ADDR2LINE_AARCH64 = $(PWD)/$(PREFIX_AARCH64)addr2line
export ADDR2LINE
export LC_ALL
export MKDIR
@ -118,6 +107,10 @@ else
TMPSAFE = $(TMPDIR)/
endif
ifneq ($(MODE), aarch64)
MNO_FENTRY = -mno-fentry
endif
FTRACE = \
-pg
@ -131,7 +124,7 @@ SANITIZER = \
-fsanitize=address
NO_MAGIC = \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fwrapv \
-fno-sanitize=all
@ -342,14 +335,10 @@ OBJECTIFY.greg.c = \
-fno-optimize-sibling-calls \
-fno-sanitize=all \
-ffreestanding \
$(MNO_FENTRY) \
-fwrapv \
-c
ifneq ($(MODE), aarch64)
OBJECTIFY.greg.c += \
-mno-fentry
endif
OBJECTIFY.ansi.c = $(CC) $(OBJECTIFY.c.flags) -ansi -Wextra -Werror -pedantic-errors -c
OBJECTIFY.c99.c = $(CC) $(OBJECTIFY.c.flags) -std=c99 -Wextra -Werror -pedantic-errors -c
OBJECTIFY.c11.c = $(CC) $(OBJECTIFY.c.flags) -std=c11 -Wextra -Werror -pedantic-errors -c
@ -386,7 +375,7 @@ OBJECTIFY.ncabi.c = \
$(OBJECTIFY.c.flags) \
-mno-sse \
-mfpmath=387 \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \
@ -405,7 +394,7 @@ OBJECTIFY.ncabi.c = \
OBJECTIFY.initabi.c = \
$(GCC) \
$(OBJECTIFY.c.flags) \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \

View file

@ -1,6 +1,6 @@
#!/bin/sh
for last; do true; done
if grep aarch64 "$last" >/dev/null 2>&1; then
if printf '%s\n' "$last" | grep aarch64 >/dev/null 2>&1; then
exec o/third_party/gcc/bin/aarch64-linux-musl-objdump "$@"
else
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.align 16
.balign 16
// Mixes audio.
//

View file

@ -32,7 +32,6 @@
#include "dsp/mpeg/idct.h"
#include "dsp/mpeg/mpeg.h"
#include "dsp/mpeg/video.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/fmt/conv.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"

View file

@ -18,7 +18,6 @@
*/
#include "dsp/tty/itoa8.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/str/str.h"
struct Itoa8 kItoa8;

View file

@ -19,7 +19,6 @@
#include "dsp/core/core.h"
#include "dsp/tty/quant.h"
#include "libc/assert.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"

View file

@ -18,7 +18,6 @@
*/
#include "dsp/tty/internal.h"
#include "dsp/tty/quant.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/dce.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

14
libc/aarch64/aarch64.mk Normal file
View file

@ -0,0 +1,14 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
o/$(MODE)/libc/aarch64/%.o: libc/aarch64/%.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/aarch64/start.o: \
libc/aarch64/start.c \
libc/runtime/runtime.h
o/$(MODE)/libc/aarch64: \
o/$(MODE)/libc/aarch64/crt.o \
o/$(MODE)/libc/aarch64/fenv.o \
o/$(MODE)/libc/aarch64/start.o

53
libc/aarch64/crt.S Normal file
View file

@ -0,0 +1,53 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2023 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.
*/
.globl _start
.type _start,%function
_start: mov x29,#0
mov x30,#0
mov x0,sp
and sp,x0,#-16
b _start_c
.size _start,.-_start
.section .initprologue
.global _init
.type _init,%function
_init: stp x29,x30,[sp,-16]!
mov x29,sp
.previous/*
...
decentralized content
...
*/.section .initepilogue
ldp x29,x30,[sp],#16
ret
.section .finiprologue
.global _fini
.type _fini,%function
_fini: stp x29,x30,[sp,-16]!
mov x29,sp
.previous/*
...
decentralized content
...
*/.section .finiepilogue
ldp x29,x30,[sp],#16
ret

67
libc/aarch64/fenv.S Normal file
View file

@ -0,0 +1,67 @@
.global fegetround
.type fegetround,%function
fegetround:
mrs x0,fpcr
and w0,w0,#0xc00000
ret
.global __fesetround
.hidden __fesetround
.type __fesetround,%function
__fesetround:
mrs x1,fpcr
bic w1,w1,#0xc00000
orr w1,w1,w0
msr fpcr,x1
mov w0,#0
ret
.global fetestexcept
.type fetestexcept,%function
fetestexcept:
and w0,w0,#0x1f
mrs x1,fpsr
and w0,w0,w1
ret
.global feclearexcept
.type feclearexcept,%function
feclearexcept:
and w0,w0,#0x1f
mrs x1,fpsr
bic w1,w1,w0
msr fpsr,x1
mov w0,#0
ret
.global feraiseexcept
.type feraiseexcept,%function
feraiseexcept:
and w0,w0,#0x1f
mrs x1,fpsr
orr w1,w1,w0
msr fpsr,x1
mov w0,#0
ret
.global fegetenv
.type fegetenv,%function
fegetenv:
mrs x1,fpcr
mrs x2,fpsr
stp w1,w2,[x0]
mov w0,#0
ret
.global fesetenv
.type fesetenv,%function
fesetenv:
mov x1,#0
mov x2,#0
cmn x0,#1
b.eq 1f
ldp w1,w2,[x0]
1: msr fpcr,x1
msr fpsr,x2
mov w0,#0
ret

56
libc/aarch64/start.c Normal file
View file

@ -0,0 +1,56 @@
/*-*- 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 2023 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/runtime/runtime.h"
int main(int, char **, char **);
int __argc;
char **__argv;
char **__envp;
char **environ;
static inline long sys_set_tid_address(int *t) {
register int64_t __r0 asm("x0") = (int64_t)t;
register int64_t __res_x0 asm("x0");
int64_t __res;
asm volatile("mov x8, %1\n"
"svc 0x0\n"
: "=r"(__res_x0)
: "i"(96), "r"(__r0)
: "x8", "memory");
return __res_x0;
}
void _start_c(long *sp) {
int argc;
char **argv, **envp;
unsigned long *auxv;
argc = *sp;
argv = (char **)(sp + 1);
envp = (char **)(sp + 1 + argc + 1);
auxv = (unsigned long *)(sp + 1 + argc + 1);
for (;;) {
if (!*auxv++) {
break;
}
}
__auxv = auxv;
environ = envp;
exit(main(argc, argv, envp));
}

View file

@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"

View file

@ -21,7 +21,6 @@
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"

View file

@ -106,7 +106,11 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef __x86_64__
extern const int __hostos;
#else
#define __hostos _HOSTLINUX
#endif
bool IsWsl1(void);

View file

@ -578,11 +578,15 @@ typedef struct {
#define autotype(x) typeof(x)
#endif
#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
__has_attribute(__no_sanitize_address__)
@ -608,11 +612,15 @@ typedef struct {
#endif
#endif
#ifdef __x86_64__
#define notpossible \
do { \
asm("nop\n\tud2\n\tnop"); \
unreachable; \
} while (0)
#else
#define notpossible __builtin_trap()
#endif
#define donothing \
do { \
@ -667,7 +675,7 @@ typedef struct {
#endif
#endif
#ifndef __llvm__
#if defined(__x86_64__) && !defined(__llvm__)
#define initarray _Section(".init_array,\"a\",@init_array #")
#else
#define initarray _Section(".init_array")
@ -773,8 +781,12 @@ typedef struct {
#endif /* -w */
#ifndef __STRICT_ANSI__
#ifdef __x86_64__
#define DebugBreak() asm("int3")
#else
#define DebugBreak() __builtin_trap()
#endif
#else
#define DebugBreak() (void)0
#endif
@ -810,14 +822,14 @@ typedef struct {
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
#endif
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
#define YOINK(SYMBOL) \
asm(".section .yoink\n\tnopl\t%a0\n\t.previous" : : "X"(SYMBOL))
#else
#define YOINK(SYMBOL) (void)0
#endif
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
#define STATIC_YOINK(SYMBOLSTR) \
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#else

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥+𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥+𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥+𝑦, aborting on overflow.
//

View file

@ -9,6 +9,7 @@ int _bsfll(long long) pureconst;
int _bsf128(uintmax_t) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#ifdef __x86_64__
#define _bsf(u) \
({ \
unsigned BiTs; \
@ -22,6 +23,11 @@ int _bsf128(uintmax_t) pureconst;
(unsigned)BiTs; \
})
#define _bsfll(u) _bsfl(u)
#else
#define _bsf(x) __builtin_ctz(x)
#define _bsfl(x) __builtin_ctzl(x)
#define _bsfll(x) __builtin_ctzll(x)
#endif
#endif
COSMOPOLITAN_C_END_

View file

@ -7,7 +7,8 @@ int _bsr(int) pureconst;
int _bsrl(long) pureconst;
int _bsrll(long long) pureconst;
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#ifdef __x86_64__
int _bsr128(uint128_t) pureconst;
#define _bsr(u) \
({ \
@ -22,6 +23,11 @@ int _bsr128(uint128_t) pureconst;
(unsigned)BiTs; \
})
#define _bsrll(u) _bsrl(u)
#else
#define _bsr(x) (__builtin_clz(x) ^ (sizeof(int) * CHAR_BIT - 1))
#define _bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * CHAR_BIT - 1))
#define _bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * CHAR_BIT - 1))
#endif
#endif
COSMOPOLITAN_C_END_

View file

@ -43,6 +43,7 @@ static dontinline antiquity void bzero_sse(char *p, size_t n) {
}
}
#ifdef __x86_64__
microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
xmm_t v = {0};
if (IsAsan()) __asan_verify(p, n);
@ -73,6 +74,7 @@ microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
*(xmm_t *)p = v;
}
}
#endif
/**
* Sets memory to zero.
@ -134,7 +136,11 @@ void bzero(void *p, size_t n) {
char *b;
uint64_t x;
b = p;
#ifdef __x86_64__
asm("xorl\t%k0,%k0" : "=r"(x));
#else
x = 0;
#endif
if (n <= 16) {
if (n >= 8) {
__builtin_memcpy(b, &x, 8);
@ -148,11 +154,13 @@ void bzero(void *p, size_t n) {
b[--n] = x;
} while (n);
}
#ifdef __x86_64__
} else if (IsTiny()) {
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "a"(0));
return;
} else if (X86_HAVE(AVX)) {
bzero_avx(b, n);
#endif
} else {
bzero_sse(b, n);
}

View file

@ -4,7 +4,7 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__x86__)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \

View file

@ -40,6 +40,7 @@ size_t _countbits(const void *a, size_t n) {
p = a;
e = p + n;
if (!IsTiny()) {
#ifdef __x86_64__
if (X86_HAVE(POPCNT)) {
while (p + sizeof(long) * 4 <= e) {
__builtin_memcpy(&Ai, p + 000, sizeof(long));
@ -60,6 +61,7 @@ size_t _countbits(const void *a, size_t n) {
t += Ao;
}
} else {
#endif
while (p + 8 <= e) {
__builtin_memcpy(&x, p, 8);
x = x - ((x >> 1) & 0x5555555555555555);
@ -71,7 +73,9 @@ size_t _countbits(const void *a, size_t n) {
t += x;
p += 8;
}
#ifdef __x86_64__
}
#endif
}
while (p < e) {
b = *p++ & 255;

View file

@ -25,6 +25,7 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__
#define MAP_ANONYMOUS_linux 0x00000020
#define MAP_FIXED_linux 0x00000010
@ -109,3 +110,5 @@ noasan struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot,
res.maphandle = -1;
return res;
}
#endif /* __x86_64__ */

View file

@ -39,6 +39,7 @@
privileged wontreturn void _Exit(int exitcode) {
int i;
STRACE("_Exit(%d)", exitcode);
#ifdef __x86_64__
if (!IsWindows() && !IsMetal()) {
// On Linux _Exit1 (exit) must be called in pledge("") mode. If we
// call _Exit (exit_group) when we haven't used pledge("stdio") then
@ -64,4 +65,13 @@ privileged wontreturn void _Exit(int exitcode) {
"cli\n\t"
"lidt\t(%rsp)");
for (;;) asm("ud2");
#elif defined(__aarch64__)
register long x0 asm("x0") = exitcode;
asm volatile("mov\tx8,%1\n"
"svc\t0"
: /* no outputs */
: "i"(94), "r"(x0)
: "x8", "memory");
notpossible;
#endif
}

View file

@ -43,6 +43,7 @@ __msabi extern typeof(ExitThread) *const __imp_ExitThread;
* @noreturn
*/
privileged wontreturn void _Exit1(int rc) {
#ifdef __x86_64__
char cf;
int ax, dx, di, si;
if (!IsWindows() && !IsMetal()) {
@ -72,4 +73,13 @@ privileged wontreturn void _Exit1(int rc) {
unreachable;
}
notpossible;
#elif defined(__aarch64__)
register long r0 asm("x0") = rc;
asm volatile("mov\tx8,%1\n"
"svc\t0"
: /* no outputs */
: "i"(93), "r"(r0)
: "x8", "memory");
notpossible;
#endif
}

View file

@ -9,7 +9,7 @@ void *_wrfsbase(void *);
void *_wrgsbase(void *);
int _have_fsgsbase(void);
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define _rdfsbase() \
({ \
void *_p; \

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/runtime/runtime.h"
#ifdef __x86_64__
void GetCpuidBrand(char s[13], uint32_t leaf) {
int ax, cx;
@ -32,3 +33,5 @@ void GetCpuidBrand(char s[13], uint32_t leaf) {
: "rdx");
s[12] = 0;
}
#endif /* __x86_64__ */

View file

@ -20,6 +20,7 @@
#include "libc/errno.h"
#include "libc/intrin/fsgsbase.h"
#include "libc/nexgen32e/x86feature.h"
#ifdef __x86_64__
/**
* Returns true if FSGSBASE ISA can be used.
@ -61,3 +62,5 @@ privileged int _have_fsgsbase(void) {
return 0;
}
}
#endif /* __x86_64__ */

View file

@ -1,22 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
#define COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
/* TODO: DELETE */
/**
* Teleports code fragment inside _init().
*/
#ifndef INITIALIZER
#define INITIALIZER(PRI, NAME, CODE) \
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
"call\t" #NAME "\n\t" \
".previous"); \
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
CODE; \
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
}
#endif /* INITIALIZER */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ */

View file

@ -89,7 +89,7 @@ o/$(MODE)/libc/intrin/kprintf.greg.o: private \
-fpie \
-fwrapv \
-x-no-pg \
-mno-fentry \
$(MNO_FENTRY) \
-ffreestanding \
-fno-sanitize=all \
-fno-stack-protector
@ -105,7 +105,7 @@ o/$(MODE)/libc/intrin/_spinlock_debug_4.o: private \
OVERRIDE_CFLAGS += \
-fwrapv \
-x-no-pg \
-mno-fentry \
$(MNO_FENTRY) \
-ffreestanding \
-fno-sanitize=all \
-mgeneral-regs-only \
@ -186,6 +186,10 @@ o/$(MODE)/libc/intrin/memmove.o: private \
OVERRIDE_CFLAGS += \
-fpie
# these assembly files are safe to build on aarch64
o/$(MODE)/libc/intrin/kclocknames.o: libc/intrin/kclocknames.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
LIBC_INTRIN_LIBS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)))
LIBC_INTRIN_HDRS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_HDRS))
LIBC_INTRIN_INCS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_INCS))

View file

@ -28,18 +28,18 @@
.endm
.section .rodata,"a",@progbits
.align 4
.balign 4
.underrun
kClockNames:
.e CLOCK_REALTIME,"REALTIME"
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" # order matters
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" # order matters
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" # order matters
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" // order matters
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" // order matters
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" // order matters
.e CLOCK_MONOTONIC,"MONOTONIC"
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" # order matters
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" # order matters
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" # order matters
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" # order matters
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" // order matters
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" // order matters
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" // order matters
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" // order matters
.e CLOCK_PROCESS_CPUTIME_ID,"PROCESS_CPUTIME_ID"
.e CLOCK_THREAD_CPUTIME_ID,"THREAD_CPUTIME_ID"
.e CLOCK_TAI,"TAI"

View file

@ -22,7 +22,7 @@
// @see libc/sysv/dos2errno.sh for the numbers
.section .sort.rodata.dos2errno.1,"a",@progbits
.align 8
.balign 8
kDos2Errno:/*
...decentralized content...
*/.endobj kDos2Errno,globl

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kErrnoDocs:
.e EINVAL,"Invalid argument"

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kErrnoNames:
.e EINVAL

View file

@ -28,7 +28,7 @@
.endm
.section .rodata,"a",@progbits
.align 4
.balign 4
.underrun
kFcntlCmds:
.e F_GETFD,"GETFD"

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kIpOptnames:
.e IP_TOS,"TOS" # int

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kOpenFlags:
.e O_RDWR,"RDWR" // order matters

View file

@ -165,6 +165,7 @@ privileged bool kisdangerous(const void *p) {
}
privileged static void klog(const char *b, size_t n) {
#ifdef __x86_64__
int e;
bool cf;
size_t i;
@ -196,6 +197,17 @@ privileged static void klog(const char *b, size_t n) {
: "0"(__NR_write), "1"(2), "2"(b), "3"(n)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
}
#else
register long r0 asm("x0") = (long)2;
register long r1 asm("x1") = (long)b;
register long r2 asm("x2") = (long)n;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
: "x8", "memory");
#endif
}
privileged static size_t kformat(char *b, size_t n, const char *fmt,
@ -798,7 +810,6 @@ privileged size_t kvsnprintf(char *b, size_t n, const char *fmt, va_list v) {
privileged void kvprintf(const char *fmt, va_list v) {
size_t n;
char b[4000];
if (!v) return;
n = kformat(b, sizeof(b), fmt, v);
klog(b, MIN(n, sizeof(b) - 1));
}

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kRlimitNames:
.e RLIMIT_AS,"AS"

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kSignalNames:
.e SIGHUP,"SIGHUP"

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kSockOptnames:
.e SO_DEBUG,"DEBUG" # bool32

View file

@ -28,7 +28,7 @@
.endm
.section .rodata
.align 4
.balign 4
.underrun
kTcpOptnames:
.e TCP_NODELAY,"NODELAY" # bool32

View file

@ -25,7 +25,7 @@
.globl _leaky_start,_leaky_end
.hidden _leaky_start,_leaky_end
.byte 0
.align __SIZEOF_POINTER__
.balign __SIZEOF_POINTER__
.underrun
_leaky_start:
.previous/*

View file

@ -3,9 +3,11 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* TODO(jart): DELETE */
intptr_t lockxchg(void *, void *, size_t);
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
/**
* Exchanges *MEMORY into *LOCALVAR w/ one operation.
*

View file

@ -25,6 +25,8 @@
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
#ifdef __x86_64__
static dontinline antiquity int memcmp_sse(const unsigned char *p,
const unsigned char *q, size_t n) {
unsigned u;
@ -99,6 +101,8 @@ microarchitecture("avx") static int memcmp_avx(const unsigned char *p,
}
}
#endif /* __x86_64__ */
/**
* Compares memory byte by byte.
*
@ -136,6 +140,7 @@ int memcmp(const void *a, const void *b, size_t n) {
const unsigned char *p, *q;
if ((p = a) == (q = b) || !n) return 0;
if ((c = *p - *q)) return c;
#ifdef __x86_64__
if (!IsTiny()) {
if (n <= 16) {
if (n >= 8) {
@ -187,6 +192,7 @@ int memcmp(const void *a, const void *b, size_t n) {
return memcmp_sse(p, q, n);
}
}
#endif /* __x86_64__ */
for (; n; ++p, ++q, --n) {
if ((c = *p - *q)) {
return c;

View file

@ -93,6 +93,8 @@ void *memmove(void *dst, const void *src, size_t n) {
xmm_t v, w, x, y, V, W, X, Y, wut;
d = dst;
s = src;
#ifdef __x86__
if (IsTiny()) {
uint16_t w1, w2;
uint32_t l1, l2;
@ -133,6 +135,8 @@ void *memmove(void *dst, const void *src, size_t n) {
}
return dst;
}
#endif
switch (n) {
case 0:
return d;
@ -208,6 +212,8 @@ void *memmove(void *dst, const void *src, size_t n) {
return d;
default:
if (d == s) return d;
#ifdef __x86__
if (n < kHalfCache3 || !kHalfCache3) {
if (d > s) {
if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) {
@ -280,6 +286,31 @@ void *memmove(void *dst, const void *src, size_t n) {
}
asm("sfence");
}
#else
if (d > s) {
do {
n -= 32;
v = *(const xmm_t *)(s + n);
w = *(const xmm_t *)(s + n + 16);
*(xmm_t *)(d + n) = v;
*(xmm_t *)(d + n + 16) = w;
} while (n >= 32);
} else {
i = 0;
do {
v = *(const xmm_t *)(s + i);
w = *(const xmm_t *)(s + i + 16);
*(xmm_t *)(d + i) = v;
*(xmm_t *)(d + i + 16) = w;
} while ((i += 32) + 32 <= n);
d += i;
s += i;
n -= i;
}
#endif
if (n) {
if (n >= 16) {
v = *(const xmm_t *)s;
@ -305,6 +336,7 @@ void *memmove(void *dst, const void *src, size_t n) {
*d = *s;
}
}
return dst;
}
}

View file

@ -44,6 +44,7 @@ static dontinline antiquity void *memset_sse(char *p, char c, size_t n) {
return p;
}
#ifdef __x86_64__
microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
char *t;
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
@ -76,6 +77,7 @@ microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
}
return p;
}
#endif /* __x86_64__ */
/**
* Sets memory.
@ -155,11 +157,13 @@ void *memset(void *p, int c, size_t n) {
} while (n);
}
return b;
#ifdef __x86_64__
} else if (IsTiny()) {
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "0"(p), "a"(c));
return p;
} else if (X86_HAVE(AVX)) {
return memset_avx(b, c, n);
#endif
} else {
return memset_sse(b, c, n);
}

View file

@ -42,6 +42,7 @@
#include "libc/runtime/metalprintf.internal.h"
#include "libc/runtime/pc.internal.h"
#include "libc/runtime/runtime.h"
#ifdef __x86_64__
#define INVERT(x) (BANE + PHYSICAL(x))
#define NOPAGE ((uint64_t)-1)
@ -313,3 +314,5 @@ noasan textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start,
}
mm->frp = p;
}
#endif /* __x86_64__ */

View file

@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
void mpsadbw(uint16_t[8], const uint8_t[16], const uint8_t[16], uint8_t);
#ifndef __STRICT_ANSI__
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
__intrin_xmm_t __mpsadbws(__intrin_xmm_t, __intrin_xmm_t);
#define mpsadbw(C, B, A, I) \
do { \

View file

@ -22,7 +22,7 @@
//
// @note needs sse4 cf. core c. 2006 cf. bulldozer c. 2011
// @see mpsadbw()
.align 8
.balign 8
__mpsadbws:
i = 0
.rept 8

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥*𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥*𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥*𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns -𝑥, aborting on overflow (two's complement bane).
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns -𝑥, aborting on overflow (two's complement bane).
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns -𝑥, aborting on overflow.
//

View file

@ -1,7 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__GNUC__) && \
!defined(__llvm__) && !defined(__chibicc__) && !defined(__STRICT_ANSI__)
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__x86_64__) && \
defined(__GNUC__) && !defined(__llvm__) && !defined(__chibicc__) && \
!defined(__STRICT_ANSI__)
/**
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.

View file

@ -18,6 +18,7 @@
*/
#include "libc/nt/struct/teb.h"
#include "libc/runtime/runtime.h"
#ifdef __x86_64__
/**
* Returns New Technology version, e.g.
@ -29,3 +30,5 @@
textwindows noasan int NtGetVersion(void) {
return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion;
}
#endif /* __x86_64__ */

View file

@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
void palignr(void *, const void *, const void *, unsigned long);
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__)
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I) \
do { \

View file

@ -22,7 +22,7 @@
//
// @note needs ssse3 cf. prescott c. 2004 cf. bulldozer c. 2011
// @see palignr()
.align 8
.balign 8
__palignrs:
palignr $0,%xmm1,%xmm0
ret

View file

@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
size_t _countbits(const void *, size_t);
unsigned long popcnt(unsigned long) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X) \
(__builtin_constant_p(X) ? __builtin_popcountll(X) : ({ \
unsigned long PoP = (X); \
@ -18,6 +18,8 @@ unsigned long popcnt(unsigned long) pureconst;
} \
PoP; \
}))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */
COSMOPOLITAN_C_END_

View file

@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
void pslldq(uint8_t[16], const uint8_t[16], unsigned long);
#ifndef __STRICT_ANSI__
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
__intrin_xmm_t __pslldqs(__intrin_xmm_t);
#define pslldq(B, A, I) \
do { \

View file

@ -19,7 +19,7 @@
#include "libc/macros.internal.h"
// Jump table for pslldq() with non-constexpr immediate parameter.
.align 8
.balign 8
__pslldqs:
pslldq $0,%xmm0
ret

View file

@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
void psrldq(uint8_t[16], const uint8_t[16], unsigned long);
#ifndef __STRICT_ANSI__
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
__intrin_xmm_t __psrldqs(__intrin_xmm_t);
#define psrldq(B, A, I) \
do { \

View file

@ -19,7 +19,7 @@
#include "libc/macros.internal.h"
// Jump table for psrldq() with non-constexpr immediate parameter.
.align 8
.balign 8
__psrldqs:
psrldq $0,%xmm0
ret

View file

@ -3,7 +3,7 @@
#include "libc/macros.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
#define pushpop(x) (x)
#else
/**
@ -31,7 +31,7 @@
})
#endif
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
#define pushmov(d, x) (*(d) = (x))
#else
#define pushmov(d, x) \

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Reads `%fs` base address.
@ -26,3 +27,5 @@
void *(_rdfsbase)(void) {
return _rdfsbase();
}
#endif /* __x86_64__ */

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Reads `%gs` base address.
@ -26,3 +27,5 @@
void *(_rdgsbase)(void) {
return _rdgsbase();
}
#endif /* __x86_64__ */

View file

@ -18,13 +18,13 @@
*/
#include "libc/macros.internal.h"
.align 8
.balign 8
shufpdjt:
i=0
.rept 256
shufpd $i,%xmm1,%xmm0
ret
.align 8
.balign 8
i=i+1
.endr
.endfn shufpdjt,globl

View file

@ -18,13 +18,13 @@
*/
#include "libc/macros.internal.h"
.align 8
.balign 8
shufpsjt:
i=0
.rept 256
shufps $i,%xmm1,%xmm0
ret
.align 8
.balign 8
i=i+1
.endr
.endfn shufpsjt,globl

View file

@ -21,6 +21,7 @@
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
#ifdef __x86_64__
static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
xmm_t v, z = {0};
for (;;) {
@ -34,6 +35,7 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
}
return i;
}
#endif
/**
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
@ -45,13 +47,15 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
* @asyncsignalsafe
*/
char *stpcpy(char *d, const char *s) {
size_t i;
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
size_t i = 0;
#ifdef __x86_64__
for (; (uintptr_t)(s + i) & 15; ++i) {
if (!(d[i] = s[i])) {
return d + i;
}
}
i = stpcpy_sse2(d, s, i);
#endif
for (;;) {
if (!(d[i] = s[i])) {
return d + i;

View file

@ -21,6 +21,7 @@
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
#ifdef __x86_64__
static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
xmm_t v, z = {0};
for (;;) {
@ -34,6 +35,7 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
}
return i;
}
#endif
/**
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
@ -45,13 +47,15 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
* @asyncsignalsafe
*/
char *strcpy(char *d, const char *s) {
size_t i;
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
size_t i = 0;
#ifdef __x86_64__
for (; (uintptr_t)(s + i) & 15; ++i) {
if (!(d[i] = s[i])) {
return d;
}
}
i = strcpy_sse2(d, s, i);
#endif
for (;;) {
if (!(d[i] = s[i])) {
return d;

View file

@ -30,6 +30,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
* @asyncsignalsafe
*/
noasan size_t strlen(const char *s) {
#ifdef __x86_64__
size_t n;
xmm_t z = {0};
unsigned m, k = (uintptr_t)s & 15;
@ -39,4 +40,9 @@ noasan size_t strlen(const char *s) {
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
n = (const char *)p + __builtin_ctzl(m) - s;
return n;
#else
size_t n = 0;
while (*s++) ++n;
return n;
#endif
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥-𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥-𝑦, aborting on overflow.
//

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.privileged
.alignfunc
.balignfunc
// Returns 𝑥-𝑦, aborting on overflow.
//

View file

@ -25,6 +25,7 @@
__msabi extern typeof(GetCurrentThreadId) *const __imp_GetCurrentThreadId;
privileged int sys_gettid(void) {
#ifdef __x86_64__
int tid;
int64_t wut;
if (IsWindows()) {
@ -61,4 +62,13 @@ privileged int sys_gettid(void) {
tid = __pid;
}
return tid;
#elif defined(__aarch64__)
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(178)
: "x8", "memory");
return res_x0;
#endif
}

View file

@ -55,7 +55,7 @@ __syscall__:
.endfn __syscall__,globl,hidden
.bss
.align 8
.balign 8
.Lrcx: .quad 0 # clobbered by syscall
.Lrdi: .quad 0 # just in case
.Lrsi: .quad 0 # just in case

View file

@ -45,7 +45,7 @@ _tpenc: .leafprologue
.endfn _tpenc,globl
.rodata
.align 4
.balign 4
.underrun
kTpenc: .rept 4 # MSB10 (0x7FF)
.byte 1,0b11000000 # len,mark

View file

@ -4,10 +4,11 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifndef __STRICT_ANSI__
#define _weaken(symbol) \
({ \
asm(".weak\t" #symbol); \
&symbol; \
#define _weaken(symbol) \
({ \
typeof(&symbol) _p = &symbol; \
asm(".weak\t" #symbol : "+r"(_p)); \
_p; \
})
#define _strongaddr(symbolstr) \

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Changes `%fs` base address.
@ -26,3 +27,5 @@
void *(_wrfsbase)(void *p) {
return _wrfsbase(p);
}
#endif /* __x86_64__ */

View file

@ -67,10 +67,10 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
break;
}
addr = frame->addr;
if (addr == _weakaddr("__gc")) {
if (addr == (intptr_t)_weaken(__gc)) {
do {
--gi;
} while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
} while ((addr = garbage->p[gi].ret) == (intptr_t)_weaken(__gc));
}
/*
* we subtract one to handle the case of noreturn functions with a

View file

@ -21,14 +21,14 @@
.yoink countbranch_report
.section .sort.data.countbranch.1,"a",@progbits
.align 8
.balign 8
.underrun
.globl countbranch_data
countbranch_data:
.previous
.section .sort.data.countbranch.3,"a",@progbits
.align 8
.balign 8
.rept 5
.quad -1
.endr

View file

@ -22,14 +22,14 @@
.yoink countexpr_report
.section .sort.data.countexpr.1,"a",@progbits
.align 8
.balign 8
.globl countexpr_data
.underrun
countexpr_data:
.previous
.section .sort.data.countexpr.3,"a",@progbits
.align 8
.balign 8
.quad 0
.overrun
.previous

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_LOG_GDB_H_
#define COSMOPOLITAN_LIBC_LOG_GDB_H_
#include "libc/calls/calls.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/wait4.h"
#include "libc/dce.h"
#include "libc/sysv/consts/nr.h"
@ -41,6 +42,7 @@ int AttachDebugger(intptr_t);
Pid; \
})
#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \
({ \
int64_t WaAx; \
@ -56,6 +58,9 @@ int AttachDebugger(intptr_t);
} \
WaAx; \
})
#else
#define __inline_wait4 wait4
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -17,6 +17,15 @@ forceinline long __sysv_exit(long rc) {
: "=a"(ax)
: "0"(__NR_exit_group), "D"(rc)
: "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = rc;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(94), "r"(r0)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_exit_group, rc);
#endif
@ -30,6 +39,15 @@ forceinline int __sysv_close(long fd) {
: "=a"(ax)
: "0"(__NR_close), "D"(fd)
: "rdx", "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = fd;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(57), "r"(r0)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_close, fd);
#endif
@ -43,6 +61,18 @@ forceinline int __sysv_open(const char *path, long flags, long mode) {
: "=a"(ax), "=d"(dx)
: "0"(__NR_open), "D"(path), "S"(flags), "1"(mode)
: "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = -100;
register long r1 asm("x1") = (long)path;
register long r2 asm("x2") = (long)flags;
register long r3 asm("x3") = (long)mode;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(56), "r"(r0), "r"(r1), "r"(r2), "r"(r3)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_open, path, flags, mode);
#endif
@ -56,6 +86,17 @@ forceinline long __sysv_read(long fd, void *data, unsigned long size) {
: "=a"(ax), "=d"(dx)
: "0"(__NR_read), "D"(fd), "S"(data), "1"(size)
: "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)fd;
register long r1 asm("x1") = (long)data;
register long r2 asm("x2") = (long)size;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(63), "r"(r0), "r"(r1), "r"(r2)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_read, fd, data, size);
#endif
@ -69,6 +110,17 @@ forceinline long __sysv_write(long fd, const void *data, unsigned long size) {
: "=a"(ax), "=d"(dx)
: "0"(__NR_write), "D"(fd), "S"(data), "1"(size)
: "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)fd;
register long r1 asm("x1") = (long)data;
register long r2 asm("x2") = (long)size;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_write, fd, data, size);
#endif
@ -82,6 +134,17 @@ forceinline long __sysv_mprotect(void *addr, size_t size, long prot) {
: "=a"(ax), "=d"(dx)
: "0"(__NR_mprotect), "D"(addr), "S"(size), "1"(prot)
: "memory", "cc");
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)addr;
register long r1 asm("x1") = (long)size;
register long r2 asm("x2") = (long)prot;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(226), "r"(r0), "r"(r1), "r"(r2)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_mprotect, addr, size, prot);
#endif
@ -95,6 +158,14 @@ forceinline int __sysv_getpid(void) {
: "=a"(ax)
: "0"(__NR_getpid)
: "rdx", "memory", "cc");
#elif defined(__aarch64__)
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n"
"svc\t0"
: "=r"(res_x0)
: "i"(172)
: "x8", "memory");
ax = res_x0;
#else
ax = syscall(__NR_getpid);
#endif

View file

@ -210,7 +210,7 @@ void _log_exit(int) wontreturn;
#define ARGS unsigned, const char *, int, FILE *, const char *
#define ATTR paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5, 6))
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;

26
libc/log/logfile.c Normal file
View file

@ -0,0 +1,26 @@
/*-*- 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 2020 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/log/log.h"
#include "libc/stdio/stdio.h"
FILE *__log_file;
__attribute__((__constructor__)) static void init(void) {
__log_file = stderr;
}

View file

@ -1,24 +0,0 @@
/*-*- 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 2020 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/intrin/initializer.internal.h"
#include "libc/stdio/stdio.h"
FILE *__log_file;
INITIALIZER(401, _init_log_file, (__log_file = stderr));

View file

@ -20,7 +20,7 @@
#include "libc/macros.internal.h"
.bss
.align 4
.balign 4
__log_level:
.long 0
.endobj __log_level,globl

View file

@ -13,20 +13,20 @@
#define TRUE 1
#define FALSE 0
#define IS2POW(X) (!((X) & ((X)-1)))
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
#define ROUNDDOWN(X, K) ((X) & -(K))
#define IS2POW(X) (!((X) & ((X)-1)))
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
#define ROUNDDOWN(X, K) ((X) & -(K))
#ifndef __ASSEMBLER__
#define ABS(X) ((X) >= 0 ? (X) : -(X))
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
#define ABS(X) ((X) >= 0 ? (X) : -(X))
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
#else
// The GNU assembler does not grok the ?: ternary operator; furthermore,
// boolean expressions yield -1 and 0 for "true" and "false", not 1 and 0.
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
#endif
#define PASTE(A, B) __PASTE(A, B)
#define STRINGIFY(A) __STRINGIFY(A)
@ -43,9 +43,31 @@
#ifdef __ASSEMBLER__
// clang-format off
#if __MNO_VZEROUPPER__ + 0
#define vzeroupper
#endif
// Ends function definition.
// @cost saves 1-3 lines of code
.macro .endfn name:req bnd vis
.size "\name",.-"\name"
.type "\name",@function
.ifnb \bnd
.\bnd "\name"
.endif
.ifnb \vis
.\vis "\name"
.endif
.endm
// Ends variable definition.
// @cost saves 1-3 lines of code
.macro .endobj name:req bnd vis
.size "\name",.-"\name"
.type "\name",@object
.ifnb \bnd
.\bnd "\name"
.endif
.ifnb \vis
.\vis "\name"
.endif
.endm
// Shorthand notation for widely-acknowledged sections.
.macro .rodata
@ -77,7 +99,7 @@
.endm
.macro .text.modernity
.section .text.modernity,"ax",@progbits
.align 16
.balign 16
.endm
.macro .text.antiquity
.section .text.antiquity,"ax",@progbits
@ -95,6 +117,51 @@
.section .text.windows,"ax",@progbits
.endm
// Mergeable NUL-terminated UTF-8 string constant section.
//
// @note linker de-dupes C strings here across whole compile
// @note therefore item/values are reordered w.r.t. link order
// @note therefore no section relative addressing
.macro .rodata.str1.1
.section .rodata.str1.1,"aMS",@progbits,1
.align 1
.endm
// Locates unreferenced code invulnerable to --gc-sections.
.macro .keep.text
.section .keep.text,"ax",@progbits
.endm
// Flags code as only allowed for testing purposes.
.macro .testonly
.section .test,"ax",@progbits
.endm
// Makes code runnable while code morphing.
.macro .privileged
.section .privileged,"ax",@progbits
.endm
// Pulls unrelated module into linkage.
//
// In order for this technique to work with --gc-sections, another
// module somewhere might want to weakly reference whats yoinked.
.macro .yoink symbol:req
.section .yoink
#ifdef __x86_64__
nopl "\symbol"(%rip)
#elif defined(__aarch64__)
b "\symbol"
#endif
.previous
.endm
#ifdef __x86_64__
#if __MNO_VZEROUPPER__ + 0
#define vzeroupper
#endif
// Mergeable numeric constant sections.
//
// @note linker de-dupes item/values across whole compile
@ -129,31 +196,6 @@
.align 4
.endm
// Mergeable NUL-terminated UTF-8 string constant section.
//
// @note linker de-dupes C strings here across whole compile
// @note therefore item/values are reordered w.r.t. link order
// @note therefore no section relative addressing
.macro .rodata.str1.1
.section .rodata.str1.1,"aMS",@progbits,1
.align 1
.endm
// Locates unreferenced code invulnerable to --gc-sections.
.macro .keep.text
.section .keep.text,"ax",@progbits
.endm
// Flags code as only allowed for testing purposes.
.macro .testonly
.section .test,"ax",@progbits
.endm
// Makes code runnable while code morphing.
.macro .privileged
.section .privileged,"ax",@progbits
.endm
// Loads address of errno into %rcx
.macro .errno
call __errno_location
@ -197,32 +239,6 @@
.weak \canonical
.endm
// Ends function definition.
// @cost saves 1-3 lines of code
.macro .endfn name:req bnd vis
.size "\name",.-"\name"
.type "\name",@function
.ifnb \bnd
.\bnd "\name"
.endif
.ifnb \vis
.\vis "\name"
.endif
.endm
// Ends variable definition.
// @cost saves 1-3 lines of code
.macro .endobj name:req bnd vis
.size "\name",.-"\name"
.type "\name",@object
.ifnb \bnd
.\bnd "\name"
.endif
.ifnb \vis
.\vis "\name"
.endif
.endm
// LOOP Instruction Replacement.
.macro .loop label:req
.byte 0x83
@ -341,16 +357,6 @@
.byte 0x0f,0x1f,0x40,0x00
.endm
// Pulls unrelated module into linkage.
//
// In order for this technique to work with --gc-sections, another
// module somewhere might want to weakly reference whats yoinked.
.macro .yoink symbol:req
.section .yoink
nopl "\symbol"(%rip)
.previous
.endm
// Calls Windows function.
//
// @param cx,dx,r8,r9,stack
@ -542,6 +548,14 @@
#endif
.endm
#else
.macro .underrun
.endm
.macro .overrun
.endm
// clang-format on
#endif /* __x86_64__ */
#endif /* __ASSEMBLER__ */
#endif /* COSMOPOLITAN_LIBC_MACROS_H_ */

23
libc/nexgen32e/auxv2.c Normal file
View file

@ -0,0 +1,23 @@
/*-*- 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 2023 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/runtime/runtime.h"
#ifdef __aarch64__
unsigned long *__auxv;
#endif

View file

@ -21,7 +21,7 @@
// Environment variable pointer list.
.bss
.align 8
.balign 8
environ:
.quad 0
.endobj environ,globl

Some files were not shown because too many files have changed in this diff Show more