From bfa858153737fad6c5dc783bcc40bbb28762c068 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 11 Feb 2021 08:37:18 -0800 Subject: [PATCH] Trim down executable sizes --- ape/ape.S | 23 +- ape/ape.lds | 8 +- build/config.mk | 762 +++++++++++++++++++++++++++++ build/definitions.mk | 1 + examples/hello2.c | 16 +- examples/statsize.c | 18 + hello.com | Bin 0 -> 16384 bytes libc/calls/fstatat-nt.c | 2 +- libc/runtime/destruct.S | 44 -- libc/runtime/{exit.S => exit.c} | 51 +- libc/runtime/exit3.S | 15 +- libc/runtime/vfork.S | 2 + libc/runtime/winmain.greg.c | 28 +- libc/sysv/consts/syscon.internal.h | 2 +- libc/sysv/systemfive.S | 8 +- tool/build/dis.c | 319 ++++++++++++ tool/build/lib/debug.c | 4 +- tool/build/lib/diself.c | 1 - tool/decode/elf.c | 3 +- 19 files changed, 1176 insertions(+), 131 deletions(-) create mode 100644 examples/statsize.c create mode 100644 hello.com delete mode 100644 libc/runtime/destruct.S rename libc/runtime/{exit.S => exit.c} (62%) create mode 100644 tool/build/dis.c diff --git a/ape/ape.S b/ape/ape.S index 4a73fd4fe..57097e585 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -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 diff --git a/ape/ape.lds b/ape/ape.lds index c12e8818d..d1b1db3e8 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -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)) diff --git a/build/config.mk b/build/config.mk index 9b0e3d399..7ce0bc974 100644 --- a/build/config.mk +++ b/build/config.mk @@ -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 diff --git a/build/definitions.mk b/build/definitions.mk index 5bdf70227..456f8d524 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -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 diff --git a/examples/hello2.c b/examples/hello2.c index 6c8c85045..e29718369 100644 --- a/examples/hello2.c +++ b/examples/hello2.c @@ -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; } diff --git a/examples/statsize.c b/examples/statsize.c new file mode 100644 index 000000000..4ed9c6bfe --- /dev/null +++ b/examples/statsize.c @@ -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; +} diff --git a/hello.com b/hello.com new file mode 100644 index 0000000000000000000000000000000000000000..4a58161132f4e33bf6484499b69bbe48ce795432 GIT binary patch literal 16384 zcmeG?3v^q>l_OcQW#uD<#KDwLCax1gNrGiQiAfDoEG6^klYjCr}3ak^lB#R(yKMi2r4$1x#q?>tG4 zLpj~g*|TSRjz@lT@66nL=gyrwGxyE2{qB3$HCYR<*CS*^6DW~XNM}x>6x>xYtuPIJ zIuoJan&T+Gpra$6PJ~Z%rs3Zs6xWXJH6nDO2Q`@n+oO~1Z;7vcJ$I3W(3ah&8&N0H zl$K_g`^?9!W`x?`?m~H;NYx%OMNIP9XIm!C+ukF=b+v*lQ1C^{7V@!{*z7n#P}`?^v7-=6yy znx0woGli|@*~d1vQz}!kpY?_5Q}j zI$r}`(TsC)^Kx#;(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UFl7Q;dsCu&v5gT!9^g3IUz;NuAc(Fw0oh zvNpU9G_(|Nz>ZQ|5o2MOgSzFmqKf6fpTdBmsHE6oE2{)qK%=)>>~O8`z)99rv6?{8 zQUX1e!>AmUYz5VRU3rNevn39oUWY3kHs}DZ%z;%8b^~P{%W*ZafokPcV+;HhRWK#R zlo~p%D2L*5Tx?sw$sg(2K@C-<^FwL!0EL4n%x1vuhHq_9N^l%Z9z)7-pLgu{$qrNg)>#- z3;IE(zkzl_X}+78w$RQib~RB#D6w@x&PM<5Aj#+88m5#*pktNWd0&Z(^4NA#U4g9J zS=T@-D2Ib;qx4-=dU-je%O#2uo@?T{DY|JIR@DXEbz8m4Xexb;(|ZM>)d6?HWayqH zw2wr355vVlUaE9CbahA&7tl1Gghq&uXu2*5S0~|JNw_Hqo0G6L2_H|wXOi$h680tG zn@K1o;l(7(PHOstX&Tf1Q{TTjG8fK%9kpN;z@_*U1*xI})89gKRrtYV_3oAyEcEEHGn%84Ju<;J;^q{{X+d{7(P? literal 0 HcmV?d00001 diff --git a/libc/calls/fstatat-nt.c b/libc/calls/fstatat-nt.c index fcdec0b4b..e21c3b942 100644 --- a/libc/calls/fstatat-nt.c +++ b/libc/calls/fstatat-nt.c @@ -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]; diff --git a/libc/runtime/destruct.S b/libc/runtime/destruct.S deleted file mode 100644 index 642394038..000000000 --- a/libc/runtime/destruct.S +++ /dev/null @@ -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 diff --git a/libc/runtime/exit.S b/libc/runtime/exit.c similarity index 62% rename from libc/runtime/exit.S rename to libc/runtime/exit.c index cf062c92a..694bc000e 100644 --- a/libc/runtime/exit.S +++ b/libc/runtime/exit.c @@ -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); +} diff --git a/libc/runtime/exit3.S b/libc/runtime/exit3.S index 5344a0a15..62115fbb5 100644 --- a/libc/runtime/exit3.S +++ b/libc/runtime/exit3.S @@ -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 diff --git a/libc/runtime/vfork.S b/libc/runtime/vfork.S index 8f71213e5..db2743480 100644 --- a/libc/runtime/vfork.S +++ b/libc/runtime/vfork.S @@ -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 diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index 8353b5066..106bc5f6c 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -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; diff --git a/libc/sysv/consts/syscon.internal.h b/libc/sysv/consts/syscon.internal.h index 68c791b98..be78d2273 100644 --- a/libc/sysv/consts/syscon.internal.h +++ b/libc/sysv/consts/syscon.internal.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 diff --git a/libc/sysv/systemfive.S b/libc/sysv/systemfive.S index 7c9ec2548..c87ea5076 100644 --- a/libc/sysv/systemfive.S +++ b/libc/sysv/systemfive.S @@ -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:/* diff --git a/tool/build/dis.c b/tool/build/dis.c new file mode 100644 index 000000000..ac6e78a71 --- /dev/null +++ b/tool/build/dis.c @@ -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; +} diff --git a/tool/build/lib/debug.c b/tool/build/lib/debug.c index ac7535958..7c65dde96 100644 --- a/tool/build/lib/debug.c +++ b/tool/build/lib/debug.c @@ -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) { diff --git a/tool/build/lib/diself.c b/tool/build/lib/diself.c index 4c686bac1..37ccfd028 100644 --- a/tool/build/lib/diself.c +++ b/tool/build/lib/diself.c @@ -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); diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 5e101dfda..2d7a09bab 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -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);