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:
Justine Tunney 2021-02-08 09:19:00 -08:00
parent 0e36cb3ac4
commit e75ffde09e
4528 changed files with 7776 additions and 11640 deletions

View file

@ -23,7 +23,7 @@
#define vzeroupper
#endif
/ Begins definition of frameless function that calls no functions.
// Begins definition of frameless function that calls no functions.
.macro .leafprologue
#if !(defined(TINY) && !defined(__PG__))
push %rbp
@ -31,7 +31,7 @@
#endif
.endm
/ Ends definition of frameless function that calls no functions.
// Ends definition of frameless function that calls no functions.
.macro .leafepilogue
#if !(defined(TINY) && !defined(__PG__))
pop %rbp
@ -39,16 +39,16 @@
ret
.endm
/ Good alignment for functions where alignment actually helps.
/ @note 16-byte
// Good alignment for functions where alignment actually helps.
// @note 16-byte
.macro .alignfunc
#ifndef __OPTIMIZE_SIZE__
.p2align 4
#endif
.endm
/ Good alignment for loops where alignment actually helps.
/ @note 16-byte if <10 padding otherwise 8-byte
// Good alignment for loops where alignment actually helps.
// @note 16-byte if <10 padding otherwise 8-byte
.macro .alignloop
#ifndef __OPTIMIZE_SIZE__
.p2align 4,,10
@ -56,8 +56,8 @@
#endif
.endm
/ Loads Effective Address
/ Supporting security blankets
// Loads Effective Address
// Supporting security blankets
.macro plea symbol:req reg64:req reg32:req
#if __PIC__ + __PIE__ + __code_model_medium__ + __code_model_large__ + 0 > 1
lea \symbol(%rip),\reg64
@ -66,8 +66,8 @@
#endif
.endm
/ Loads Effective Address to Stack
/ Supporting security blankets
// Loads Effective Address to Stack
// Supporting security blankets
.macro pshaddr symbol:req
#if __PIC__ + __PIE__ + __code_model_medium__ + __code_model_large__ + 0 > 1
push $IMAGE_BASE_VIRTUAL+RVA(\symbol)(%rip),\reg64
@ -76,12 +76,12 @@
#endif
.endm
/ TODO(jart): delete
/ Loads Effective Address
/ Supporting security blankets
// TODO(jart): delete
// Loads Effective Address
// Supporting security blankets
.macro ezlea symbol:req reg:req
#if __pic__ + __pie__ + __code_model_medium__ + __code_model_large__ + 0 > 1
/ lea \symbol(%rip),%r\reg
// lea \symbol(%rip),%r\reg
mov $\symbol,%e\reg
#else
mov $\symbol,%e\reg
@ -97,7 +97,7 @@
#endif
.endm
/ Creates first stack frame.
// Creates first stack frame.
.macro .frame0
and $-16,%rsp
xor %ebp,%ebp
@ -106,38 +106,33 @@
.macro .source symbol:req
.endm
/ Inserts profiling hook in prologue if cc wants it.
/
/ Cosmopolitan does this in a slightly different way from normal
/ GNU toolchains. We always use the -mnop-mcount behavior, since
/ the runtime is able to morph the binary at runtime. It is good
/ since we can put hooks for profiling and function tracing into
/ most builds, without any impact on performance.
/
/ @cost ≥0.3 cycles, 5 bytes
/ @see build/compile
// Inserts profiling hook in prologue if cc wants it.
//
// Cosmopolitan does this in a slightly different way from normal
// GNU toolchains. We always use the -mnop-mcount behavior, since
// the runtime is able to morph the binary at runtime. It is good
// since we can put hooks for profiling and function tracing into
// most builds, without any impact on performance.
//
// @cost ≥0.3 cycles, 5 bytes
// @see build/compile
.macro .profilable
#ifdef __PG__
1382:
#if defined(__MFENTRY__)
call __fentry__
#elif defined(__PIC__) || defined(__PIE__)
/ nopw 0x00(%rax,%rax,1)
// nopw 0x00(%rax,%rax,1)
.byte 0x66,0x0f,0x1f,0x44,0x00,0x00
#else
/ nopl 0x00(%rax,%rax,1)
// nopl 0x00(%rax,%rax,1)
.byte 0x0f,0x1f,0x44,0x00,0x00
#endif
#if defined(__MRECORD_MCOUNT__) && !defined(__MFENTRY__)
.section __mcount_loc,"a",@progbits
.quad 1382b
.previous
#endif
#endif
.endm
/ Pushes RVA on stack of linktime mergeable string literal.
/ @see popstr
// Pushes RVA on stack of linktime mergeable string literal.
// @see popstr
.macro pushstr text
.section .rodata.str1.1,"aSM",@progbits,1
.Lstr\@: .asciz "\text"
@ -146,14 +141,14 @@
push $.Lstr\@ - IMAGE_BASE_VIRTUAL
.endm
/ Pops off stack string address.
/ @see pushstr
// Pops off stack string address.
// @see pushstr
.macro popstr dest:req
addl $IMAGE_BASE_VIRTUAL,(%rsp)
pop \dest
.endm
/ Loads address of linktime mergeable string literal into register.
// Loads address of linktime mergeable string literal into register.
.macro getstr text:req reg64:req reg32 regsz64 regsz32 bias=0
.section .rodata.str1.1,"aSM",@progbits,1
.type .Lstr\@,@object
@ -175,8 +170,8 @@
.endif
.endm
/ TODO(jart): delete
/ Loads address of linktime mergeable string literal into register.
// TODO(jart): delete
// Loads address of linktime mergeable string literal into register.
.macro loadstr text:req reg:req regsz bias=0
.section .rodata.str1.1,"aSM",@progbits,1
.type .Lstr\@,@object