mirror of
https://github.com/jart/cosmopolitan.git
synced 2026-11-08 01:58:20 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
face6b61d5 | ||
|
|
e345b42d78 | ||
|
|
e85aeda4ba | ||
|
|
3e1fd1d962 | ||
|
|
b740cca642 | ||
|
|
c797f139bb | ||
|
|
adebc5e4c3 | ||
|
|
5f1415af3a | ||
|
|
02b4a5c824 | ||
|
|
45b994ea23 | ||
|
|
2c15efc249 | ||
|
|
667ab245fe | ||
|
|
08d3700c15 | ||
|
|
6f35bd47ab | ||
|
|
bfa8581537 |
No files matched your search
@@ -206,7 +206,7 @@ depend: o/$(MODE)/depend
|
||||
tags: TAGS HTAGS
|
||||
|
||||
o/$(MODE)/.x:
|
||||
@$(MKDIR) $(@D) && touch $@
|
||||
@mkdir -p $(@D) && touch $@
|
||||
|
||||
o/$(MODE)/srcs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS),$(dir $(x))))
|
||||
$(file >$@) $(foreach x,$(SRCS),$(file >>$@,$(x)))
|
||||
@@ -215,15 +215,15 @@ o/$(MODE)/hdrs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS) $(
|
||||
$(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x)))
|
||||
|
||||
o/$(MODE)/depend: o/$(MODE)/.x o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt $(SRCS) $(HDRS) $(INCS)
|
||||
@build/mkdeps -o $@ -r o/$(MODE)/ o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt
|
||||
@$(COMPILE) -AMKDEPS $(MKDEPS) -o $@ -r o/$(MODE)/ o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt
|
||||
|
||||
TAGS: o/$(MODE)/srcs.txt $(SRCS)
|
||||
@rm -f $@
|
||||
@ACTION=TAGS TARGET=$@ build/do $(TAGS) $(TAGSFLAGS) -L $< -o $@
|
||||
@$(COMPILE) -ATAGS -T$@ $(TAGS) $(TAGSFLAGS) -L $< -o $@
|
||||
|
||||
HTAGS: o/$(MODE)/hdrs.txt $(HDRS)
|
||||
@rm -f $@
|
||||
@ACTION=TAGS TARGET=$@ build/do build/htags -L $< -o $@
|
||||
@$(COMPILE) -ATAGS -T$@ build/htags -L $< -o $@
|
||||
|
||||
loc: o/$(MODE)/tool/build/summy.com
|
||||
find -name \*.h -or -name \*.c -or -name \*.S | \
|
||||
@@ -315,7 +315,7 @@ o/cosmopolitan.h: \
|
||||
o/$(MODE)/tool/build/rollup.com \
|
||||
libc/integral/normalize.inc \
|
||||
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
|
||||
@ACTION=ROLLUP TARGET=$@ build/do $^ >$@
|
||||
@$(COMPILE) -AROLLUP -T$@ $^ >$@
|
||||
|
||||
o/cosmopolitan.html: \
|
||||
o/$(MODE)/third_party/chibicc/chibicc.com.dbg \
|
||||
|
||||
@@ -23,8 +23,8 @@ five files to get started:
|
||||
|
||||
```sh
|
||||
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.2.zip
|
||||
unzip cosmopolitan-amalgamated-0.2.zip
|
||||
echo 'main() { printf("hello world\n"); }' >hello.c
|
||||
unzip cosmopolitan-amalgamation-0.2.zip
|
||||
printf 'main() { printf("hello world\\n"); }\n' >hello.c
|
||||
gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
|
||||
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
|
||||
-include cosmopolitan.h crt.o ape.o cosmopolitan.a
|
||||
|
||||
@@ -117,11 +117,7 @@ rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
||||
//
|
||||
// @param dl is drive number
|
||||
// @noreturn
|
||||
ape_mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
jno 2f # MZ: bytes on last page
|
||||
jo 2f # MZ: 512-byte pages in file
|
||||
.ascii "='" # MZ: reloc table entry count
|
||||
.ascii "\n\0" # MZ: data segment file offset / 16
|
||||
ape_mz: .asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
|
||||
.short 0x1000 # MZ: lowers upper bound load / 16
|
||||
.short 0xf800 # MZ: roll greed on bss
|
||||
.short 0 # MZ: lower bound on stack segment
|
||||
@@ -174,6 +170,8 @@ ape_mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
|
||||
#if SupportsMetal()
|
||||
|
||||
// Disk Operating System Stub
|
||||
//
|
||||
// @param dl is drive number
|
||||
@@ -190,7 +188,7 @@ stub: mov $0x40,%dl # *literally* dos
|
||||
3: .byte 0xbd,0,0 # a.k.a. mov imm,%bp
|
||||
jmp pc # real mode, is real
|
||||
jmp _start # surprise it's unix
|
||||
// .endfn stub
|
||||
.endfn stub
|
||||
|
||||
/*─────────────────────────────────────────────────────────────────────────────╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § ibm personal computer │
|
||||
@@ -224,7 +222,6 @@ pc: cld
|
||||
xor %cx,%cx
|
||||
mov %cx,%es
|
||||
rlstack %di,%cx
|
||||
#if SupportsMetal()
|
||||
push %cs # memcpy() [relocate this page]
|
||||
pop %ds
|
||||
call 1f
|
||||
@@ -472,6 +469,8 @@ ape_disk:
|
||||
╚────────────────────────────────────────────────────────────────────────────│─╝
|
||||
the bourne executable & linkable format */
|
||||
|
||||
#if SupportsSystemv()
|
||||
|
||||
#if SupportsWindows() || SupportsXnu()
|
||||
apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.ascii "o=\"$(command -v \"$0\")\"\n"
|
||||
@@ -488,6 +487,36 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.ascii "el"
|
||||
#endif
|
||||
.ascii "if exec 7<> \"$o\"; then\n"
|
||||
|
||||
// Writes 32-bit ELF header if --32 is the first argument
|
||||
// This should be changed to check $(uname -m) on ENOEXEC
|
||||
.ascii "if [ x\"$1\" = x--32 ]; then\n"
|
||||
.ascii "printf '"
|
||||
.ascii "\\177ELF" # 0x0: ⌂ELF
|
||||
.ascii "\\1" # 4: legacy mode
|
||||
.ascii "\\1" # 5: little endian
|
||||
.ascii "\\1" # 6: elf v1.o
|
||||
.ascii "\\011" # 7: FreeBSD
|
||||
.ascii "\\0" # 8: os/abi ver.
|
||||
.ascii "\\0\\0\\0" # 9: padding 3/7
|
||||
.ascii "\\0\\0\\0\\0" # padding 4/7
|
||||
.ascii "\\2\\0" # 10: εxεcµταblε
|
||||
.ascii "\\3\\0" # 12: i386
|
||||
.ascii "\\1\\0\\0\\0" # 14: elf v1.o
|
||||
.shstub ape_elf32_entry,4 # 18: e_entry
|
||||
.shstub ape_elf32_phoff,4 # 1c: e_phoff
|
||||
.shstub ape_elf32_shoff,4 # 20: e_shoff
|
||||
.ascii "\\0\\0\\0\\0" # 24: e_flags
|
||||
.ascii "\\100\\0" # 28: e_ehsize
|
||||
.ascii "\\040\\0" # 2a: e_phentsize
|
||||
.shstub ape_elf32_phnum,2 # 2c: e_phnum
|
||||
.ascii "\\0\\0" # 2e: e_shentsize
|
||||
.shstub ape_elf32_shnum,2 # 30: e_shnum
|
||||
.shstub ape_elf32_shstrndx,2 # 32: e_shstrndx
|
||||
.ascii "' >&7\n"
|
||||
.ascii "else\n"
|
||||
|
||||
// Standard 64-bit ELF Header
|
||||
.ascii "printf '"
|
||||
.ascii "\\177ELF" # 0x0: ⌂ELF
|
||||
.ascii "\\2" # 4: long mode
|
||||
@@ -509,8 +538,10 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.shstub ape_elf_phnum,2 # 38: e_phnum
|
||||
.ascii "\\0\\0" # 3a: e_shentsize
|
||||
.shstub ape_elf_shnum,2 # 3c: e_shnum
|
||||
.shstub ape_elf_shstrndx,2 # 3e: e_shstrndx
|
||||
.shstub ape_elf_shstrndx,2 # 3e: e_shstrndx
|
||||
.ascii "' >&7\n"
|
||||
.ascii "fi\n"
|
||||
|
||||
.ascii "exec 7<&-\n"
|
||||
.ascii "fi\n"
|
||||
.ascii "exec \"$0\" \"$@\"\n" # etxtbsy tail recursion
|
||||
@@ -530,10 +561,6 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
|
||||
.section .elf.phdrs,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
.type ape_phdrs,@object
|
||||
.globl ape_phdrs
|
||||
ape_phdrs:
|
||||
.long PT_LOAD # text segment
|
||||
.long PF_R|PF_X
|
||||
.stub ape_rom_offset,quad
|
||||
@@ -542,7 +569,6 @@ ape_phdrs:
|
||||
.stub ape_rom_filesz,quad
|
||||
.stub ape_rom_memsz,quad
|
||||
.stub ape_rom_align,quad
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_LOAD # data segment
|
||||
.long PF_R|PF_W
|
||||
.stub ape_ram_offset,quad
|
||||
@@ -554,7 +580,6 @@ ape_phdrs:
|
||||
#if SupportsLinux()
|
||||
// Linux ignores mprotect() and returns 0 without this lool
|
||||
// It has nothing to do with the stack, which is still exec
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_GNU_STACK # p_type
|
||||
.long PF_R|PF_W # p_flags
|
||||
.quad 0 # p_offset
|
||||
@@ -565,7 +590,6 @@ ape_phdrs:
|
||||
.quad 16 # p_align
|
||||
#endif
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_NOTE # notes
|
||||
.long PF_R
|
||||
.stub ape_note_offset,quad
|
||||
@@ -605,6 +629,8 @@ netbsd.ident:
|
||||
.previous
|
||||
#endif /* SupportsNetbsd() */
|
||||
|
||||
#endif /* SupportsSystemv() */
|
||||
|
||||
/* ▄▄███▄
|
||||
▄▄████████▄
|
||||
▄█████████████▄
|
||||
@@ -1517,17 +1543,20 @@ long: push $GDT_LONG_DATA
|
||||
xor %ebp,%ebp
|
||||
mov $REAL_STACK_FRAME+FRAMESIZE,%esp
|
||||
call __map_image
|
||||
ezlea metal,ax
|
||||
ezlea metal.thunk,ax
|
||||
jmp *%rax
|
||||
.endfn long
|
||||
|
||||
// Long mode in virtual address space.
|
||||
// @noreturn
|
||||
metal:
|
||||
metal.thunk:
|
||||
#if USE_SYMBOL_HACK
|
||||
.byte 0x0f,0x1f,0207 # nop rdi binbase
|
||||
.long (IMAGE_BASE_VIRTUAL-IMAGE_BASE_REAL)/512
|
||||
#endif
|
||||
// 𝑠𝑙𝑖𝑑𝑒
|
||||
.endfn metal.thunk
|
||||
metal:
|
||||
xor %eax,%eax # clear bss
|
||||
mov $ape_bss_vaddr,%edi
|
||||
mov $ape_bss_memsz,%ecx
|
||||
@@ -1565,6 +1594,7 @@ metal:
|
||||
.type ape_note,@object
|
||||
.type ape_note_end,@object
|
||||
.type ape_note_vaddr,@object
|
||||
.type ape_phdrs,@object
|
||||
.type ape_pe_sections,@object
|
||||
.type ape_pe_sections_end,@object
|
||||
.type ape_text_nops,@object
|
||||
|
||||
+14
-6
@@ -201,21 +201,22 @@ SECTIONS {
|
||||
|
||||
/* Real Mode */
|
||||
KEEP(*(.head))
|
||||
. += 1;
|
||||
|
||||
/* Executable & Linkable Format */
|
||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(ape_phdrs = .);
|
||||
KEEP(*(.elf.phdrs))
|
||||
HIDDEN(ape_phdrs_end = .);
|
||||
. += 1;
|
||||
HIDDEN(ape_phdrs32 = .);
|
||||
KEEP(*(.elf.phdrs32))
|
||||
HIDDEN(ape_phdrs32_end = .);
|
||||
|
||||
/* OpenBSD */
|
||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(ape_note = .);
|
||||
KEEP(*(.note.openbsd.ident))
|
||||
KEEP(*(.note.netbsd.ident))
|
||||
HIDDEN(ape_note_end = .);
|
||||
. += 1;
|
||||
|
||||
/* Portable Executable */
|
||||
KEEP(*(.pe.header))
|
||||
@@ -248,7 +249,7 @@ SECTIONS {
|
||||
/*END: realmode addressability guarantee */
|
||||
|
||||
/* Normal Code */
|
||||
*(.start)
|
||||
KEEP(*(.start))
|
||||
KEEP(*(.initprologue))
|
||||
KEEP(*(SORT_BY_NAME(.init.*)))
|
||||
KEEP(*(.init))
|
||||
@@ -447,6 +448,13 @@ PFSTUB4(ape_elf_phnum, (ape_phdrs_end - ape_phdrs) / 56);
|
||||
PFSTUB4(ape_elf_shnum, 0);
|
||||
PFSTUB4(ape_elf_shstrndx, 0);
|
||||
|
||||
PFSTUB4(ape_elf32_entry, _start32);
|
||||
PFSTUB4(ape_elf32_phoff, RVA(ape_phdrs32));
|
||||
PFSTUB4(ape_elf32_shoff, 0);
|
||||
PFSTUB4(ape_elf32_phnum, (ape_phdrs32_end - ape_phdrs32) / 32);
|
||||
PFSTUB4(ape_elf32_shnum, 0);
|
||||
PFSTUB4(ape_elf32_shstrndx, 0);
|
||||
|
||||
HIDDEN(__privileged_addr = ROUNDDOWN(__privileged_start, PAGESIZE));
|
||||
HIDDEN(__privileged_size = (ROUNDUP(__privileged_end, PAGESIZE) -
|
||||
ROUNDDOWN(__privileged_start, PAGESIZE)));
|
||||
|
||||
+1
-1
@@ -20,8 +20,8 @@ APE = $(APE_DEPS) \
|
||||
o/$(MODE)/ape/ape.lds
|
||||
|
||||
APELINK = \
|
||||
ACTION=LINK.ape \
|
||||
$(COMPILE) \
|
||||
-ALINK.ape \
|
||||
$(LINK) \
|
||||
$(LINKARGS) \
|
||||
$(OUTPUT_OPTION)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Cosmopolitan Archiver
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This goes 100x faster than ar and ranlib.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/archive rcsD library.a foo.o ...
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
if [ -x "o//tool/build/ar.com" ]; then
|
||||
set -- "o//tool/build/ar.com" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/ar.com ]; then
|
||||
mkdir -p o/build/bootstrap &&
|
||||
cp -f build/bootstrap/ar.com o/build/bootstrap/ar.com.$$ &&
|
||||
mv -f o/build/bootstrap/ar.com.$$ o/build/bootstrap/ar.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/ar.com "$@"
|
||||
fi
|
||||
OUT=$3
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# else
|
||||
# # some of these windows nt archives are quite huge
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
"$@" >/dev/null && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "archive $REASON:" "$*" >&2
|
||||
exit 1
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Assembler Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal assembler commands that're transparently
|
||||
# passed-through. It adds ephemeral logging and directory creation.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# TARGET=program build/assemble as -o program program.o
|
||||
#
|
||||
# SEE ALSO
|
||||
#
|
||||
# https://justine.storage.googleapis.com/perm/as.pdf
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-OBJECTIFY.s}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
if [ "$TARGET" ]; then
|
||||
TARGETDIR="${TARGET%/*}"
|
||||
if [ "$TARGETDIR" != "$TARGET" ] && [ ! -d "$TARGETDIR" ]; then
|
||||
$MKDIR "$TARGETDIR" || exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
"$@" && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "assemble failed:" "$*" >&2
|
||||
exit 1
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
-298
@@ -1,298 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU/LLVM Compiler Frontend Frontend
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This wrapper script filters out certain flags so the compiler won't
|
||||
# whine, and passes extra information to the preprocessor.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/compile cc -o program program.c
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
if [ "$1" = "clang-10" ]; then
|
||||
if ! command -v clang-10 >/dev/null; then
|
||||
shift
|
||||
set -- o/third_party/gcc/bin/x86_64-linux-musl-gcc "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "clang++-10" ]; then
|
||||
if ! command -v clang++-10 >/dev/null; then
|
||||
shift
|
||||
set -- o/third_party/gcc/bin/x86_64-linux-musl-g++ "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
GZME=
|
||||
ASAN=
|
||||
UBSAN=
|
||||
PLAT="${1%% *}"
|
||||
FDIAGNOSTIC_COLOR=
|
||||
CCNAME=${CCNAME:-gcc}
|
||||
CCVERSION=${CCVERSION:-4}
|
||||
COUNTERMAND=
|
||||
|
||||
# The GNU Compiler Collection passes a lot of CFLAGS to the preprocessor
|
||||
# (which we call CCFLAGS) but it should pass more; and we do just that.
|
||||
NOPG=0
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
INVISIBLE=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
if [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
set -- "$@" "$x"
|
||||
OUTARG=1
|
||||
;;
|
||||
-w)
|
||||
set -- "$@" "$x" -D__W__
|
||||
;;
|
||||
-x-no-pg)
|
||||
NOPG=1
|
||||
;;
|
||||
-pg)
|
||||
if [ $NOPG -eq 0 ] && [ $INVISIBLE -eq 0 ]; then
|
||||
set -- "$@" "$x" -D__PG__ # @see libc/macros.h
|
||||
fi
|
||||
;;
|
||||
-mfentry)
|
||||
if [ $NOPG -eq 0 ] && [ $INVISIBLE -eq 0 ]; then
|
||||
set -- "$@" "$x" -D__MFENTRY__
|
||||
fi
|
||||
;;
|
||||
-fomit-frame-pointer)
|
||||
INVISIBLE=1
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
-mno-vzeroupper)
|
||||
set -- "$@" "$x" -Wa,-msse2avx -D__MNO_VZEROUPPER__
|
||||
;;
|
||||
-fsanitize=address)
|
||||
ASAN="$x -D__FSANITIZE_ADDRESS__"
|
||||
;;
|
||||
-fsanitize=undefined)
|
||||
# UBSAN w/ -fdata-sections exceeds ELF's 65,280 section limit
|
||||
UBSAN="$x -fno-data-sections"
|
||||
;;
|
||||
-fno-sanitize=address)
|
||||
ASAN=
|
||||
;;
|
||||
-fno-sanitize=ubsan)
|
||||
UBSAN=
|
||||
;;
|
||||
-fno-sanitize=all)
|
||||
ASAN=
|
||||
UBSAN=
|
||||
;;
|
||||
-mnop-mcount)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x" -D__MNOP_MCOUNT__
|
||||
fi
|
||||
;;
|
||||
-mrecord-mcount)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x" -D__MRECORD_MCOUNT__
|
||||
fi
|
||||
;;
|
||||
-fsanitize=implicit*integer*)
|
||||
if ! [ "$CCNAME" = "gcc" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-f*sanitize*|-gz*|-*stack-protector*|-fvect-cost*|-mstringop*)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-freorder-blocks-and-partition|-fstack-clash-protection)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 8 ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-fdiagnostic-color=*)
|
||||
FDIAGNOSTIC_COLOR=$x
|
||||
;;
|
||||
-fopt-info*=*.optinfo)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 9 ]; then
|
||||
GZME="$GZME ${x##*=}"
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-R*) # e.g. clang's -Rpass-missed=all
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-fsave-optimization-record) # clang only
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -z "$FDIAGNOSTIC_COLOR" ] && [ "$TERM" != "dumb" ]; then
|
||||
FDIAGNOSTIC_COLOR=-fdiagnostics-color=always
|
||||
fi
|
||||
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
FIRST=1
|
||||
for x; do
|
||||
# clang's assembler isn't complete yet
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set -- \
|
||||
"$x" \
|
||||
-fno-integrated-as \
|
||||
-Wno-unused-command-line-argument \
|
||||
-Wno-incompatible-pointer-types-discards-qualifiers
|
||||
FIRST=0
|
||||
continue
|
||||
fi
|
||||
TRAPV= # clang handles -f{,no-}{trap,wrap}v weird
|
||||
# removes flags clang whines about
|
||||
case "$x" in
|
||||
-gstabs) ;;
|
||||
-ftrapv) ;;
|
||||
-ffixed-*) ;;
|
||||
-fcall-saved*) ;;
|
||||
-fsignaling-nans) ;;
|
||||
-fcx-limited-range) ;;
|
||||
-fno-fp-int-builtin-inexact) ;;
|
||||
-Wno-unused-but-set-variable) ;;
|
||||
-Wunsafe-loop-optimizations) ;;
|
||||
-mdispatch-scheduler) ;;
|
||||
-ftracer) ;;
|
||||
-frounding-math) ;;
|
||||
-fmerge-constants) ;;
|
||||
-fmodulo-sched) ;;
|
||||
-msse2avx)
|
||||
set -- "$@" -Wa,-msse2avx
|
||||
;;
|
||||
-fopt-info-vec) ;;
|
||||
-fopt-info-vec-missed) ;;
|
||||
-fmodulo-sched-allow-regmoves) ;;
|
||||
-fgcse-*) ;;
|
||||
-freschedule-modulo-scheduled-loops) ;;
|
||||
-freschedule-modulo-scheduled-loops) ;;
|
||||
-fipa-pta) ;;
|
||||
-fsched2-use-superblocks) ;;
|
||||
-fbranch-target-load-optimize) ;;
|
||||
-fdelete-dead-exceptions) ;;
|
||||
-funsafe-loop-optimizations) ;;
|
||||
-fcall-used*) ;;
|
||||
-mmitigate-rop) ;;
|
||||
-mnop-mcount) ;;
|
||||
-fno-align-jumps) ;;
|
||||
-fno-align-labels) ;;
|
||||
-fno-align-loops) ;;
|
||||
-fivopts) ;;
|
||||
-fschedule-insns) ;;
|
||||
-fno-semantic-interposition) ;;
|
||||
-mno-fentry) ;;
|
||||
-f*shrink-wrap) ;;
|
||||
-f*schedule-insns2) ;;
|
||||
-fvect-cost-model=*) ;;
|
||||
-fsimd-cost-model=*) ;;
|
||||
-fversion-loops-for-strides) ;;
|
||||
-fopt-info*) ;;
|
||||
-f*var-tracking-assignments) ;;
|
||||
-femit-struct-debug-baseonly) ;;
|
||||
-ftree-loop-vectorize) ;;
|
||||
-gdescribe-dies) ;;
|
||||
-flimit-function-alignment) ;;
|
||||
-ftree-loop-im) ;;
|
||||
-fno-instrument-functions) ;;
|
||||
-fstack-clash-protection) ;;
|
||||
-mstringop-strategy=*) ;;
|
||||
-mpreferred-stack-boundary=*) ;;
|
||||
-*stack-protector*) ;; # clang requires segmented memory for this
|
||||
-f*gnu-unique) ;;
|
||||
-Wframe-larger-than=*) ;;
|
||||
-f*whole-program) ;;
|
||||
-Wa,--size-check=*) ;;
|
||||
-Wa,--listing*) ;;
|
||||
-mfpmath=sse+387) ;;
|
||||
-Wa,--noexecstack) ;;
|
||||
-freg-struct-return) ;;
|
||||
-mcall-ms2sysv-xlogues) ;;
|
||||
-mno-vzeroupper)
|
||||
set -- "$@" -mllvm -x86-use-vzeroupper=0
|
||||
;;
|
||||
-Wa,-a*)
|
||||
x="${x#*=}"
|
||||
if [ "$x" ] && [ -p "$x" ]; then
|
||||
printf '' >"$x"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
set -- "$@" -fno-stack-protector
|
||||
else
|
||||
# removes flags only clang supports
|
||||
FIRST=1
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
case "$x" in
|
||||
-Oz) set -- "$@" -Os ;;
|
||||
*) set -- "$@" "$x" ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
set -- "$@" -no-canonical-prefixes $FDIAGNOSTIC_COLOR $ASAN $UBSAN $COUNTERMAND
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-COMPILE}" "${TARGET:-$OUT}" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
if "$@"; then
|
||||
for f in $GZME; do
|
||||
if GZ=${GZ:-$(command -v gzip)}; then
|
||||
if [ -f "$f" ]; then
|
||||
build/actuallynice $GZ $ZFLAGS -qf $f &
|
||||
fi
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "\n$LOGFMT" "$CCNAME $CCVERSION: compile $REASON:" "$*" >&2
|
||||
exit 1
|
||||
+16
-44
@@ -43,14 +43,9 @@
|
||||
# TARGET_ARCH microarchitecture flags (e.g. -march=native)
|
||||
|
||||
V ?= 1
|
||||
LC_ALL = C.UTF-8
|
||||
LC_ALL = C
|
||||
SOURCE_DATE_EPOCH = 0
|
||||
|
||||
DD ?= /bin/dd
|
||||
CP ?= /bin/cp -f
|
||||
RM ?= /bin/rm -f
|
||||
SED ?= /bin/sed
|
||||
MKDIR ?= /bin/mkdir -p
|
||||
TAGS ?= /usr/bin/ctags # emacs source builds or something breaks it
|
||||
ARFLAGS = rcsD
|
||||
ZFLAGS ?=
|
||||
@@ -62,12 +57,15 @@ CLANG = clang-10
|
||||
FC = gfortran #/opt/cross9f/bin/x86_64-linux-musl-gfortran
|
||||
|
||||
# see build/compile, etc. which run third_party/gcc/unbundle.sh
|
||||
AR = build/bootstrap/ar.com
|
||||
PKG = build/bootstrap/package.com
|
||||
MKDEPS = build/bootstrap/mkdeps.com
|
||||
ZIPOBJ = build/bootstrap/zipobj.com
|
||||
AS = o/third_party/gcc/bin/x86_64-linux-musl-as
|
||||
CC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
|
||||
CXX = o/third_party/gcc/bin/x86_64-linux-musl-g++
|
||||
CXXFILT = o/third_party/gcc/bin/x86_64-linux-musl-c++filt
|
||||
LD = o/third_party/gcc/bin/x86_64-linux-musl-ld.bfd
|
||||
AR = build/archive
|
||||
NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
|
||||
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
|
||||
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
|
||||
@@ -78,47 +76,16 @@ ADDR2LINE = o/third_party/gcc/bin/x86_64-linux-musl-addr2line
|
||||
COMMA := ,
|
||||
PWD := $(shell pwd)
|
||||
IMAGE_BASE_VIRTUAL ?= 0x400000
|
||||
HELLO := $(shell build/hello)
|
||||
TMPDIR := $(shell build/findtmp)
|
||||
LOGFMT := $(shell build/getlogfmt)
|
||||
COMPILE := $(shell build/getcompile)
|
||||
CCNAME := $(shell build/getccname $(CC))
|
||||
CCVERSION := $(shell build/getccversion $(CC))
|
||||
BLAH1 := $(shell build/zipobj 2>/dev/null)
|
||||
BLAH2 := $(shell build/package 2>/dev/null)
|
||||
COMPILE := $(shell build/getcompile) -V$(shell build/getccversion $(CC))
|
||||
|
||||
export ADDR2LINE
|
||||
export CCNAME
|
||||
export CCVERSION
|
||||
export COMPILE
|
||||
export CP
|
||||
export DD
|
||||
export GZ
|
||||
export IMAGE_BASE_VIRTUAL
|
||||
export LC_ALL
|
||||
export LOGFMT
|
||||
export MKDIR
|
||||
export MODE
|
||||
export OBJDUMP
|
||||
export RM
|
||||
export SED
|
||||
export SOURCE_DATE_EPOCH
|
||||
export TMPDIR
|
||||
export V
|
||||
export ZFLAGS
|
||||
|
||||
unexport COMPILER_PATH
|
||||
unexport CPATH
|
||||
unexport CPLUS_INCLUDE_PATH
|
||||
unexport C_INCLUDE_PATH
|
||||
unexport DEPENDENCIES_OUTPUT
|
||||
unexport GCC_COMPARE_DEBUG
|
||||
unexport GCC_EXEC_PREFIX
|
||||
unexport LANG
|
||||
unexport LC_CTYPE
|
||||
unexport LC_MESSAGES
|
||||
unexport LIBRARY_PATH
|
||||
unexport OBJC_INCLUDE_PATH
|
||||
unexport SUNPRO_DEPENDENCIES
|
||||
|
||||
FTRACE = \
|
||||
-pg
|
||||
@@ -197,6 +164,7 @@ DEFAULT_LDFLAGS = \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m elf_x86_64 \
|
||||
--gc-sections \
|
||||
--build-id=none \
|
||||
--no-dynamic-linker \
|
||||
-z max-page-size=0x1000
|
||||
@@ -289,8 +257,8 @@ COMPILE.F.flags = $(cc.flags) $(cpp.flags) $(copt.flags) $(f.flags)
|
||||
COMPILE.i.flags = $(cc.flags) $(copt.flags) $(c.flags)
|
||||
COMPILE.ii.flags = $(cc.flags) $(copt.flags) $(cxx.flags)
|
||||
LINK.flags = $(DEFAULT_LDFLAGS) $(CONFIG_LDFLAGS) $(LDFLAGS)
|
||||
OBJECTIFY.c.flags = $(OBJECTIFY.S.flags) $(c.flags)
|
||||
OBJECTIFY.cxx.flags = $(OBJECTIFY.S.flags) $(cxx.flags)
|
||||
OBJECTIFY.c.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(c.flags)
|
||||
OBJECTIFY.cxx.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(cxx.flags)
|
||||
OBJECTIFY.s.flags = $(ASONLYFLAGS) $(s.flags)
|
||||
OBJECTIFY.S.flags = $(copt.flags) $(cc.flags) $(o.flags) $(cpp.flags) $(S.flags)
|
||||
OBJECTIFY.f.flags = $(copt.flags) $(cc.flags) $(o.flags) $(copt.flags) $(S.flags) $(f.flags)
|
||||
@@ -313,8 +281,7 @@ PREPROCESS = $(CC) $(PREPROCESS.flags)
|
||||
PREPROCESS.lds = $(CC) $(PREPROCESS.lds.flags)
|
||||
LINK = $(LD) $(LINK.flags)
|
||||
ELF = o/libc/elf/elf.lds
|
||||
ELFLINK = ACTION=LINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION)
|
||||
ARCHIVE = $(AR) $(ARFLAGS)
|
||||
ELFLINK = $(COMPILE) -ALINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION)
|
||||
LINKARGS = $(patsubst %.lds,-T %.lds,$(call uniqr,$(LD.libs) $(filter-out %.pkg,$^)))
|
||||
LOLSAN = build/lolsan -b $(IMAGE_BASE_VIRTUAL)
|
||||
|
||||
@@ -332,6 +299,11 @@ OBJECTIFY.greg.c = \
|
||||
-fno-sanitize=all \
|
||||
-c
|
||||
|
||||
OBJECTIFY.i386.c = \
|
||||
$(OBJECTIFY.c) \
|
||||
-m32 \
|
||||
-wrapper build/i386ify.sh
|
||||
|
||||
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
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Generic Command Runner
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This does auto mkdir and ephemeral logging.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/do PROG [ARGS...]
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
# Ensure directory creation if -o PATH flag is passed.
|
||||
OUT="$TARGET"
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
-o*)
|
||||
OUT=${x#-o}
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
if [ "$OUT" ]; then
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# Log command.
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Compiler Name Discovery
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Cosmopolitan itself may be built using either GCC and Clang, and our
|
||||
# build irons out many of the differences between the two. This script
|
||||
# determines which one's in play, which is nontrivial, since they tend
|
||||
# to call themselves so many different names.
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
SPECIAL_TEXT=$(
|
||||
$1 --version |
|
||||
sed -n '
|
||||
/chibicc/ {
|
||||
i\
|
||||
chibicc
|
||||
q
|
||||
}
|
||||
/Free Software/ {
|
||||
i\
|
||||
gcc
|
||||
q
|
||||
}
|
||||
/clang/ {
|
||||
i\
|
||||
clang
|
||||
q
|
||||
}
|
||||
')
|
||||
|
||||
if [ -z "$SPECIAL_TEXT" ]; then
|
||||
echo gcc
|
||||
else
|
||||
printf '%s\n' "$SPECIAL_TEXT"
|
||||
fi
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
if ! [ o/build/bootstrap/compile.com -nt build/bootstrap/compile.com ]; then
|
||||
mkdir -p o/build/bootstrap/
|
||||
cp -f build/bootstrap/compile.com o/build/bootstrap/compile.$$.com
|
||||
o/build/bootstrap/compile.$$.com --do-nothing
|
||||
o/build/bootstrap/compile.$$.com -n
|
||||
mv -f o/build/bootstrap/compile.$$.com o/build/bootstrap/compile.com
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Printf Logger Initializer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This program is invoked once by build/definitions.mk to choose the
|
||||
# most appropriate format string when logging command invocations.
|
||||
|
||||
W1=15
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
if [ "$COLUMNS" = "" ]; then
|
||||
if TPUT=$(command -v tput); then
|
||||
COLUMNS=$("$TPUT" cols)
|
||||
else
|
||||
COLUMNS=80
|
||||
fi
|
||||
fi
|
||||
COLUMNS=$((COLUMNS - 1))
|
||||
W2=$((COLUMNS - W1))
|
||||
printf '%%-%ds%%-%ds\\r' "$W1" "$W2"
|
||||
else
|
||||
echo ♥cosmo >&2
|
||||
printf '\\033[F\\033[K%%-%ds%%s\\r\\n' "$W1"
|
||||
fi
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# HELLO BUILD
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# We generate a line at the start of each Makefile run, because if we
|
||||
# use `make V=0` mode then the terminal logging trick we use in
|
||||
# tool/build/compile.c will delete the previous line, and we'd rather
|
||||
# have that line not be the bash prompt that ran make.
|
||||
#
|
||||
# This script is also useful for giving us an indicator each time the
|
||||
# build restarts itself from scratch, which can happen in cases like
|
||||
# when dependencies need to be regenerated by tool/build/mkdeps.c
|
||||
|
||||
echo ♥cosmo >&2
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# gcc -m32 -wrapper build/i386ify.sh -c -o foo.o foo.c
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Compiles 32-bit code inside 64-bit ELF objects.
|
||||
|
||||
if [ "${1##*/}" = as ]; then
|
||||
FIRST=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 0 ]; then
|
||||
set --
|
||||
FIRST=1
|
||||
fi
|
||||
if [ "$x" = "--32" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ "${x##*.}" = s ]; then
|
||||
{
|
||||
printf "\t.section .yoink\n"
|
||||
printf "\tnopl\t_start32\n"
|
||||
printf "\t.previous\n"
|
||||
printf "\t.code32\n"
|
||||
cat "$x"
|
||||
} >"$x".tmp
|
||||
mv -f "$x".tmp "$x"
|
||||
fi
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Linker Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal linker commands that're transparently
|
||||
# passed-through. It adds ephemeral logging and directory creation.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/linker ld -o program program.o
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
OUT=
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-LINK.elf}" "$OUT" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
"$@" && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "link $REASON:" "$*" >&2
|
||||
exit 1
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if [ -x "o/$MODE/tool/build/mkdeps.com" ]; then
|
||||
set -- "o/$MODE/tool/build/mkdeps.com" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/mkdeps.com ]; then
|
||||
mkdir -p o/build/bootstrap &&
|
||||
cp -a build/bootstrap/mkdeps.com \
|
||||
o/build/bootstrap/mkdeps.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/mkdeps.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-MKDEPS}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Disassembly Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal objdump commands that're transparently
|
||||
# passed-through.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/objdump -xd o/tiny/examples/life.com.dbg
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"
|
||||
+4
-5
@@ -23,9 +23,8 @@
|
||||
# - tool/build/runitd.c
|
||||
|
||||
.PRECIOUS: o/$(MODE)/%.com.ok
|
||||
o/$(MODE)/%.com.ok: \
|
||||
o/$(MODE)/tool/build/runit.com.dbg \
|
||||
o/$(MODE)/tool/build/runitd.com \
|
||||
o/$(MODE)/%.com.ok: \
|
||||
o/$(MODE)/tool/build/runit.com \
|
||||
o/$(MODE)/tool/build/runitd.com \
|
||||
o/$(MODE)/%.com
|
||||
@ACTION=TEST TARGET=$@ build/do $^ $(HOSTS)
|
||||
@touch $@
|
||||
@$(COMPILE) -ATEST -tT$@ $^ $(HOSTS)
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if [ "$TOOL_BUILD_PACKAGE" ]; then
|
||||
set -- "$TOOL_BUILD_PACKAGE" "$@"
|
||||
else
|
||||
if [ -x "o/tool/build/package.com.dbg" ]; then
|
||||
set -- "o/tool/build/package.com.dbg" "$@"
|
||||
else
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
CP=${CP:-$(command -v cp) -f} || exit
|
||||
if [ ! -x o/build/bootstrap/package.com ]; then
|
||||
$MKDIR o/build/bootstrap &&
|
||||
$CP -a build/bootstrap/package.com \
|
||||
o/build/bootstrap/package.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/package.com "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# else
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# fi
|
||||
|
||||
exec "$@"
|
||||
+62
-67
@@ -16,73 +16,68 @@
|
||||
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
o/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.zip.o: o/%; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/%.a: ; @$(COMPILE) -AARCHIVE -T$@ $(AR) $(ARFLAGS) $@ $^
|
||||
o/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.pkg: ; @$(COMPILE) -APACKAGE -T$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.zip.o: o/% ; @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
|
||||
o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg; @ACTION=OBJCOPY TARGET=$@ $(COMPILE) $(OBJCOPY) -S -O binary $< $@
|
||||
o/$(MODE)/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c; @ACTION=COMPILE.c $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c; @ACTION=OBJECTIFY.s $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c; @ACTION=OBJECTIFY.c99 $(COMPILE) $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c; @ACTION=OBJECTIFY.c11 $(COMPILE) $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c; @ACTION=OBJECTIFY.c2x $(COMPILE) $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c; @ACTION=OBJECTIFY.init $(COMPILE) $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c; @ACTION=OBJECTIFY.nc $(COMPILE) $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c; @ACTION=OBJECTIFY.real $(COMPILE) $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.runs: o/$(MODE)/%; @ACTION=CHECK.runs TARGET=$< build/runcom $< $(TESTARGS) && touch $@
|
||||
o/$(MODE)/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/$(MODE)/%.zip.o: %; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.a: ; @$(COMPILE) -AARCHIVE -T$@ $(AR) $(ARFLAGS) $@ $^
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg ; @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
|
||||
o/$(MODE)/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f ; @$(COMPILE) -AOBJECTIFY.f $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F ; @$(COMPILE) -AOBJECTIFY.F $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c ; @$(COMPILE) -ACOMPILE.c $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c ; @$(COMPILE) -AOBJECTIFY.s $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i386.o: %.i386.c ; @$(COMPILE) -AOBJECTIFY.i386 $(OBJECTIFY.i386.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c ; @$(COMPILE) -AOBJECTIFY.ansi $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c ; @$(COMPILE) -AOBJECTIFY.ansi $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c ; @$(COMPILE) -AOBJECTIFY.c99 $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c ; @$(COMPILE) -AOBJECTIFY.c11 $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c ; @$(COMPILE) -AOBJECTIFY.c2x $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c ; @$(COMPILE) -AOBJECTIFY.init $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c ; @$(COMPILE) -AOBJECTIFY.nc $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c ; @$(COMPILE) -AOBJECTIFY.real $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.runs: o/$(MODE)/% ; @$(COMPILE) -ACHECK -tT$@ $< $(TESTARGS)
|
||||
o/$(MODE)/%.pkg: ; @$(COMPILE) -APACKAGE -T$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/$(MODE)/%.zip.o: % ; @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-gcc.asm: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
|
||||
o/$(MODE)/%-gcc.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
DD=${DD:-$(command -v dd)} || exit
|
||||
$DD if="$1" of="$1.bak" bs=4096 count=1 conv=notrunc 2>/dev/null
|
||||
"$@"
|
||||
rc=$?
|
||||
echo "$1"
|
||||
$DD if="$1.bak" of="$1" bs=4096 count=1 conv=notrunc 2>/dev/null
|
||||
exit $rc
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
CP=${CP:-$(command -v cp) -f} || exit
|
||||
SED=${SED:-$(command -v sed)} || exit
|
||||
|
||||
MODE=
|
||||
|
||||
OUT=
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
if [ -x "o/$MODE/tool/build/zipobj.com.dbg" ]; then
|
||||
set -- "o/$MODE/tool/build/zipobj.com.dbg" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/zipobj.com ]; then
|
||||
$MKDIR o/build/bootstrap &&
|
||||
$CP -a build/bootstrap/zipobj.com \
|
||||
o/build/bootstrap/zipobj.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/zipobj.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-ZIPOBJ}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ai.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/shut.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "net/http/uri.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Downloads HTTP URL to stdout.
|
||||
*
|
||||
* make -j8 o//examples/curl.com
|
||||
* o//examples/curl.com http://justine.lol/ape.html
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int sock;
|
||||
ssize_t rc;
|
||||
unsigned long need;
|
||||
struct UriSlice path;
|
||||
size_t i, got, toto, msglen;
|
||||
char buf[1500], host[256], port[7];
|
||||
const char *url, *msg, *pathstr, *crlfcrlf, *contentlength;
|
||||
struct UriSlice us[16];
|
||||
struct Uri u = {.segs.p = us, .segs.n = ARRAYLEN(us)};
|
||||
struct addrinfo *addr, *addrs;
|
||||
struct addrinfo hints = {.ai_family = AF_INET,
|
||||
.ai_socktype = SOCK_STREAM,
|
||||
.ai_protocol = IPPROTO_TCP,
|
||||
.ai_flags = AI_NUMERICSERV};
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "USAGE: %s URL\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
url = argv[1];
|
||||
CHECK_NE(-1, uriparse(&u, url, strlen(url)), "BAD URL: %`'s", url);
|
||||
CHECK_EQ(kUriSchemeHttp, urischeme(u.scheme, url));
|
||||
urislice2cstr(host, sizeof(host), u.host, url, "127.0.0.1");
|
||||
urislice2cstr(port, sizeof(port), u.port, url, "80");
|
||||
path = uripath(&u);
|
||||
pathstr = path.n ? url + path.i : "/";
|
||||
msg = gc(xstrcat("GET ", pathstr,
|
||||
" HTTP/1.1\r\n"
|
||||
"Host: ",
|
||||
host,
|
||||
"\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"Accept: text/plain; */*\r\n"
|
||||
"Accept-Encoding: identity\r\n"
|
||||
"User-Agent: github.com/jart/cosmopolitan\r\n"
|
||||
"\r\n"));
|
||||
msglen = strlen(msg);
|
||||
CHECK_EQ(EAI_SUCCESS, getaddrinfo(host, port, &hints, &addrs));
|
||||
for (addr = addrs; addr; addr = addr->ai_next) {
|
||||
CHECK_NE(-1, (sock = socket(addr->ai_family, addr->ai_socktype,
|
||||
addr->ai_protocol)));
|
||||
CHECK_NE(-1, connect(sock, addr->ai_addr, addr->ai_addrlen));
|
||||
CHECK_EQ(msglen, write(sock, msg, msglen));
|
||||
shutdown(sock, SHUT_WR);
|
||||
buf[0] = '\0';
|
||||
CHECK_NE(-1, (rc = read(sock, buf, sizeof(buf))));
|
||||
got = rc;
|
||||
CHECK(startswith(buf, "HTTP/1.1 200"), "%`'.*s", got, buf);
|
||||
CHECK_NOTNULL((crlfcrlf = memmem(buf, got, "\r\n\r\n", 4)));
|
||||
need = strtol((char *)firstnonnull(
|
||||
memmem(buf, crlfcrlf - buf, "\r\nContent-Length: ", 18),
|
||||
firstnonnull(memmem(buf, crlfcrlf - buf,
|
||||
"\r\ncontent-length: ", 18),
|
||||
"\r\nContent-Length: -1")) +
|
||||
18,
|
||||
NULL, 10);
|
||||
got = MIN(got - (crlfcrlf + 4 - buf), need);
|
||||
CHECK_EQ(got, write(1, crlfcrlf + 4, got));
|
||||
for (toto = got; toto < need; toto += got) {
|
||||
CHECK_NE(-1, (rc = read(sock, buf, sizeof(buf))));
|
||||
if (!(got = rc)) exit(18);
|
||||
got = MIN(got, need - toto);
|
||||
CHECK_EQ(got, write(1, buf, got));
|
||||
}
|
||||
close(sock);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -40,6 +40,7 @@ EXAMPLES_DIRECTDEPS = \
|
||||
LIBC_ALG \
|
||||
LIBC_BITS \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
@@ -64,6 +65,7 @@ EXAMPLES_DIRECTDEPS = \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
NET_HTTP \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_GDTOA \
|
||||
@@ -128,13 +130,9 @@ o/$(MODE)/examples/nesemu1.com.dbg: \
|
||||
$(EXAMPLES_OBJS): examples/examples.mk
|
||||
|
||||
usr/share/dict/words: usr/share/dict/words.gz
|
||||
@$(MKDIR) $(dir $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(GZ) $(ZFLAGS) -d <$< >$@
|
||||
|
||||
o/$(MODE)/examples/ugh.ok: o/$(MODE)/examples/wut.com
|
||||
$<
|
||||
touch $@
|
||||
|
||||
.PHONY: o/$(MODE)/examples
|
||||
o/$(MODE)/examples: \
|
||||
o/$(MODE)/examples/package \
|
||||
|
||||
+2
-14
@@ -9,20 +9,8 @@
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
#define kMessage "hello \e[1mworld\e[0m\r\n"
|
||||
|
||||
int main() {
|
||||
/*
|
||||
* Cosmopolitan "Hello World" using system calls.
|
||||
*
|
||||
* Another Cosmopolitan best practice is to use the standard symbolic
|
||||
* names for file descriptors 0, 1, and 2. This is a good idea because
|
||||
* on Windows the numbers are actually different. Because Cosmopolitan
|
||||
* is a zero-emulation library, we address that problem by turning
|
||||
* traditional #define's into variables, which the runtime determines
|
||||
* automatically.
|
||||
*/
|
||||
return write(STDOUT_FILENO, kMessage, strlen(kMessage)) != -1 ? 0 : 1;
|
||||
write(1, "hello world\n", 12);
|
||||
return 0;
|
||||
}
|
||||
+3
-1
@@ -10,6 +10,7 @@
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
@@ -39,6 +40,7 @@ int main(int argc, char *argv[]) {
|
||||
struct stat st;
|
||||
const char *code;
|
||||
duk_context *ctx;
|
||||
showcrashreports();
|
||||
ctx = duk_create_heap_default();
|
||||
duk_push_c_function(ctx, NativePrint, DUK_VARARGS);
|
||||
duk_put_global_string(ctx, "NativePrint");
|
||||
@@ -47,7 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
CHECK_NE(-1, (fd = open("zip:examples/hello.js", O_RDONLY)));
|
||||
CHECK_NE(-1, fstat(fd, &st));
|
||||
CHECK_NOTNULL((code = gc(malloc(st.st_size))));
|
||||
CHECK_NOTNULL((code = gc(calloc(1, st.st_size + 1))));
|
||||
CHECK_EQ(st.st_size, read(fd, code, st.st_size));
|
||||
CHECK_NE(-1, close(fd));
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/str/str.h"
|
||||
|
||||
char kTenFour[10] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
|
||||
|
||||
int main32(int argc, char *argv[]) {
|
||||
return argc;
|
||||
if (memset(argv[0], 4, 10) != argv[0]) return 1;
|
||||
if (memcmp(argv[0], kTenFour, 10)) return 2;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct stat st;
|
||||
st.st_size = -1;
|
||||
stat(argv[1], &st);
|
||||
return st.st_size;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Command for updating timestamps on files.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (touch(argv[i], 0644) == -1) {
|
||||
fprintf(stderr, "ERROR: %s: %s\n", argv[i], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st,
|
||||
uint32_t flags) {
|
||||
uint32_t flags) {
|
||||
int rc;
|
||||
int64_t fh;
|
||||
uint16_t path16[PATH_MAX];
|
||||
|
||||
@@ -263,6 +263,7 @@ int sys_sync_nt(void) hidden;
|
||||
int sys_sysinfo_nt(struct sysinfo *) hidden;
|
||||
int sys_truncate_nt(const char *, u64) hidden;
|
||||
int sys_unlinkat_nt(int, const char *, int) hidden;
|
||||
int sys_utimes_nt(const char *, const struct timeval[2]) hidden;
|
||||
int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden;
|
||||
ssize_t sys_open_nt(int, const char *, u32, i32) nodiscard hidden;
|
||||
ssize_t sys_read_nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-*- 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│
|
||||
/*-*- 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 │
|
||||
│ Copyright 2021 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 │
|
||||
@@ -16,29 +16,18 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.exit
|
||||
.source __FILE__
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
||||
// Calls linker registered finalization functions.
|
||||
// @note functions are called in reverse order
|
||||
_destruct:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
ezlea __fini_array_start,cx
|
||||
.weak __fini_array_start
|
||||
ezlea __fini_array_end,ax
|
||||
.weak __fini_array_end
|
||||
cmp %rax,%rcx
|
||||
je 2f
|
||||
1: sub $8,%rax
|
||||
push %rax
|
||||
push %rcx
|
||||
call *(%rax)
|
||||
pop %rcx
|
||||
pop %rax
|
||||
cmp %rax,%rcx
|
||||
jne 1b
|
||||
2: pop %rbp
|
||||
ret
|
||||
.endfn _destruct,globl
|
||||
textwindows int sys_utimes_nt(const char *path, const struct timeval tv[2]) {
|
||||
struct timespec ts[2];
|
||||
if (tv) {
|
||||
ts[0].tv_sec = tv[0].tv_sec;
|
||||
ts[0].tv_nsec = tv[0].tv_usec * 1000;
|
||||
ts[1].tv_sec = tv[1].tv_sec;
|
||||
ts[1].tv_nsec = tv[1].tv_usec * 1000;
|
||||
return sys_utimensat_nt(AT_FDCWD, path, ts, 0);
|
||||
} else {
|
||||
return sys_utimensat_nt(AT_FDCWD, path, NULL, 0);
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -17,7 +17,9 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
/**
|
||||
* Creates new file or changes modified time on existing one.
|
||||
@@ -28,7 +30,12 @@
|
||||
* @see creat()
|
||||
*/
|
||||
int touch(const char *file, uint32_t mode) {
|
||||
int fd;
|
||||
if ((fd = open(file, O_CREAT | O_WRONLY, mode)) == -1) return -1;
|
||||
return close(fd);
|
||||
int rc, fd, olderr;
|
||||
olderr = errno;
|
||||
if ((rc = utimes(file, NULL)) == -1 && errno == ENOENT) {
|
||||
errno = olderr;
|
||||
if ((fd = open(file, O_CREAT | O_WRONLY, mode)) == -1) return -1;
|
||||
return close(fd);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
+8
-7
@@ -26,16 +26,17 @@
|
||||
*
|
||||
* @param times if NULL means now
|
||||
* @return 0 on success or -1 w/ errno
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int utime(const char *path, const struct utimbuf *times) {
|
||||
struct timespec ts[2];
|
||||
struct timeval tv[2];
|
||||
if (times) {
|
||||
ts[0].tv_sec = times->actime;
|
||||
ts[0].tv_nsec = 0;
|
||||
ts[1].tv_sec = times->modtime;
|
||||
ts[1].tv_nsec = 0;
|
||||
return utimensat(AT_FDCWD, path, ts, 0);
|
||||
tv[0].tv_sec = times->actime;
|
||||
tv[0].tv_usec = 0;
|
||||
tv[1].tv_sec = times->modtime;
|
||||
tv[1].tv_usec = 0;
|
||||
return utimes(path, tv);
|
||||
} else {
|
||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
||||
return utimes(path, NULL);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "libc/time/time.h"
|
||||
|
||||
textwindows int sys_utimensat_nt(int dirfd, const char *path,
|
||||
const struct timespec ts[2], int flags) {
|
||||
const struct timespec ts[2], int flags) {
|
||||
int i, rc;
|
||||
int64_t fh;
|
||||
uint16_t path16[PATH_MAX];
|
||||
|
||||
@@ -17,12 +17,33 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
#define __NR_utimensat_linux 0x118 /*RHEL5:CVE-2010-3301*/
|
||||
|
||||
int sys_utimensat(int dirfd, const char *path, const struct timespec ts[2],
|
||||
int flags) {
|
||||
int rc, olderr;
|
||||
struct timeval tv[2];
|
||||
if (!IsXnu()) {
|
||||
return __sys_utimensat(dirfd, path, ts, flags);
|
||||
olderr = errno;
|
||||
rc = __sys_utimensat(dirfd, path, ts, flags);
|
||||
if (((rc == -1 && errno == ENOSYS) || rc == __NR_utimensat_linux) &&
|
||||
dirfd == AT_FDCWD && !flags) {
|
||||
errno = olderr;
|
||||
if (ts) {
|
||||
tv[0].tv_sec = ts[0].tv_sec;
|
||||
tv[0].tv_usec = ts[0].tv_nsec / 1000;
|
||||
tv[1].tv_sec = ts[1].tv_sec;
|
||||
tv[1].tv_usec = ts[1].tv_nsec / 1000;
|
||||
rc = sys_utimes(path, tv);
|
||||
} else {
|
||||
rc = sys_utimes(path, NULL);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
return sys_utimensat_xnu(dirfd, path, ts, flags);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,11 @@
|
||||
*
|
||||
* @param ts is atime/mtime, or null for current time
|
||||
* @param flags can have AT_SYMLINK_NOFOLLOW
|
||||
* @note no rhel5 support
|
||||
* @note no xnu/rhel5 support if dirfd≠AT_FDCWD∨flags≠0
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int utimensat(int dirfd, const char *path,
|
||||
const struct timespec ts[hasatleast 2], int flags) {
|
||||
int utimensat(int dirfd, const char *path, const struct timespec ts[2],
|
||||
int flags) {
|
||||
if (!IsWindows()) {
|
||||
return sys_utimensat(dirfd, path, ts, flags);
|
||||
} else {
|
||||
|
||||
+11
-9
@@ -16,6 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
@@ -24,17 +26,17 @@
|
||||
*
|
||||
* @param times is access/modified and NULL means now
|
||||
* @return 0 on success or -1 w/ errno
|
||||
* @asyncsignalsafe
|
||||
* @see stat()
|
||||
*/
|
||||
int utimes(const char *path, const struct timeval tv[hasatleast 2]) {
|
||||
struct timespec ts[2];
|
||||
if (tv) {
|
||||
ts[0].tv_sec = tv[0].tv_sec;
|
||||
ts[0].tv_nsec = tv[0].tv_usec * 1000;
|
||||
ts[1].tv_sec = tv[1].tv_sec;
|
||||
ts[1].tv_nsec = tv[1].tv_usec * 1000;
|
||||
return utimensat(AT_FDCWD, path, ts, 0);
|
||||
int utimes(const char *path, const struct timeval tv[2]) {
|
||||
if (!IsWindows()) {
|
||||
/*
|
||||
* we don't modernize utimes() into utimensat() because the
|
||||
* latter is poorly supported and utimes() works everywhere
|
||||
*/
|
||||
return sys_utimes(path, tv);
|
||||
} else {
|
||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
||||
return sys_utimes_nt(path, tv);
|
||||
}
|
||||
}
|
||||
+26
-7
@@ -1,15 +1,34 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_DNS_DNS_H_
|
||||
#define COSMOPOLITAN_LIBC_DNS_DNS_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#include "libc/dns/resolvconf.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
||||
#define DNS_PORT 53
|
||||
#define DNS_NAME_MAX 253
|
||||
#define DNS_PORT 53
|
||||
#define DNS_NAME_MAX 253
|
||||
#define DNS_LABEL_MAX 63
|
||||
|
||||
struct sockaddr;
|
||||
struct sockaddr_in;
|
||||
struct ResolvConf;
|
||||
#define EAI_SUCCESS 0
|
||||
#define EAI_BADFLAGS -1
|
||||
#define EAI_NONAME -2
|
||||
#define EAI_AGAIN -3
|
||||
#define EAI_FAIL -4
|
||||
#define EAI_NODATA -5
|
||||
#define EAI_FAMILY -6
|
||||
#define EAI_SOCKTYPE -7
|
||||
#define EAI_SERVICE -8
|
||||
#define EAI_ADDRFAMILY -9
|
||||
#define EAI_MEMORY -10
|
||||
#define EAI_OVERFLOW -12
|
||||
#define EAI_SYSTEM -11
|
||||
#define EAI_ALLDONE -103
|
||||
#define EAI_CANCELED -101
|
||||
#define EAI_IDN_ENCODE -105
|
||||
#define EAI_INPROGRESS -100
|
||||
#define EAI_INTR -104
|
||||
#define EAI_NOTCANCELED -102
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct addrinfo {
|
||||
int32_t ai_flags; /* AI_XXX */
|
||||
|
||||
+42
-21
@@ -17,30 +17,51 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/sysv/consts/eai.h"
|
||||
|
||||
/**
|
||||
* Turns getaddrinfo() return code into string.
|
||||
*/
|
||||
const char *eai2str(int code) {
|
||||
if (code == EAI_ADDRFAMILY) return "ADDRFAMILY";
|
||||
if (code == EAI_AGAIN) return "AGAIN";
|
||||
if (code == EAI_ALLDONE) return "ALLDONE";
|
||||
if (code == EAI_BADFLAGS) return "BADFLAGS";
|
||||
if (code == EAI_CANCELED) return "CANCELED";
|
||||
if (code == EAI_FAIL) return "FAIL";
|
||||
if (code == EAI_FAMILY) return "FAMILY";
|
||||
if (code == EAI_IDN_ENCODE) return "ENCODE";
|
||||
if (code == EAI_INPROGRESS) return "INPROGRESS";
|
||||
if (code == EAI_INTR) return "INTR";
|
||||
if (code == EAI_MEMORY) return "MEMORY";
|
||||
if (code == EAI_NODATA) return "NODATA";
|
||||
if (code == EAI_NONAME) return "NONAME";
|
||||
if (code == EAI_NOTCANCELED) return "NOTCANCELED";
|
||||
if (code == EAI_OVERFLOW) return "OVERFLOW";
|
||||
if (code == EAI_SERVICE) return "SERVICE";
|
||||
if (code == EAI_SOCKTYPE) return "SOCKTYPE";
|
||||
if (code == EAI_SUCCESS) return "SUCCESS";
|
||||
if (code == EAI_SYSTEM) return "SYSTEM";
|
||||
return "???";
|
||||
switch (code) {
|
||||
case EAI_ADDRFAMILY:
|
||||
return "ADDRFAMILY";
|
||||
case EAI_AGAIN:
|
||||
return "AGAIN";
|
||||
case EAI_ALLDONE:
|
||||
return "ALLDONE";
|
||||
case EAI_BADFLAGS:
|
||||
return "BADFLAGS";
|
||||
case EAI_CANCELED:
|
||||
return "CANCELED";
|
||||
case EAI_FAIL:
|
||||
return "FAIL";
|
||||
case EAI_FAMILY:
|
||||
return "FAMILY";
|
||||
case EAI_IDN_ENCODE:
|
||||
return "ENCODE";
|
||||
case EAI_INPROGRESS:
|
||||
return "INPROGRESS";
|
||||
case EAI_INTR:
|
||||
return "INTR";
|
||||
case EAI_MEMORY:
|
||||
return "MEMORY";
|
||||
case EAI_NODATA:
|
||||
return "NODATA";
|
||||
case EAI_NONAME:
|
||||
return "NONAME";
|
||||
case EAI_NOTCANCELED:
|
||||
return "NOTCANCELED";
|
||||
case EAI_OVERFLOW:
|
||||
return "OVERFLOW";
|
||||
case EAI_SERVICE:
|
||||
return "SERVICE";
|
||||
case EAI_SOCKTYPE:
|
||||
return "SOCKTYPE";
|
||||
case EAI_SUCCESS:
|
||||
return "SUCCESS";
|
||||
case EAI_SYSTEM:
|
||||
return "SYSTEM";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ai.h"
|
||||
#include "libc/sysv/consts/eai.h"
|
||||
#include "libc/sysv/consts/inaddr.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_DNS_RESOLVCONF_H_
|
||||
#define COSMOPOLITAN_LIBC_DNS_RESOLVCONF_H_
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct FILE;
|
||||
struct sockaddr_in;
|
||||
|
||||
struct Nameservers {
|
||||
size_t i, n;
|
||||
struct sockaddr_in *p;
|
||||
|
||||
@@ -23,5 +23,6 @@ bool IsElf64Binary(const Elf64_Ehdr *elf, size_t mapsize) {
|
||||
if (mapsize < sizeof(Elf64_Ehdr)) return false;
|
||||
if (memcmp(elf->e_ident, ELFMAG, 4)) return false;
|
||||
return (elf->e_ident[EI_CLASS] == ELFCLASSNONE ||
|
||||
elf->e_ident[EI_CLASS] == ELFCLASS64);
|
||||
elf->e_ident[EI_CLASS] == ELFCLASS64 ||
|
||||
elf->e_ident[EI_CLASS] == ELFCLASS32);
|
||||
}
|
||||
@@ -28,7 +28,14 @@
|
||||
*
|
||||
* This is a higher level version of the commandv() function. Programs
|
||||
* that spawn subprocesses can use this function to determine the path
|
||||
* at startup.
|
||||
* at startup. Here's an example how you could use it:
|
||||
*
|
||||
* if ((strace = commandvenv("STRACE", "strace"))) {
|
||||
* strace = strdup(strace);
|
||||
* } else {
|
||||
* fprintf(stderr, "error: please install strace\n");
|
||||
* exit(1);
|
||||
* }
|
||||
*
|
||||
* @param var is environment variable which may be used to override
|
||||
* PATH search, and it can force a NULL result if it's empty
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
// @param rsi:rdi is 128-bit unsigned 𝑥 value
|
||||
// @return eax number in range [0,128) or undef if 𝑥 is 0
|
||||
// @see also treasure trove of nearly identical functions
|
||||
// @mode legacy,long
|
||||
bsrmax: .leafprologue
|
||||
.profilable
|
||||
bsr %rsi,%rax
|
||||
|
||||
@@ -151,8 +151,6 @@ $(LIBC_NT_NTDLL_A): \
|
||||
libc/nt/ntdll/ \
|
||||
$(LIBC_NT_NTDLL_A).pkg \
|
||||
$(LIBC_NT_NTDLL_A_OBJS)
|
||||
@$(file >$@.cmd) $(file >>$@.cmd,$(ARCHIVE) $@ $^ >$(LIBC_NT_NTDLL_A).cmd)
|
||||
@$(ARCHIVE) $@ $^
|
||||
|
||||
$(LIBC_NT_NTDLL_A).pkg: \
|
||||
$(LIBC_NT_NTDLL_A_OBJS) \
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*-*- 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 2021 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 "ape/macros.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/macros.h"
|
||||
.section .start,"ax",@progbits
|
||||
.code32
|
||||
|
||||
// @fileoverview 80386 APE UNIX CRT
|
||||
//
|
||||
// This module is yoinked by build/i386ify.sh when GNU make
|
||||
// builds source codes that have the .i386.c file extension
|
||||
// thereby avoiding some 386 bloat when it isn't being used
|
||||
//
|
||||
// TODO: Verify we can't use 64-bit ELF with i386 e_machine
|
||||
|
||||
_start32:
|
||||
.weak main32
|
||||
call main32
|
||||
mov %eax,%ebx
|
||||
pushpop 1,%eax # _exit() ordinal
|
||||
push %ebx # hybrid calling convention
|
||||
push %eax # should work on Linux+BSDs
|
||||
int $0x80
|
||||
ud2
|
||||
.endfn _start32,globl,hidden
|
||||
|
||||
.section .elf.phdrs32,"a",@progbits
|
||||
.long PT_LOAD # text segment
|
||||
.stub ape_rom_offset,long
|
||||
.stub ape_rom_vaddr,long
|
||||
.stub ape_rom_paddr,long
|
||||
.stub ape_rom_filesz,long
|
||||
.stub ape_rom_memsz,long
|
||||
.long PF_R|PF_X # <-- wut
|
||||
.stub ape_rom_align,long
|
||||
.long PT_LOAD # data segment
|
||||
.stub ape_ram_offset,long
|
||||
.stub ape_ram_vaddr,long
|
||||
.stub ape_ram_paddr,long
|
||||
.stub ape_ram_filesz,long
|
||||
.stub ape_ram_memsz,long
|
||||
.long PF_R|PF_W
|
||||
.stub ape_ram_align,long
|
||||
#if SupportsLinux()
|
||||
// Linux ignores mprotect() and returns 0 without this lool
|
||||
// It has nothing to do with the stack, which is still exec
|
||||
.long PT_GNU_STACK # p_type
|
||||
.long 0 # p_offset
|
||||
.long 0 # p_vaddr
|
||||
.long 0 # p_paddr
|
||||
.long 0 # p_filesz
|
||||
.long 0 # p_memsz
|
||||
.long PF_R|PF_W # p_flags
|
||||
.long 16 # p_align
|
||||
#endif
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
.long PT_NOTE # notes
|
||||
.stub ape_note_offset,long
|
||||
.stub ape_note_vaddr,long
|
||||
.stub ape_note_paddr,long
|
||||
.stub ape_note_filesz,long
|
||||
.stub ape_note_memsz,long
|
||||
.long PF_R
|
||||
.stub ape_note_align,long
|
||||
#endif
|
||||
.previous
|
||||
@@ -0,0 +1,46 @@
|
||||
/*-*- 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 2021 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/bits/weaken.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
extern const uintptr_t __fini_array_start[];
|
||||
extern const uintptr_t __fini_array_end[];
|
||||
|
||||
/**
|
||||
* Exits process with grace.
|
||||
*
|
||||
* This calls functions registered by atexit() before terminating
|
||||
* the current process, and any associated threads. It also calls
|
||||
* all the legacy linker registered destructors in reeverse order
|
||||
*
|
||||
* @param exitcode is masked with 255
|
||||
* @see _Exit()
|
||||
* @noreturn
|
||||
*/
|
||||
wontreturn void exit(int exitcode) {
|
||||
const uintptr_t *p;
|
||||
if (weaken(__cxa_finalize)) {
|
||||
weaken(__cxa_finalize)(NULL);
|
||||
}
|
||||
for (p = *weaken(__fini_array_end); p > *weaken(__fini_array_start);) {
|
||||
((void (*)(void))(*--p))();
|
||||
}
|
||||
_Exit(exitcode);
|
||||
}
|
||||
+5
-10
@@ -20,7 +20,6 @@
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/macros.h"
|
||||
.privileged
|
||||
.source __FILE__
|
||||
|
||||
// Terminates process, ignoring destructors and atexit() handlers.
|
||||
//
|
||||
@@ -34,17 +33,13 @@ _Exit: push %rbp
|
||||
testb IsWindows()
|
||||
jz 1f
|
||||
sub $32,%rsp
|
||||
movzbl %dil,%ecx # %ERRORLEVEL% is limitless
|
||||
4: call *__imp_ExitProcess(%rip)
|
||||
jmp 4b
|
||||
0: int3 # @see setjmp() in WinMain()
|
||||
movzbl %dil,%ecx # %ERRORLEVEL% is limitless
|
||||
call *__imp_ExitProcess(%rip)
|
||||
#endif
|
||||
1: mov __NR_exit_group(%rip),%eax
|
||||
syscall
|
||||
cli
|
||||
lidt 3f
|
||||
2: hlt
|
||||
jmp 2b
|
||||
3: .quad 0
|
||||
#if SupportsMetal()
|
||||
call triplf
|
||||
#endif
|
||||
.endfn _Exit,globl,protected
|
||||
.hidden __NR_exit_group
|
||||
@@ -35,7 +35,9 @@ const char *FindDebugBinary(void) {
|
||||
unsigned i, len;
|
||||
char buf[2][PATH_MAX];
|
||||
static char res[PATH_MAX];
|
||||
const char *bins[4], *pwd;
|
||||
const char *bins[4], *pwd, *comdbg;
|
||||
if (res[0]) return res;
|
||||
if ((comdbg = emptytonull(getenv("COMDBG")))) return comdbg;
|
||||
if (res[0]) return res;
|
||||
bins[0] = program_invocation_name;
|
||||
bins[1] = (const char *)getauxval(AT_EXECFN);
|
||||
|
||||
@@ -47,8 +47,10 @@ vfork:
|
||||
#endif
|
||||
syscall
|
||||
push %rsi # note it happens twice in same page
|
||||
#if SupportsLinux()
|
||||
cmp $-4095,%eax
|
||||
jae systemfive_error
|
||||
#endif
|
||||
0: ezlea __vforked,di
|
||||
test %eax,%eax
|
||||
jz 1f
|
||||
|
||||
+15
-13
@@ -35,6 +35,7 @@
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/struct/teb.h"
|
||||
#include "libc/runtime/directmap.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.h"
|
||||
@@ -64,11 +65,11 @@ static noasan textwindows void MakeLongDoubleLongAgain(void) {
|
||||
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(x87cw));
|
||||
}
|
||||
|
||||
static noasan textwindows void NormalizeCmdExe(void) {
|
||||
static noasan textwindows void NormalizeCmdExe(int version) {
|
||||
uint32_t mode;
|
||||
int64_t handle, hstdin, hstdout, hstderr;
|
||||
if ((int)weakaddr("v_ntsubsystem") == kNtImageSubsystemWindowsCui &&
|
||||
NtGetVersion() >= kNtVersionWindows10) {
|
||||
version >= 10) {
|
||||
hstdin = GetStdHandle(pushpop(kNtStdInputHandle));
|
||||
hstdout = GetStdHandle(pushpop(kNtStdOutputHandle));
|
||||
hstderr = GetStdHandle(pushpop(kNtStdErrorHandle));
|
||||
@@ -86,17 +87,16 @@ static noasan textwindows void NormalizeCmdExe(void) {
|
||||
SetTrueColor();
|
||||
SetConsoleOutputCP(kNtCpUtf8);
|
||||
GetConsoleMode(handle, &mode);
|
||||
SetConsoleMode(handle, mode | kNtEnableProcessedOutput |
|
||||
kNtEnableWrapAtEolOutput |
|
||||
(NtGetVersion() >= kNtVersionWindows10
|
||||
? kNtEnableVirtualTerminalProcessing
|
||||
: 0));
|
||||
SetConsoleMode(
|
||||
handle, mode | kNtEnableProcessedOutput | kNtEnableWrapAtEolOutput |
|
||||
(version >= 10 ? kNtEnableVirtualTerminalProcessing : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static noasan textwindows wontreturn void WinMainNew(void) {
|
||||
int64_t h;
|
||||
int version;
|
||||
size_t size;
|
||||
int i, count;
|
||||
uint64_t addr;
|
||||
@@ -105,13 +105,15 @@ static noasan textwindows wontreturn void WinMainNew(void) {
|
||||
const char16_t *env16;
|
||||
extern char os asm("__hostos");
|
||||
os = WINDOWS; /* madness https://news.ycombinator.com/item?id=21019722 */
|
||||
NormalizeCmdExe();
|
||||
addr = NtGetVersion() < kNtVersionWindows10 ? 0xff00000 : 0x777000000000;
|
||||
version = NtGetPeb()->OSMajorVersion;
|
||||
NormalizeCmdExe(version);
|
||||
addr = version < 10 ? 0xff00000 : 0x777000000000;
|
||||
size = ROUNDUP(STACKSIZE + sizeof(struct WinArgs), FRAMESIZE);
|
||||
_mmi.p[0].h =
|
||||
sys_mmap_nt((char *)addr, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE, -1, 0)
|
||||
.maphandle;
|
||||
MapViewOfFileExNuma((_mmi.p[0].h = CreateFileMappingNuma(
|
||||
-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
|
||||
size >> 32, size, NULL, kNtNumaNoPreferredNode)),
|
||||
kNtFileMapWrite | kNtFileMapExecute, 0, 0, size,
|
||||
(void *)addr, kNtNumaNoPreferredNode);
|
||||
_mmi.p[0].x = addr >> 16;
|
||||
_mmi.p[0].y = (addr >> 16) + ((size >> 16) - 1);
|
||||
_mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC;
|
||||
|
||||
@@ -1833,29 +1833,6 @@ syscon gai AI_NUMERICSERV 0x0400 0x1000 8 0x10 0x10 8
|
||||
syscon gai AI_ALL 0x10 0x0100 0x0100 0 0 0x0100
|
||||
syscon gai AI_V4MAPPED 8 0x0800 0x0800 0 0 0x0800
|
||||
|
||||
# getaddrinfo() return codes
|
||||
#
|
||||
# group name GNU/Systemd XNU's Not UNIX FreeBSD OpenBSD NetBSD XENIX Commentary
|
||||
syscon eai EAI_SUCCESS 0 0 0 0 0 0
|
||||
syscon eai EAI_BADFLAGS -1 3 3 -1 -1 0x2726
|
||||
syscon eai EAI_NONAME -2 8 8 -2 -2 0x2af9
|
||||
syscon eai EAI_AGAIN -3 2 2 -3 -3 0x2afa
|
||||
syscon eai EAI_FAIL -4 4 4 -4 -4 0x2afb
|
||||
syscon eai EAI_FAMILY -6 5 5 -6 -6 0x273f
|
||||
syscon eai EAI_MEMORY -10 6 6 -10 -10 0x2747
|
||||
syscon eai EAI_SERVICE -8 9 9 -8 -8 0x277d
|
||||
syscon eai EAI_SOCKTYPE -7 10 10 -7 -7 0x273c
|
||||
syscon eai EAI_NODATA -5 7 0 -5 -5 0x2af9
|
||||
syscon eai EAI_OVERFLOW -12 14 14 -14 -14 -12
|
||||
syscon eai EAI_SYSTEM -11 11 11 -11 -11 -11
|
||||
syscon eai EAI_ADDRFAMILY -9 1 0 -9 -9 -9
|
||||
syscon eai EAI_ALLDONE -103 -103 -103 -103 -103 -103 # copying from linux
|
||||
syscon eai EAI_CANCELED -101 -101 -101 -101 -101 -101 # copying from linux
|
||||
syscon eai EAI_IDN_ENCODE -105 -105 -105 -105 -105 -105 # copying from linux
|
||||
syscon eai EAI_INPROGRESS -100 -100 -100 -100 -100 -100 # copying from linux
|
||||
syscon eai EAI_INTR -104 -104 -104 -104 -104 -104 # copying from linux
|
||||
syscon eai EAI_NOTCANCELED -102 -102 -102 -102 -102 -102 # copying from linux
|
||||
|
||||
syscon misc BLK_BYTECOUNT 2 2 2 2 2 0 # unix consensus
|
||||
syscon misc BLK_EOF 0x40 0x40 0x40 0x40 0x40 0 # unix consensus
|
||||
syscon misc BLK_EOR 0x80 0x80 0x80 0x80 0x80 0 # unix consensus
|
||||
@@ -1890,21 +1867,6 @@ syscon misc ILL_ILLOPN 2 4 2 2 2 0
|
||||
syscon misc ILL_ILLTRP 4 2 4 4 4 0
|
||||
syscon misc ILL_PRVOPC 5 3 5 5 5 0
|
||||
|
||||
syscon misc LC_CTYPE 0 2 2 2 2 0 # bsd consensus
|
||||
syscon misc LC_NUMERIC 1 4 4 4 4 0 # bsd consensus
|
||||
syscon misc LC_CTYPE_MASK 1 0 2 4 4 0
|
||||
syscon misc LC_TIME 2 5 5 5 5 0 # bsd consensus
|
||||
syscon misc LC_NUMERIC_MASK 2 0 8 0x10 0x10 0
|
||||
syscon misc LC_COLLATE 3 1 1 1 1 0 # bsd consensus
|
||||
syscon misc LC_MONETARY 4 3 3 3 3 0 # bsd consensus
|
||||
syscon misc LC_TIME_MASK 4 0 0x10 0x20 0x20 0
|
||||
syscon misc LC_MESSAGES 5 6 6 6 6 0 # bsd consensus
|
||||
syscon misc LC_ALL 6 0 0 0 0 0
|
||||
syscon misc LC_COLLATE_MASK 8 0 1 2 2 0
|
||||
syscon misc LC_MONETARY_MASK 0x10 0 4 8 8 0
|
||||
syscon misc LC_MESSAGES_MASK 0x20 0 0x20 0x40 0x40 0
|
||||
syscon misc LC_ALL_MASK 0x1fbf 0 63 126 126 0
|
||||
|
||||
syscon lock LOCK_UNLOCK_CACHE 54 0 0 0 0 0 # wut
|
||||
|
||||
syscon misc ARPHRD_ETHER 1 1 1 1 1 0 # unix consensus
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_ADDRFAMILY,-9,1,0,-9,-9,-9
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_AGAIN,-3,2,2,-3,-3,0x2afa
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_ALLDONE,-103,-103,-103,-103,-103,-103
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_BADFLAGS,-1,3,3,-1,-1,0x2726
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_CANCELED,-101,-101,-101,-101,-101,-101
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_FAIL,-4,4,4,-4,-4,0x2afb
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_FAMILY,-6,5,5,-6,-6,0x273f
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_IDN_ENCODE,-105,-105,-105,-105,-105,-105
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_INPROGRESS,-100,-100,-100,-100,-100,-100
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_INTR,-104,-104,-104,-104,-104,-104
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_MEMORY,-10,6,6,-10,-10,0x2747
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_NODATA,-5,7,0,-5,-5,0x2af9
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_NONAME,-2,8,8,-2,-2,0x2af9
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_NOTCANCELED,-102,-102,-102,-102,-102,-102
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_OVERFLOW,-12,14,14,-14,-14,-12
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_SERVICE,-8,9,9,-8,-8,0x277d
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_SOCKTYPE,-7,10,10,-7,-7,0x273c
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_SUCCESS,0,0,0,0,0,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon eai,EAI_SYSTEM,-11,11,11,-11,-11,-11
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_ALL,6,0,0,0,0,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_ALL_MASK,0x1fbf,0,63,126,126,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_COLLATE,3,1,1,1,1,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_COLLATE_MASK,8,0,1,2,2,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_CTYPE,0,2,2,2,2,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_CTYPE_MASK,1,0,2,4,4,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_MESSAGES,5,6,6,6,6,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_MESSAGES_MASK,0x20,0,0x20,0x40,0x40,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_MONETARY,4,3,3,3,3,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_MONETARY_MASK,0x10,0,4,8,8,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_NUMERIC,1,4,4,4,4,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_NUMERIC_MASK,2,0,8,0x10,0x10,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_TIME,2,5,5,5,5,0
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc,LC_TIME_MASK,4,0,0x10,0x20,0x20,0
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_EAI_H_
|
||||
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EAI_H_
|
||||
#include "libc/runtime/symbolic.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern const long EAI_ADDRFAMILY;
|
||||
extern const long EAI_AGAIN;
|
||||
extern const long EAI_ALLDONE;
|
||||
extern const long EAI_BADFLAGS;
|
||||
extern const long EAI_CANCELED;
|
||||
extern const long EAI_FAIL;
|
||||
extern const long EAI_FAMILY;
|
||||
extern const long EAI_IDN_ENCODE;
|
||||
extern const long EAI_INPROGRESS;
|
||||
extern const long EAI_INTR;
|
||||
extern const long EAI_MEMORY;
|
||||
extern const long EAI_NODATA;
|
||||
extern const long EAI_NONAME;
|
||||
extern const long EAI_NOTCANCELED;
|
||||
extern const long EAI_OVERFLOW;
|
||||
extern const long EAI_SERVICE;
|
||||
extern const long EAI_SOCKTYPE;
|
||||
extern const long EAI_SYSTEM;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
||||
#define EAI_ADDRFAMILY SYMBOLIC(EAI_ADDRFAMILY)
|
||||
#define EAI_AGAIN SYMBOLIC(EAI_AGAIN)
|
||||
#define EAI_ALLDONE SYMBOLIC(EAI_ALLDONE)
|
||||
#define EAI_BADFLAGS SYMBOLIC(EAI_BADFLAGS)
|
||||
#define EAI_CANCELED SYMBOLIC(EAI_CANCELED)
|
||||
#define EAI_FAIL SYMBOLIC(EAI_FAIL)
|
||||
#define EAI_FAMILY SYMBOLIC(EAI_FAMILY)
|
||||
#define EAI_IDN_ENCODE SYMBOLIC(EAI_IDN_ENCODE)
|
||||
#define EAI_INPROGRESS SYMBOLIC(EAI_INPROGRESS)
|
||||
#define EAI_INTR SYMBOLIC(EAI_INTR)
|
||||
#define EAI_MEMORY SYMBOLIC(EAI_MEMORY)
|
||||
#define EAI_NODATA SYMBOLIC(EAI_NODATA)
|
||||
#define EAI_NONAME SYMBOLIC(EAI_NONAME)
|
||||
#define EAI_NOTCANCELED SYMBOLIC(EAI_NOTCANCELED)
|
||||
#define EAI_OVERFLOW SYMBOLIC(EAI_OVERFLOW)
|
||||
#define EAI_SERVICE SYMBOLIC(EAI_SERVICE)
|
||||
#define EAI_SOCKTYPE SYMBOLIC(EAI_SOCKTYPE)
|
||||
#define EAI_SUCCESS LITERALLY(0)
|
||||
#define EAI_SYSTEM SYMBOLIC(EAI_SYSTEM)
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_EAI_H_ */
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_
|
||||
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_
|
||||
#include "libc/runtime/symbolic.h"
|
||||
|
||||
#define LC_ALL SYMBOLIC(LC_ALL)
|
||||
#define LC_ALL_MASK SYMBOLIC(LC_ALL_MASK)
|
||||
#define LC_COLLATE SYMBOLIC(LC_COLLATE)
|
||||
#define LC_COLLATE_MASK SYMBOLIC(LC_COLLATE_MASK)
|
||||
#define LC_CTYPE SYMBOLIC(LC_CTYPE)
|
||||
#define LC_CTYPE_MASK SYMBOLIC(LC_CTYPE_MASK)
|
||||
#define LC_MESSAGES SYMBOLIC(LC_MESSAGES)
|
||||
#define LC_MESSAGES_MASK SYMBOLIC(LC_MESSAGES_MASK)
|
||||
#define LC_MONETARY SYMBOLIC(LC_MONETARY)
|
||||
#define LC_MONETARY_MASK SYMBOLIC(LC_MONETARY_MASK)
|
||||
#define LC_NUMERIC SYMBOLIC(LC_NUMERIC)
|
||||
#define LC_NUMERIC_MASK SYMBOLIC(LC_NUMERIC_MASK)
|
||||
#define LC_TIME SYMBOLIC(LC_TIME)
|
||||
#define LC_TIME_MASK SYMBOLIC(LC_TIME_MASK)
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern const long LC_ALL;
|
||||
extern const long LC_ALL_MASK;
|
||||
extern const long LC_COLLATE;
|
||||
extern const long LC_COLLATE_MASK;
|
||||
extern const long LC_CTYPE;
|
||||
extern const long LC_CTYPE_MASK;
|
||||
extern const long LC_MESSAGES;
|
||||
extern const long LC_MESSAGES_MASK;
|
||||
extern const long LC_MONETARY;
|
||||
extern const long LC_MONETARY_MASK;
|
||||
extern const long LC_NUMERIC;
|
||||
extern const long LC_NUMERIC_MASK;
|
||||
extern const long LC_TIME;
|
||||
extern const long LC_TIME_MASK;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_LC_H_ */
|
||||
@@ -27,7 +27,7 @@
|
||||
.endobj \name,globl
|
||||
.previous
|
||||
|
||||
#if SupportsLinux()
|
||||
#if SupportsLinux() || SupportsMetal()
|
||||
.section .sort.rodata.syscon.linux.2.\group\().\name,"a",@progbits
|
||||
.sleb128 \linux
|
||||
.previous
|
||||
|
||||
@@ -104,7 +104,7 @@ __systemfive:
|
||||
|
||||
.privileged
|
||||
.Lanchorpoint:
|
||||
#if SupportsLinux()
|
||||
#if SupportsLinux() || SupportsMetal()
|
||||
systemfive_linux:
|
||||
and $0xfff,%eax
|
||||
cmp $0xfff,%eax
|
||||
@@ -137,7 +137,7 @@ systemfive_enosys:
|
||||
systemfive_netbsd:
|
||||
shr $4*13,%rax
|
||||
jmp systemfive_bsdscrub
|
||||
.endfn systemfive_openbsd,globl,hidden
|
||||
.endfn systemfive_netbsd,globl,hidden
|
||||
#endif
|
||||
#if SupportsOpenbsd()
|
||||
systemfive_openbsd:
|
||||
@@ -222,7 +222,7 @@ systemfive_xnu:
|
||||
lea 2(%eax),%eax
|
||||
jnz 0b
|
||||
#endif
|
||||
#if SupportsLinux()
|
||||
#if SupportsLinux() || SupportsMetal()
|
||||
_init_systemfive_linux:
|
||||
pushb systemfive_linux-.Lanchorpoint
|
||||
push $LINUX
|
||||
@@ -403,7 +403,7 @@ syscon_end:
|
||||
.type syscon_end,@object
|
||||
.globl syscon_start
|
||||
.globl syscon_end
|
||||
#if SupportsLinux()
|
||||
#if SupportsLinux() || SupportsMetal()
|
||||
.section .sort.rodata.syscon.linux.1,"a",@progbits
|
||||
.align 1
|
||||
syscon_linux:/*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/unicode/locale.h"
|
||||
|
||||
typedef void *iconv_t;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_
|
||||
#define COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_
|
||||
|
||||
#define LC_CTYPE 0
|
||||
#define LC_NUMERIC 1
|
||||
#define LC_CTYPE_MASK 1
|
||||
#define LC_TIME 2
|
||||
#define LC_NUMERIC_MASK 2
|
||||
#define LC_COLLATE 3
|
||||
#define LC_MONETARY 4
|
||||
#define LC_TIME_MASK 4
|
||||
#define LC_MESSAGES 5
|
||||
#define LC_ALL 6
|
||||
#define LC_COLLATE_MASK 8
|
||||
#define LC_MONETARY_MASK 16
|
||||
#define LC_MESSAGES_MASK 32
|
||||
#define LC_ALL_MASK 0x1fbf
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
char *setlocale(int, const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_UNICODE_LOCALE_H_ */
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-*- 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│
|
||||
/*-*- 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 │
|
||||
│ Copyright 2021 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 │
|
||||
@@ -16,24 +16,14 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.exit
|
||||
.source __FILE__
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/unicode/locale.h"
|
||||
|
||||
// Exits program with grace.
|
||||
//
|
||||
// @param %dil has exit code
|
||||
// @noreturn
|
||||
exit: push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %rdi
|
||||
push %rdi
|
||||
xor %edi,%edi
|
||||
call __cxa_finalize
|
||||
call _destruct
|
||||
pop %rdi
|
||||
pop %rdi
|
||||
call _Exit
|
||||
.endfn exit,globl
|
||||
|
||||
ud2
|
||||
/**
|
||||
* Sets program locale.
|
||||
*
|
||||
* Cosmopolitan only supports the C or POSIX locale.
|
||||
*/
|
||||
char *setlocale(int category, const char *locale) {
|
||||
return firstnonnull(locale, "C");
|
||||
}
|
||||
+6
-12
@@ -61,31 +61,25 @@ o/$(MODE)/libc/unicode: $(LIBC_UNICODE) $(LIBC_UNICODE_CHECKS)
|
||||
o/$(MODE)/libc/unicode/eastasianwidth.bin: \
|
||||
libc/unicode/eastasianwidth.txt \
|
||||
o/$(MODE)/tool/decode/mkwides.com
|
||||
@TARGET=$@ ACTION=MKWIDES build/do \
|
||||
o/$(MODE)/tool/decode/mkwides.com -o $@ $<
|
||||
@$(COMPILE) -AMKWIDES -T$@ o/$(MODE)/tool/decode/mkwides.com -o $@ $<
|
||||
o/$(MODE)/libc/unicode/eastasianwidth.bin.lz4: \
|
||||
o/$(MODE)/libc/unicode/eastasianwidth.bin \
|
||||
o/$(MODE)/third_party/lz4cli/lz4cli.com
|
||||
@TARGET=$@ ACTION=LZ4 build/do \
|
||||
o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
|
||||
@$(COMPILE) -ALZ4 -T$@ o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
|
||||
o/$(MODE)/libc/unicode/eastasianwidth.s: \
|
||||
o/$(MODE)/libc/unicode/eastasianwidth.bin.lz4 \
|
||||
o/$(MODE)/tool/build/lz4toasm.com
|
||||
@TARGET=$@ ACTION=BIN2ASM build/do \
|
||||
o/$(MODE)/tool/build/lz4toasm.com -s kEastAsianWidth -o $@ $<
|
||||
@$(COMPILE) -ABIN2ASM -T$@ o/$(MODE)/tool/build/lz4toasm.com -s kEastAsianWidth -o $@ $<
|
||||
|
||||
o/$(MODE)/libc/unicode/combiningchars.bin: \
|
||||
libc/unicode/unicodedata.txt \
|
||||
o/$(MODE)/tool/decode/mkcombos.com
|
||||
@TARGET=$@ ACTION=MKCOMBOS build/do \
|
||||
o/$(MODE)/tool/decode/mkcombos.com -o $@ $<
|
||||
@$(COMPILE) -AMKCOMBOS -T$@ o/$(MODE)/tool/decode/mkcombos.com -o $@ $<
|
||||
o/$(MODE)/libc/unicode/combiningchars.bin.lz4: \
|
||||
o/$(MODE)/libc/unicode/combiningchars.bin \
|
||||
o/$(MODE)/third_party/lz4cli/lz4cli.com
|
||||
@TARGET=$@ ACTION=LZ4 build/do \
|
||||
o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
|
||||
@$(COMPILE) -ALZ4 -T$@ o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
|
||||
o/$(MODE)/libc/unicode/combiningchars.s: \
|
||||
o/$(MODE)/libc/unicode/combiningchars.bin.lz4 \
|
||||
o/$(MODE)/tool/build/lz4toasm.com
|
||||
@TARGET=$@ ACTION=BIN2ASM build/do \
|
||||
o/$(MODE)/tool/build/lz4toasm.com -s kCombiningChars -o $@ $<
|
||||
@$(COMPILE) -ABIN2ASM -T$@ o/$(MODE)/tool/build/lz4toasm.com -s kCombiningChars -o $@ $<
|
||||
+8
-12
@@ -16,8 +16,6 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
@@ -37,26 +35,24 @@
|
||||
* @see gc()
|
||||
*/
|
||||
char *(xstrcat)(const char *s, ...) {
|
||||
char *p, b[2];
|
||||
va_list va;
|
||||
size_t i, n, n2, l;
|
||||
size_t n, m;
|
||||
char *p, b[2];
|
||||
p = NULL;
|
||||
i = n = 0;
|
||||
n = 0;
|
||||
va_start(va, s);
|
||||
do {
|
||||
if ((intptr_t)s > 0 && (intptr_t)s <= 255) {
|
||||
b[0] = (unsigned char)(intptr_t)s;
|
||||
b[1] = '\0';
|
||||
s = b;
|
||||
l = 1;
|
||||
m = 1;
|
||||
} else {
|
||||
l = strlen(s);
|
||||
m = strlen(s);
|
||||
}
|
||||
if ((n2 = i + l + 16) >= n) {
|
||||
p = xrealloc(p, (n = n2 + (n2 >> 1)));
|
||||
}
|
||||
memcpy(p + i, s, l + 1);
|
||||
i += l;
|
||||
p = xrealloc(p, n + m + 1);
|
||||
memcpy(p + n, s, m + 1);
|
||||
n += m;
|
||||
} while ((s = va_arg(va, const char *)));
|
||||
va_end(va);
|
||||
return p;
|
||||
|
||||
Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user