mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Get codebase completely working with LLVM
You can now build Cosmopolitan with Clang: make -j8 MODE=llvm o/llvm/examples/hello.com The assembler and linker code is now friendly to LLVM too. So it's not needed to configure Clang to use binutils under the hood. If you love LLVM then you can now use pure LLVM.
This commit is contained in:
parent
0e36cb3ac4
commit
e75ffde09e
4528 changed files with 7776 additions and 11640 deletions
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
/ Shorthand notation for widely-acknowledged sections.
|
||||
// Shorthand notation for widely-acknowledged sections.
|
||||
.macro .rodata
|
||||
.section .rodata,"a",@progbits
|
||||
.endm
|
||||
|
@ -62,11 +62,11 @@
|
|||
.section .text.windows,"ax",@progbits
|
||||
.endm
|
||||
|
||||
/ Mergeable numeric constant sections.
|
||||
/
|
||||
/ @note linker de-dupes item/values across whole compile
|
||||
/ @note therefore item/values are reordered w.r.t. link order
|
||||
/ @note therefore no section relative addressing
|
||||
// Mergeable numeric constant sections.
|
||||
//
|
||||
// @note linker de-dupes item/values across whole compile
|
||||
// @note therefore item/values are reordered w.r.t. link order
|
||||
// @note therefore no section relative addressing
|
||||
.macro .rodata.cst4
|
||||
.section .rodata.cst4,"aM",@progbits,4
|
||||
.align 4
|
||||
|
@ -96,33 +96,33 @@
|
|||
.align 4
|
||||
.endm
|
||||
|
||||
/ Mergeable NUL-terminated UTF-8 string constant section.
|
||||
/
|
||||
/ @note linker de-dupes C strings here across whole compile
|
||||
/ @note therefore item/values are reordered w.r.t. link order
|
||||
/ @note therefore no section relative addressing
|
||||
// Mergeable NUL-terminated UTF-8 string constant section.
|
||||
//
|
||||
// @note linker de-dupes C strings here across whole compile
|
||||
// @note therefore item/values are reordered w.r.t. link order
|
||||
// @note therefore no section relative addressing
|
||||
.macro .rodata.str1.1
|
||||
.section .rodata.str1.1,"aSM",@progbits,1
|
||||
.align 1
|
||||
.endm
|
||||
|
||||
/ Locates unreferenced code invulnerable to --gc-sections.
|
||||
// Locates unreferenced code invulnerable to --gc-sections.
|
||||
.macro .keep.text
|
||||
.section .keep.text,"ax",@progbits
|
||||
.endm
|
||||
|
||||
/ Flags code as only allowed for testing purposes.
|
||||
// Flags code as only allowed for testing purposes.
|
||||
.macro .testonly
|
||||
.section .test,"ax",@progbits
|
||||
.endm
|
||||
|
||||
/ Makes code runnable while code morphing.
|
||||
// Makes code runnable while code morphing.
|
||||
.macro .privileged
|
||||
.section .privileged,"ax",@progbits
|
||||
.endm
|
||||
|
||||
/ Post-Initialization Read-Only (PIRO) BSS section.
|
||||
/ @param ss is an optional string, for control image locality
|
||||
// Post-Initialization Read-Only (PIRO) BSS section.
|
||||
// @param ss is an optional string, for control image locality
|
||||
.macro .piro ss
|
||||
.ifnb \ss
|
||||
.section .piro.sort.bss.\ss,"aw",@nobits
|
||||
|
@ -131,9 +131,9 @@
|
|||
.endif
|
||||
.endm
|
||||
|
||||
/ Helpers for Cosmopolitan _init() amalgamation magic.
|
||||
/ @param name should be consistent across macros for a module
|
||||
/ @see libc/runtime/_init.S
|
||||
// Helpers for Cosmopolitan _init() amalgamation magic.
|
||||
// @param name should be consistent across macros for a module
|
||||
// @see libc/runtime/_init.S
|
||||
.macro .initro number:req name:req
|
||||
.section .initro.\number\().\name,"a",@progbits
|
||||
.align 8
|
||||
|
@ -151,16 +151,16 @@
|
|||
.previous
|
||||
.endm
|
||||
|
||||
/ Declares alternative implementation of function.
|
||||
/ @param implement e.g. tinymath_pow
|
||||
/ @param canonical e.g. pow
|
||||
// Declares alternative implementation of function.
|
||||
// @param implement e.g. tinymath_pow
|
||||
// @param canonical e.g. pow
|
||||
.macro .alias implement:req canonical:req
|
||||
.equ \canonical,\implement
|
||||
.weak \canonical
|
||||
.endm
|
||||
|
||||
/ Ends function definition.
|
||||
/ @cost saves 1-3 lines of code
|
||||
// Ends function definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endfn name:req bnd vis
|
||||
.size \name,.-\name
|
||||
.type \name,@function
|
||||
|
@ -172,8 +172,8 @@
|
|||
.endif
|
||||
.endm
|
||||
|
||||
/ Ends variable definition.
|
||||
/ @cost saves 1-3 lines of code
|
||||
// Ends variable definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endobj name:req bnd vis
|
||||
.size \name,.-\name
|
||||
.type \name,@object
|
||||
|
@ -185,35 +185,35 @@
|
|||
.endif
|
||||
.endm
|
||||
|
||||
/ LOOP Instruction Replacement.
|
||||
/ With its mop-Fusion Mexican equivalent.
|
||||
/ Thus avoiding 3x legacy pipeline slowdown.
|
||||
// LOOP Instruction Replacement.
|
||||
// With its mop-Fusion Mexican equivalent.
|
||||
// Thus avoiding 3x legacy pipeline slowdown.
|
||||
.macro .loop label:req
|
||||
.byte 0x83,0xe9,0x01 # sub $1,%ecx
|
||||
jnz \label
|
||||
.endm
|
||||
|
||||
/ Pushes CONSTEXPR ∈ [-128,127].
|
||||
/ @note assembler is wrong for non-literal constexprs
|
||||
// Pushes CONSTEXPR ∈ [-128,127].
|
||||
// @note assembler is wrong for non-literal constexprs
|
||||
.macro pushb x:req
|
||||
.byte 0x6a,\x
|
||||
.endm
|
||||
|
||||
/ Sign-extends CONSTEXPR ∈ [-128,127] to REGISTER.
|
||||
/ @cost ≥1 cycles, -2 bytes
|
||||
// Sign-extends CONSTEXPR ∈ [-128,127] to REGISTER.
|
||||
// @cost ≥1 cycles, -2 bytes
|
||||
.macro pushpop constexpr:req register:req
|
||||
pushb \constexpr
|
||||
pop \register
|
||||
.endm
|
||||
|
||||
/ Moves REGISTER to REGISTER.
|
||||
/ @cost ≥1 cycles, -1 REX byte
|
||||
// Moves REGISTER to REGISTER.
|
||||
// @cost ≥1 cycles, -1 REX byte
|
||||
.macro movpp src:req dest:req
|
||||
push \src
|
||||
pop \dest
|
||||
.endm
|
||||
|
||||
/ Declares optional function.
|
||||
// Declares optional function.
|
||||
.macro .optfn fn:req
|
||||
.globl \fn
|
||||
.weak \fn
|
||||
|
@ -221,8 +221,8 @@
|
|||
.type \fn,@function
|
||||
.endm
|
||||
|
||||
/ Embeds fixed-width zero-filled string table.
|
||||
/ @note zero-padded ≠ nul-terminated
|
||||
// Embeds fixed-width zero-filled string table.
|
||||
// @note zero-padded ≠ nul-terminated
|
||||
.macro .fxstr width head rest:vararg
|
||||
.ifnb \head
|
||||
0: .ascii "\head"
|
||||
|
@ -231,15 +231,15 @@
|
|||
.endif
|
||||
.endm
|
||||
|
||||
/ Embeds Fixed-Width Zero-Padded String.
|
||||
/ @note .fxstr is better
|
||||
// Embeds Fixed-Width Zero-Padded String.
|
||||
// @note .fxstr is better
|
||||
.macro .ascin str:req fieldsize:req
|
||||
1347: .ascii "\str"
|
||||
.org 1347b+\fieldsize,0x00
|
||||
.endm
|
||||
|
||||
/ Marks symbols as object en-masse.
|
||||
/ @note zero-padded ≠ nul-terminated
|
||||
// Marks symbols as object en-masse.
|
||||
// @note zero-padded ≠ nul-terminated
|
||||
.macro .object symbol rest:vararg
|
||||
.ifnb \symbol
|
||||
.type \symbol,@object
|
||||
|
@ -247,18 +247,14 @@
|
|||
.endif
|
||||
.endm
|
||||
|
||||
/ Pads function prologue unconditionally for runtime hooking.
|
||||
/ @cost ≥0.3 cycles, 5 bytes
|
||||
/ @see .profilable
|
||||
// Pads function prologue unconditionally for runtime hooking.
|
||||
// @cost ≥0.3 cycles, 5 bytes
|
||||
// @see .profilable
|
||||
.macro .hookable
|
||||
/ nopl 0x00(%rax,%rax,1)
|
||||
83457: .byte 0x0f,0x1f,0x44,0x00,0x00
|
||||
.section __mcount_loc,"a",@progbits
|
||||
.quad 83457b
|
||||
.previous
|
||||
.byte 0x0f,0x1f,0x44,0x00,0x00
|
||||
.endm
|
||||
|
||||
/ Puts initialized data in uninitialized data section.
|
||||
// Puts initialized data in uninitialized data section.
|
||||
.macro .bsdata name:req expr:req bnd vis
|
||||
.section .initbss.300._init_\name,"aw",@nobits
|
||||
\name: .quad 0
|
||||
|
@ -274,9 +270,9 @@ _init_\name:
|
|||
.previous
|
||||
.endm
|
||||
|
||||
/ ICE Breakpoint.
|
||||
/ Modern gas forgot this but objdump knows
|
||||
/ @mode long,legacy,real
|
||||
// ICE Breakpoint.
|
||||
// Modern gas forgot this but objdump knows
|
||||
// @mode long,legacy,real
|
||||
.macro icebp
|
||||
.byte 0xF1
|
||||
.endm
|
||||
|
@ -284,8 +280,8 @@ _init_\name:
|
|||
icebp
|
||||
.endm
|
||||
|
||||
/ Sets breakpoint for software debugger.
|
||||
/ @mode long,legacy,real
|
||||
// Sets breakpoint for software debugger.
|
||||
// @mode long,legacy,real
|
||||
.macro .softicebp
|
||||
.byte 0x53 # push bx
|
||||
.byte 0x87,0xdb # xchg bx,bx (bochs breakpoint)
|
||||
|
@ -294,38 +290,38 @@ _init_\name:
|
|||
int3 # gdb breakpoint
|
||||
.endm
|
||||
|
||||
/ Assembles Intel Official 4-Byte NOP.
|
||||
// Assembles Intel Official 4-Byte NOP.
|
||||
.macro fatnop4
|
||||
.byte 0x0f,0x1f,0x40,0x00
|
||||
.endm
|
||||
|
||||
/ Pulls unrelated module into linkage.
|
||||
/
|
||||
/ In order for this technique to work with --gc-sections, another
|
||||
/ module somewhere might want to weakly reference whats yoinked.
|
||||
// Pulls unrelated module into linkage.
|
||||
//
|
||||
// In order for this technique to work with --gc-sections, another
|
||||
// module somewhere might want to weakly reference whats yoinked.
|
||||
.macro yoink symbol:req
|
||||
.section .yoink
|
||||
nop "\symbol"
|
||||
nopl "\symbol"(%rip)
|
||||
.previous
|
||||
.endm
|
||||
.macro .yoink symbol:req
|
||||
.section .yoink
|
||||
nop "\symbol"
|
||||
nopl "\symbol"(%rip)
|
||||
.previous
|
||||
.endm
|
||||
|
||||
/ Calls Windows function.
|
||||
/
|
||||
/ @param cx,dx,r8,r9,stack
|
||||
/ @return ax
|
||||
/ @clob ax,cx,dx,r8-r11
|
||||
// Calls Windows function.
|
||||
//
|
||||
// @param cx,dx,r8,r9,stack
|
||||
// @return ax
|
||||
// @clob ax,cx,dx,r8-r11
|
||||
.macro ntcall symbol:req
|
||||
sub $32,%rsp
|
||||
call *\symbol(%rip)
|
||||
add $32,%rsp
|
||||
.endm
|
||||
|
||||
/ Custom emulator instruction for bottom stack frame.
|
||||
// Custom emulator instruction for bottom stack frame.
|
||||
.macro bofram endfunc:req
|
||||
.byte 0x0f,0x1f,0105,\endfunc-. # nopl disp8(%rbp)
|
||||
.endm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue