mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +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
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp KernelBase,__imp_GetProcessImageFileNameA,GetProcessImageFileNameA,676
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp KernelBase,__imp_GetProcessImageFileNameW,GetProcessImageFileNameW,677
|
|
@ -2,68 +2,68 @@
|
|||
#define COSMOPOLITAN_LIBC_NT_STATUS_H_
|
||||
|
||||
/* high two bits = {success,informational,warning,error} */
|
||||
#define kNtStatusSuccess 0x00000000u /* success statuses */
|
||||
#define kNtStatusWait0 0x00000000u
|
||||
#define kNtStatusAbandonedWait0 0x00000080u
|
||||
#define kNtStatusUserApc 0x000000C0u
|
||||
#define kNtStatusTimeout 0x00000102u
|
||||
#define kNtStatusPending 0x00000103u
|
||||
#define kNtStatusGuardPageViolation 0x80000001u /* warning statuses */
|
||||
#define kNtStatusDatatypeMisalignment 0x80000002u
|
||||
#define kNtStatusBreakpoint 0x80000003u
|
||||
#define kNtStatusSingleStep 0x80000004u
|
||||
#define kNtStatusLongjump 0x80000026u
|
||||
#define kNtStatusUnwindConsolidate 0x80000029u
|
||||
#define kNtStatusAccessViolation 0xC0000005u /* error statuses */
|
||||
#define kNtStatusInPageError 0xC0000006u
|
||||
#define kNtStatusInvalidHandle 0xC0000008u
|
||||
#define kNtStatusInvalidParameter 0xC000000Du
|
||||
#define kNtStatusNoMemory 0xC0000017u
|
||||
#define kNtStatusIllegalInstruction 0xC000001Du
|
||||
#define kNtStatusNoncontinuableException 0xC0000025u
|
||||
#define kNtStatusInvalidDisposition 0xC0000026u
|
||||
#define kNtStatusArrayBoundsExceeded 0xC000008Cu
|
||||
#define kNtStatusFloatDenormalOperand 0xC000008Du
|
||||
#define kNtStatusFloatDivideByZero 0xC000008Eu
|
||||
#define kNtStatusFloatInexactResult 0xC000008Fu
|
||||
#define kNtStatusFloatInvalidOperation 0xC0000090u
|
||||
#define kNtStatusFloatOverflow 0xC0000091u
|
||||
#define kNtStatusFloatStackCheck 0xC0000092u
|
||||
#define kNtStatusFloatUnderflow 0xC0000093u
|
||||
#define kNtStatusIntegerDivideBYZero 0xC0000094u
|
||||
#define kNtStatusIntegerOverflow 0xC0000095u
|
||||
#define kNtStatusPrivilegedInstruction 0xC0000096u
|
||||
#define kNtStatusStackOverflow 0xC00000FDu
|
||||
#define kNtStatusDllNotFound 0xC0000135u
|
||||
#define kNtStatusOrdinalNotFound 0xC0000138u
|
||||
#define kNtStatusEntrypointNotFound 0xC0000139u
|
||||
#define kNtStatusControlCExit 0xC000013Au
|
||||
#define kNtStatusDllInitFailed 0xC0000142u
|
||||
#define kNtStatusFloatMultipleFaults 0xC00002B4u
|
||||
#define kNtStatusFloatMultipleTraps 0xC00002B5u
|
||||
#define kNtStatusRegNatConsumption 0xC00002C9u
|
||||
#define kNtStatusHeapCorruption 0xC0000374u
|
||||
#define kNtStatusStackBufferOverrun 0xC0000409u
|
||||
#define kNtStatusInvalidCruntimeParameter 0xC0000417u
|
||||
#define kNtStatusAssertionFailure 0xC0000420u
|
||||
#define kNtStatusEnclaveViolation 0xC00004A2u
|
||||
#define kNtStatusSegmentNotification 0x40000005u
|
||||
#define kNtStatusFatalAppExit 0x40000015u
|
||||
#define kNtStatusNotFound 0xC0000225u
|
||||
#define kNtStatusCancelled 0xC0000120u
|
||||
#define kNtStatusSuccess 0x00000000 /* success statuses */
|
||||
#define kNtStatusWait0 0x00000000
|
||||
#define kNtStatusAbandonedWait0 0x00000080
|
||||
#define kNtStatusUserApc 0x000000C0
|
||||
#define kNtStatusTimeout 0x00000102
|
||||
#define kNtStatusPending 0x00000103
|
||||
#define kNtStatusGuardPageViolation 0x80000001 /* warning statuses */
|
||||
#define kNtStatusDatatypeMisalignment 0x80000002
|
||||
#define kNtStatusBreakpoint 0x80000003
|
||||
#define kNtStatusSingleStep 0x80000004
|
||||
#define kNtStatusLongjump 0x80000026
|
||||
#define kNtStatusUnwindConsolidate 0x80000029
|
||||
#define kNtStatusAccessViolation 0xC0000005 /* error statuses */
|
||||
#define kNtStatusInPageError 0xC0000006
|
||||
#define kNtStatusInvalidHandle 0xC0000008
|
||||
#define kNtStatusInvalidParameter 0xC000000D
|
||||
#define kNtStatusNoMemory 0xC0000017
|
||||
#define kNtStatusIllegalInstruction 0xC000001D
|
||||
#define kNtStatusNoncontinuableException 0xC0000025
|
||||
#define kNtStatusInvalidDisposition 0xC0000026
|
||||
#define kNtStatusArrayBoundsExceeded 0xC000008C
|
||||
#define kNtStatusFloatDenormalOperand 0xC000008D
|
||||
#define kNtStatusFloatDivideByZero 0xC000008E
|
||||
#define kNtStatusFloatInexactResult 0xC000008F
|
||||
#define kNtStatusFloatInvalidOperation 0xC0000090
|
||||
#define kNtStatusFloatOverflow 0xC0000091
|
||||
#define kNtStatusFloatStackCheck 0xC0000092
|
||||
#define kNtStatusFloatUnderflow 0xC0000093
|
||||
#define kNtStatusIntegerDivideBYZero 0xC0000094
|
||||
#define kNtStatusIntegerOverflow 0xC0000095
|
||||
#define kNtStatusPrivilegedInstruction 0xC0000096
|
||||
#define kNtStatusStackOverflow 0xC00000FD
|
||||
#define kNtStatusDllNotFound 0xC0000135
|
||||
#define kNtStatusOrdinalNotFound 0xC0000138
|
||||
#define kNtStatusEntrypointNotFound 0xC0000139
|
||||
#define kNtStatusControlCExit 0xC000013A
|
||||
#define kNtStatusDllInitFailed 0xC0000142
|
||||
#define kNtStatusFloatMultipleFaults 0xC00002B4
|
||||
#define kNtStatusFloatMultipleTraps 0xC00002B5
|
||||
#define kNtStatusRegNatConsumption 0xC00002C9
|
||||
#define kNtStatusHeapCorruption 0xC0000374
|
||||
#define kNtStatusStackBufferOverrun 0xC0000409
|
||||
#define kNtStatusInvalidCruntimeParameter 0xC0000417
|
||||
#define kNtStatusAssertionFailure 0xC0000420
|
||||
#define kNtStatusEnclaveViolation 0xC00004A2
|
||||
#define kNtStatusSegmentNotification 0x40000005
|
||||
#define kNtStatusFatalAppExit 0x40000015
|
||||
#define kNtStatusNotFound 0xC0000225
|
||||
#define kNtStatusCancelled 0xC0000120
|
||||
|
||||
#define kNtDbgExceptionHandled 0x00010001u
|
||||
#define kNtDbgContinue 0x00010002u
|
||||
#define kNtDbgReplyLater 0x40010001u
|
||||
#define kNtDbgTerminateThread 0x40010003u
|
||||
#define kNtDbgTerminateProcess 0x40010004u
|
||||
#define kNtDbgControlC 0x40010005u
|
||||
#define kNtDbgPrintexceptionC 0x40010006u
|
||||
#define kNtDbgRipexception 0x40010007u
|
||||
#define kNtDbgControlBreak 0x40010008u
|
||||
#define kNtDbgCommandException 0x40010009u
|
||||
#define kNtDbgPrintexceptionWideC 0x4001000Au
|
||||
#define kNtDbgExceptionNotHandled 0x80010001u
|
||||
#define kNtDbgExceptionHandled 0x00010001
|
||||
#define kNtDbgContinue 0x00010002
|
||||
#define kNtDbgReplyLater 0x40010001
|
||||
#define kNtDbgTerminateThread 0x40010003
|
||||
#define kNtDbgTerminateProcess 0x40010004
|
||||
#define kNtDbgControlC 0x40010005
|
||||
#define kNtDbgPrintexceptionC 0x40010006
|
||||
#define kNtDbgRipexception 0x40010007
|
||||
#define kNtDbgControlBreak 0x40010008
|
||||
#define kNtDbgCommandException 0x40010009
|
||||
#define kNtDbgPrintexceptionWideC 0x4001000A
|
||||
#define kNtDbgExceptionNotHandled 0x80010001
|
||||
#define kNtStillActive kNtStatusPending
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
|
12
libc/nt/kernel32/GetProcessImageFileNameA.s
Normal file
12
libc/nt/kernel32/GetProcessImageFileNameA.s
Normal file
|
@ -0,0 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_GetProcessImageFileNameA,GetProcessImageFileNameA,676
|
||||
|
||||
.text.windows
|
||||
GetProcessImageFileNameA:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_GetProcessImageFileNameA(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn GetProcessImageFileNameA,globl
|
||||
.previous
|
12
libc/nt/kernel32/GetProcessImageFileNameW.s
Normal file
12
libc/nt/kernel32/GetProcessImageFileNameW.s
Normal file
|
@ -0,0 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_GetProcessImageFileNameW,GetProcessImageFileNameW,677
|
||||
|
||||
.text.windows
|
||||
GetProcessImageFileName:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_GetProcessImageFileNameW(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn GetProcessImageFileName,globl
|
||||
.previous
|
|
@ -2478,8 +2478,8 @@ imp 'GetProcessHeap' GetProcessHeap kernel32 0 # KernelBase
|
|||
imp 'GetProcessHeaps' GetProcessHeaps kernel32 0 # KernelBase
|
||||
imp 'GetProcessId' GetProcessId kernel32 0 1 # KernelBase
|
||||
imp 'GetProcessIdOfThread' GetProcessIdOfThread kernel32 0 1 # KernelBase
|
||||
imp 'GetProcessImageFileNameA' GetProcessImageFileNameA KernelBase 676
|
||||
imp 'GetProcessImageFileName' GetProcessImageFileNameW KernelBase 677
|
||||
imp 'GetProcessImageFileNameA' GetProcessImageFileNameA kernel32 676 3
|
||||
imp 'GetProcessImageFileName' GetProcessImageFileNameW kernel32 677 3
|
||||
imp 'GetProcessInformation' GetProcessInformation kernel32 0 4 # KernelBase
|
||||
imp 'GetProcessIoCounters' GetProcessIoCounters kernel32 701 2
|
||||
imp 'GetProcessMemoryInfo' GetProcessMemoryInfo KernelBase 679
|
||||
|
|
|
@ -296,6 +296,10 @@ $(LIBC_NT_SHELL32_A).pkg: \
|
|||
|
||||
$(LIBC_NT_OBJS): o/libc/nt/codegen.inc
|
||||
|
||||
o/libc/nt/codegen.inc: \
|
||||
ape/idata.internal.h \
|
||||
ape/macros.internal.h
|
||||
|
||||
.PHONY: o/$(MODE)/libc/nt
|
||||
o/$(MODE)/libc/nt: \
|
||||
$(LIBC_NT_LIBS) \
|
||||
|
|
|
@ -19,24 +19,24 @@
|
|||
#include "libc/nt/enum/status.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ @fileoverview NTDLL.DLL Non-Mandatory Importer
|
||||
/
|
||||
/ This module lets us import Microsoft's private APIs in a way
|
||||
/ that ensures executables won't fail to load in the future,
|
||||
/ should Microsoft ever choose to delete these APIs.
|
||||
// @fileoverview NTDLL.DLL Non-Mandatory Importer
|
||||
//
|
||||
// This module lets us import Microsoft's private APIs in a way
|
||||
// that ensures executables won't fail to load in the future,
|
||||
// should Microsoft ever choose to delete these APIs.
|
||||
|
||||
.initro 202,sys__init_ntdll.1
|
||||
.initro 202,_init_ntdll.1
|
||||
.type kNtdllProcRvas,@object
|
||||
kNtdllProcRvas:
|
||||
.previous/*
|
||||
...
|
||||
decentralized content
|
||||
...
|
||||
*/.initro 202,sys__init_ntdll.3
|
||||
*/.initro 202,_init_ntdll.3
|
||||
.quad 0
|
||||
.previous
|
||||
|
||||
.init.start 202,sys__init_ntdll
|
||||
.init.start 202,_init_ntdll
|
||||
push %r12
|
||||
push %r13
|
||||
lea ntdllmissingno(%rip),%r13
|
||||
|
@ -47,7 +47,8 @@ kNtdllProcRvas:
|
|||
0: lodsq
|
||||
test %rax,%rax
|
||||
jz 1f
|
||||
lea (%rbx,%rax),%rdx
|
||||
.weak _base
|
||||
lea _base(%rax),%rdx
|
||||
mov %r12,%rcx
|
||||
call *__imp_GetProcAddress(%rip)
|
||||
test %rax,%rax
|
||||
|
@ -57,7 +58,7 @@ kNtdllProcRvas:
|
|||
1: add $32,%rsp
|
||||
pop %r13
|
||||
pop %r12
|
||||
.init.end 202,sys__init_ntdll,globl,hidden
|
||||
.init.end 202,_init_ntdll,globl,hidden
|
||||
|
||||
.text.windows
|
||||
ntdllmissingno:
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/*-*- 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
|
||||
#include "ape/relocations.h"
|
||||
|
@ -6,13 +24,13 @@
|
|||
/* clang-format off */
|
||||
|
||||
.macro .ntimp fn:req
|
||||
yoink sys__init_ntdll
|
||||
.initbss 202,sys__init_ntdll.\fn
|
||||
yoink _init_ntdll
|
||||
.initbss 202,_init_ntdll.\fn
|
||||
__imp_\fn:
|
||||
.quad 0
|
||||
.endobj __imp_\fn,globl,hidden
|
||||
.previous
|
||||
.initro 202,sys__init_ntdll.2.\fn
|
||||
.initro 202,_init_ntdll.2.\fn
|
||||
.quad RVA(.L\fn)
|
||||
.previous
|
||||
.section .rodata.str1.1,"aSM",@progbits,1
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
.section .text.windows,"ax",@progbits
|
||||
|
||||
/ Epilogues for calling functions w/ Microsoft x64 convention.
|
||||
/
|
||||
/ @param %rax is address of windows x64 function to call
|
||||
/ @param %rsi is ignored
|
||||
/ @param %rdx,%rcx,%r8,%r9,stack are params (unlimited)
|
||||
/ @param %xmm0,%xmm1,%xmm2 are double params (limited to 3)
|
||||
/ @return is in %rax, %xmm0, or %st
|
||||
/ @note GCC 4.8+ and Clang can avoid this indirection
|
||||
/ @note thunk that jumps here must setup frame
|
||||
/ @note this is so much faster than __nt2sysv()
|
||||
// Epilogues for calling functions w/ Microsoft x64 convention.
|
||||
//
|
||||
// @param %rax is address of windows x64 function to call
|
||||
// @param %rsi is ignored
|
||||
// @param %rdx,%rcx,%r8,%r9,stack are params (unlimited)
|
||||
// @param %xmm0,%xmm1,%xmm2 are double params (limited to 3)
|
||||
// @return is in %rax, %xmm0, or %st
|
||||
// @note GCC 4.8+ and Clang can avoid this indirection
|
||||
// @note thunk that jumps here must setup frame
|
||||
// @note this is so much faster than __nt2sysv()
|
||||
__sysv2nt14:
|
||||
pushq 72(%rbp)
|
||||
pushq 64(%rbp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue