Trim down executable sizes

This commit is contained in:
Justine Tunney 2021-02-11 08:37:18 -08:00
parent ec69413f83
commit bfa8581537
19 changed files with 1176 additions and 131 deletions

View file

@ -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"
@ -530,10 +529,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 +537,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 +548,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 +558,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 +597,8 @@ netbsd.ident:
.previous
#endif /* SupportsNetbsd() */
#endif /* SupportsSystemv() */
/*
@ -1565,6 +1559,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

View file

@ -201,21 +201,19 @@ 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;
/* 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))

View file

@ -296,3 +296,765 @@ CONFIG_CXXFLAGS += -std=c++11
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v1)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=1
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v2)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=2
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v3)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=3
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v4)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=4
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v5)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=5
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v6)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=6
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v7)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=7
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v8)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=8
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v9)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=9
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v10)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=10
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v11)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=11
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v12)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=12
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v13)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=13
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v14)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=14
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v15)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=15
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v16)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=16
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v17)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=17
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v18)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=18
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v19)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=19
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v20)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=20
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v21)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=21
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v22)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=22
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v23)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=23
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v24)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=24
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v25)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=25
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v26)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=26
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v27)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=27
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v28)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=28
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v29)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=29
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v30)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=30
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v31)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=31
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v32)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=32
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v33)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=33
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v34)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=34
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v35)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=35
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v36)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=36
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v37)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=37
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v38)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=38
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v39)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=39
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v40)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=40
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v41)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=41
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v42)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=42
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v43)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=43
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v44)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=44
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v45)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=45
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v46)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=46
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v47)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=47
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v48)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=48
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v49)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=49
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v50)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=50
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v51)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=51
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v52)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=52
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v53)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=53
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v54)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=54
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v55)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=55
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v56)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=56
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v57)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=57
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v58)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=58
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v59)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=59
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v60)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=60
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v61)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=61
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v62)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=62
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v63)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=63
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v64)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=64
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v65)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=65
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v66)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=66
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v67)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=67
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v68)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=68
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v69)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=69
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v70)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=70
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v71)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=71
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v72)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=72
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v73)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=73
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v74)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=74
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v75)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=75
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v76)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=76
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v77)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=77
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v78)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=78
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v79)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=79
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v80)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=80
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v81)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=81
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v82)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=82
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v83)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=83
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v84)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=84
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v85)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=85
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v86)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=86
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v87)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=87
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v88)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=88
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v89)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=89
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v90)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=90
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v91)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=91
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v92)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=92
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v93)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=93
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v94)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=94
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v95)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=95
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v96)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=96
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v97)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=97
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v98)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=98
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v99)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=99
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v100)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=100
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v101)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=101
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v102)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=102
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v103)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=103
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v104)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=104
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v105)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=105
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v106)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=106
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v107)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=107
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v108)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=108
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v109)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=109
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v110)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=110
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v111)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=111
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v112)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=112
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v113)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=113
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v114)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=114
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v115)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=115
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v116)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=116
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v117)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=117
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v118)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=118
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v119)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=119
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v120)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=120
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v121)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=121
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v122)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=122
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v123)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=123
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v124)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=124
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v125)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=125
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v126)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=126
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), v127)
CONFIG_CPPFLAGS += -DTINY -DNDEBUG -DTRUSTWORTHY -DSUPPORT_VECTOR=127
CONFIG_CCFLAGS += -Os -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
TARGET_ARCH ?= -msse3
endif

View file

@ -197,6 +197,7 @@ DEFAULT_LDFLAGS = \
-static \
-nostdlib \
-m elf_x86_64 \
--gc-sections \
--build-id=none \
--no-dynamic-linker \
-z max-page-size=0x1000

View file

@ -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;
}

18
examples/statsize.c Normal file
View file

@ -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;
}

BIN
hello.com Normal file

Binary file not shown.

View file

@ -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];

View file

@ -1,44 +0,0 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
.text.exit
.source __FILE__
// 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

View file

@ -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,31 @@
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/weaken.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.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
extern const uintptr_t __fini_array_start[];
extern const uintptr_t __fini_array_end[];
ud2
/**
* 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);
}

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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:/*

319
tool/build/dis.c Normal file
View file

@ -0,0 +1,319 @@
/*-*- 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/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/def.h"
#include "libc/elf/elf.h"
#include "libc/elf/struct/ehdr.h"
#include "libc/elf/struct/shdr.h"
#include "libc/elf/struct/sym.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/nt/struct/importobjectheader.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/dis.h"
#include "tool/build/lib/high.h"
#include "tool/build/lib/loader.h"
#define HEXWIDTH 8
const char *const kRealSymbols[] = {
"a20", "ape.mbrpad", "ape.str",
"ape_disk", "ape_grub", "ape_mz",
"apesh", "dsknfo", "e820",
"gdt", "golong", "hiload",
"lcheck", "longmodeloader", "pc",
"pcread", "pinit", "realmodeloader",
"rldie", "rvputs", "sconf",
"sinit", "sinit4", "str.cpuid",
"str.crlf", "str.dsknfo", "str.e820",
"str.error", "str.long", "str.memory",
"str.oldskool", "stub", "unreal",
};
const char *const kLegacySymbols[] = {
"ape_grub_entry",
};
bool boop;
long cursym;
Elf64_Ehdr *elf;
Elf64_Shdr *sec;
struct Dis dis[1];
struct Machine m[1];
struct Elf diself[1];
char codebuf[256];
char optspecbuf[128];
const Elf64_Sym *syms;
char *symstrs, *secstrs;
size_t i, j, k, l, size, skip, symcount;
bool IsRealSymbol(const char *s) {
int m, l, r, x;
l = 0;
r = ARRAYLEN(kRealSymbols) - 1;
while (l <= r) {
m = (l + r) >> 1;
x = strcmp(s, kRealSymbols[m]);
if (x < 0) {
r = m - 1;
} else if (x > 0) {
l = m + 1;
} else {
return true;
}
}
return false;
}
bool IsLegacySymbol(const char *s) {
int m, l, r, x;
l = 0;
r = ARRAYLEN(kLegacySymbols) - 1;
while (l <= r) {
m = (l + r) >> 1;
x = strcmp(s, kLegacySymbols[m]);
if (x < 0) {
r = m - 1;
} else if (x > 0) {
l = m + 1;
} else {
return true;
}
}
return false;
}
void SetSymbol(bool printit) {
if (!boop) {
printf("\n");
boop = true;
}
if (printit) {
printf("\e[38;5;%dm%s\e[0m:\n", g_high.label, symstrs + syms[k].st_name);
}
if (IsRealSymbol(symstrs + syms[k].st_name)) {
if (m->mode != XED_MACHINE_MODE_REAL) {
printf("\t\e[38;5;%dm.code16\e[0m\n", g_high.keyword);
}
m->mode = XED_MACHINE_MODE_REAL;
} else if (IsLegacySymbol(symstrs + syms[k].st_name)) {
if (m->mode != XED_MACHINE_MODE_LEGACY_32) {
printf("\t\e[38;5;%dm.code32\e[0m\n", g_high.keyword);
}
m->mode = XED_MACHINE_MODE_LEGACY_32;
} else {
if (m->mode != XED_MACHINE_MODE_LONG_64) {
printf("\t\e[38;5;%dm.code64\e[0m\n", g_high.keyword);
}
m->mode = XED_MACHINE_MODE_LONG_64;
}
cursym = k;
if (syms[k].st_size) {
skip = syms[k].st_size;
} else {
skip = -1;
for (l = 0; l < symcount; ++l) {
if (syms[l].st_shndx == i && syms[l].st_name &&
syms[l].st_value > syms[cursym].st_value) {
skip = MIN(skip, syms[l].st_value - syms[cursym].st_value);
}
}
if (skip == -1) {
skip = sec->sh_addr + sec->sh_size - syms[cursym].st_value;
}
}
}
void PrintSymbolName(void) {
bool done;
done = false;
boop = false;
for (k = 0; k < symcount; ++k) {
if (syms[k].st_value == sec->sh_addr + j && syms[k].st_name) {
if (!done && syms[k].st_size) {
SetSymbol(true);
done = true;
} else {
if (!boop) {
printf("\n");
boop = true;
}
printf("\e[38;5;%dm%s\e[0m:\n", g_high.label,
symstrs + syms[k].st_name);
}
}
}
if (done) {
return;
}
for (k = 0; k < symcount; ++k) {
if (ELF64_ST_TYPE(syms[k].st_info) && syms[k].st_name &&
syms[k].st_value == sec->sh_addr + j) {
SetSymbol(false);
return;
}
}
for (k = 0; k < symcount; ++k) {
if (syms[k].st_name && syms[k].st_value == sec->sh_addr + j) {
SetSymbol(false);
return;
}
}
if (cursym != -1 && syms[cursym].st_size &&
sec->sh_addr + j >= syms[cursym].st_value + syms[cursym].st_size) {
cursym = -1;
skip = 1;
}
}
bool Ild(void) {
int remain;
remain = 15;
if (cursym != -1 && syms[cursym].st_size) {
remain =
(syms[cursym].st_value + syms[cursym].st_size) - (sec->sh_addr + j);
}
xed_decoded_inst_zero_set_mode(dis->xedd, m->mode);
xed_instruction_length_decode(dis->xedd, (char *)elf + sec->sh_offset + j,
remain);
skip = dis->xedd->op.error ? 1 : MAX(1, dis->xedd->length);
return !dis->xedd->op.error;
}
bool IsCode(void) {
if (!(sec->sh_flags & SHF_EXECINSTR)) return false;
if (cursym != -1 && ELF64_ST_TYPE(syms[cursym].st_info) == STT_OBJECT) {
return false;
}
return true;
}
bool IsBss(void) {
return sec->sh_type == SHT_NOBITS;
}
void Disassemble(void) {
int c;
bool istext;
cursym = -1;
secstrs = GetElfSectionNameStringTable(elf, size);
symstrs = GetElfStringTable(elf, size);
syms = GetElfSymbolTable(elf, size, &symcount);
for (i = 0; i < elf->e_shnum; ++i) {
sec = GetElfSectionHeaderAddress(elf, size, i);
if (!sec->sh_size) continue;
if (!(sec->sh_flags & SHF_ALLOC)) continue;
printf("\n\t\e[38;5;%dm.section\e[0m %s\n", g_high.keyword,
secstrs + sec->sh_name);
for (j = 0; j < sec->sh_size; j += MAX(1, skip)) {
PrintSymbolName();
if (cursym == -1) continue;
if (sec->sh_type == SHT_NOBITS) {
printf("\t\e[38;5;%dm.zero\e[0m\t%ld\n", g_high.keyword, skip);
} else if (IsCode()) {
if (Ild()) {
dis->addr = sec->sh_addr + j;
DisInst(dis, codebuf, DisSpec(dis->xedd, optspecbuf));
printf("\t%s\n", codebuf);
} else {
printf("\t.wut\t%ld\n", dis->xedd->op.error);
}
} else {
for (k = 0; k < skip; ++k) {
if (!(k & (HEXWIDTH - 1))) {
if (k) {
printf(" \e[38;5;%dm# %#.*s\e[0m\n", g_high.comment, HEXWIDTH,
(unsigned char *)elf + sec->sh_offset + j + k - HEXWIDTH);
}
printf("\t\e[38;5;%dm.byte\e[0m\t", g_high.keyword);
} else if (k) {
printf(",");
}
printf("0x%02x", ((unsigned char *)elf)[sec->sh_offset + j + k]);
}
if (k) {
if (!(k & (HEXWIDTH - 1))) {
printf(" \e[38;5;%dm# %#.*s\e[0m\n", g_high.comment, HEXWIDTH,
(unsigned char *)elf + sec->sh_offset + j + skip - HEXWIDTH);
} else {
for (l = 0; l < HEXWIDTH - (k & (HEXWIDTH - 1)); ++l) {
printf(" ");
}
printf(" \e[38;5;%dm# %#.*s\e[0m\n", g_high.comment,
skip - ROUNDDOWN(skip, HEXWIDTH),
(unsigned char *)elf + sec->sh_offset + j +
ROUNDDOWN(skip, HEXWIDTH));
}
}
}
}
}
}
int main(int argc, char *argv[]) {
showcrashreports();
int fd;
void *map;
struct stat st;
const char *path;
if (argc == 1) {
path = "o/v127/examples/hello2.com.dbg";
/* fprintf(stderr, "USAGE: %s ELF\n", program_invocation_name); */
/* exit(1); */
} else {
path = argv[1];
}
if ((fd = open(path, O_RDONLY)) == -1) {
fprintf(stderr, "ERROR: NOT FOUND: %`'s\n", path);
exit(1);
}
CHECK_NE(-1, fstat(fd, &st));
CHECK_NE(0, st.st_size);
CHECK_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
if (memcmp(map, ELFMAG, 4)) {
fprintf(stderr, "ERROR: NOT AN ELF: %`'s\n", path);
exit(1);
}
m->mode = XED_MACHINE_MODE_LONG_64;
g_high.keyword = 155;
g_high.reg = 215;
g_high.literal = 182;
g_high.label = 221;
g_high.comment = 112;
g_high.quote = 180;
dis->m = m;
diself->prog = path;
LoadDebugSymbols(diself);
DisLoadElf(dis, diself);
LOGIFNEG1(close(fd));
elf = map;
size = st.st_size;
Disassemble();
LOGIFNEG1(munmap(map, st.st_size));
return 0;
}

View file

@ -30,9 +30,11 @@ void LoadDebugSymbols(struct Elf *elf) {
int fd;
void *elfmap;
struct stat st;
const char *path;
if (elf->ehdr) return;
DCHECK_NOTNULL(elf->prog);
if ((fd = open(gc(xstrcat(elf->prog, ".dbg")), O_RDONLY)) != -1) {
if ((fd = open(gc(xstrcat(elf->prog, ".dbg")), O_RDONLY)) != -1 ||
(fd = open(elf->prog, O_RDONLY))) {
if (fstat(fd, &st) != -1 &&
(elfmap = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) !=
MAP_FAILED) {

View file

@ -199,7 +199,6 @@ long DisFindSymByName(struct Dis *d, const char *s) {
}
void DisLoadElf(struct Dis *d, struct Elf *elf) {
LOGF("DisLoadElf");
if (!elf || !elf->ehdr) return;
DisLoadElfLoads(d, elf);
DisLoadElfSyms(d, elf);

View file

@ -301,13 +301,14 @@ static void printelfrelocations(void) {
}
int main(int argc, char *argv[]) {
int fd;
showcrashreports();
if (argc != 2) {
fprintf(stderr, "usage: %s FILE\n", argv[0]);
return 1;
}
path = argv[1];
int64_t fd = open(path, O_RDONLY);
fd = open(path, O_RDONLY);
if (fd == -1) {
if (errno == ENOENT) {
fprintf(stderr, "error: %`s not found\n", path);