Remove IMAGE_BASE_VIRTUAL

This commit is contained in:
Justine Tunney 2023-09-12 01:21:36 -07:00
parent 8a0008d985
commit 20c77338e6
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
65 changed files with 10 additions and 286 deletions

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
@ -21,22 +20,6 @@ void __sig_lock(void);
void __sig_unlock(void);
void __sig_funlock(void);
#ifdef _NOPL0
#define __fds_lock() _NOPL0("__threadcalls", __fds_lock)
#define __fds_unlock() _NOPL0("__threadcalls", __fds_unlock)
#else
#define __fds_lock() (__threaded ? __fds_lock() : 0)
#define __fds_unlock() (__threaded ? __fds_unlock() : 0)
#endif
#ifdef _NOPL0
#define __sig_lock() _NOPL0("__threadcalls", __sig_lock)
#define __sig_unlock() _NOPL0("__threadcalls", __sig_unlock)
#else
#define __sig_lock() (__threaded ? __sig_lock() : 0)
#define __sig_unlock() (__threaded ? __sig_unlock() : 0)
#endif
#define __vforked (__tls_enabled && (__get_tls()->tib_flags & TIB_FLAG_VFORKED))
COSMOPOLITAN_C_END_

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
#define COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/tls.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
@ -24,14 +23,6 @@ void __cxa_lock(void);
void __cxa_unlock(void);
void __cxa_printexits(FILE *, void *);
#ifdef _NOPL0
#define __cxa_lock() _NOPL0("__threadcalls", __cxa_lock)
#define __cxa_unlock() _NOPL0("__threadcalls", __cxa_unlock)
#else
#define __cxa_lock() (__threaded ? __cxa_lock() : 0)
#define __cxa_unlock() (__threaded ? __cxa_unlock() : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_CXAATEXIT_H_ */

View file

@ -1,77 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__x86_64__) && \
defined(__GNUC__) && !defined(__llvm__) && !defined(__chibicc__) && \
defined(__MNO_RED_ZONE__) && !defined(__STRICT_ANSI__)
/**
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.
*
* Things like lock/unlock function calls can take on average 100ms.
* Libc needs to use internal locking pervasively in order to support
* threads. So there's a lot of cost everywhere, even though most progs
* don't use threads. In ANSI mode we dispatching (__threaded && lock())
* to solve this problem, but if we write lock statements that way, it
* adds a lot of bloat to the functions that call locking routines. So
* what we do here is replace the CALL instruction with NOP, which keeps
* the code just as fast as inlining, while making code size 10x tinier.
*/
#define _NOPL_PROLOGUE(SECTION) \
".section \".sort.rodata." SECTION ".1" \
"\",\"aG\",@progbits,\"" SECTION "\",comdat\n\t" \
".balign\t4\n\t" \
".type\t\"" SECTION "_start\",@object\n\t" \
".globl\t\"" SECTION "_start\"\n\t" \
".equ\t\"" SECTION "_start\",.\n\t" \
".previous\n\t"
#define _NOPL_EPILOGUE(SECTION) \
".section \".sort.rodata." SECTION ".3" \
"\",\"aG\",@progbits,\"" SECTION "\",comdat\n\t" \
".balign\t4\n\t" \
".type\"" SECTION "_end\",@object\n\t" \
".globl\t\"" SECTION "_end\"\n\t" \
".equ\t\"" SECTION "_end\",.\n\t" \
".previous\n\t"
#define _NOPL0(SECTION, FUNC) __NOPL0(SECTION, FUNC, IMAGE_BASE_VIRTUAL)
#define __NOPL0(SECTION, FUNC, GARDEN) ___NOPL0(SECTION, FUNC, GARDEN)
#define ___NOPL0(SECTION, FUNC, GARDEN) \
({ \
asm volatile(_NOPL_PROLOGUE(SECTION) /* */ \
_NOPL_EPILOGUE(SECTION) /* */ \
".section \".sort.rodata." SECTION ".2\",\"a\",@progbits\n\t" \
".balign\t4\n\t" \
".long\t353f-" #GARDEN "\n\t" \
".previous\n353:\t" \
"nopl\t" #FUNC "(%%rip)" \
: /* no inputs */ \
: /* no outputs */ \
: "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", \
"r11", "memory", "cc"); \
(void)0; \
})
#define _NOPL1(SECTION, FUNC, ARG) \
__NOPL1(SECTION, FUNC, ARG, IMAGE_BASE_VIRTUAL)
#define __NOPL1(SECTION, FUNC, ARG, GARDEN) ___NOPL1(SECTION, FUNC, ARG, GARDEN)
#define ___NOPL1(SECTION, FUNC, ARG, GARDEN) \
({ \
register autotype(ARG) __arg asm("rdi") = ARG; \
asm volatile(_NOPL_PROLOGUE(SECTION) /* */ \
_NOPL_EPILOGUE(SECTION) /* */ \
".section \".sort.rodata." SECTION ".2\",\"a\",@progbits\n\t" \
".balign\t4\n\t" \
".long\t353f-" #GARDEN "\n\t" \
".previous\n353:\t" \
"nopl\t" #FUNC "(%%rip)" \
: "+D"(__arg) \
: /* no inputs */ \
: "rax", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11", \
"memory", "cc"); \
(void)0; \
})
#endif /* !ASSEMBLER && !LINKER && GNUC && !CHIBICC && !LLVM && !ANSI */
#endif /* COSMOPOLITAN_LIBC_INTRIN_NOPL_H_ */

View file

@ -35,7 +35,6 @@
#include "libc/runtime/runtime.h"
#include "libc/stdio/dprintf.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"

View file

@ -445,35 +445,6 @@
#endif
.endm
// 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
.p2align 4
#endif
.endm
// 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
#else
mov $\symbol,\reg32
#endif
.endm
// 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
#else
push $\symbol
#endif
.endm
// TODO(jart): delete
// Loads Effective Address
// Supporting security blankets
@ -486,32 +457,6 @@
#endif
.endm
.macro farcall symbol:req
.type \symbol,@function
#if __PIC__ + __PIE__ + __code_model_medium__ + __code_model_large__ + 0 > 1
call *\symbol\()@gotpcrel(%rip)
#else
call \symbol\()@plt
#endif
.endm
// Pushes RVA on stack of linktime mergeable string literal.
// @see popstr
.macro pushstr text
.section .rodata.str1.1,"aSM",@progbits,1
.Lstr\@: .asciz "\text"
.endobj .Lstr\@
.previous
push $.Lstr\@ - IMAGE_BASE_VIRTUAL
.endm
// 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.
.macro loadstr text:req reg:req regsz bias=0
.section .rodata.str1.1,"aSM",@progbits,1

View file

@ -21,7 +21,6 @@
#include "libc/fmt/itoa.h"
#include "libc/intrin/cmpxchg.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nopl.internal.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/stackframe.h"
#include "libc/runtime/internal.h"

View file

@ -2,7 +2,6 @@
#define COSMOPOLITAN_LIBC_RUNTIME_MEMTRACK_H_
#include "ape/sections.internal.h"
#include "libc/dce.h"
#include "libc/intrin/nopl.internal.h"
#include "libc/macros.internal.h"
#include "libc/nt/version.h"
#include "libc/runtime/runtime.h"
@ -61,14 +60,6 @@ void __release_memory_nt(struct MemoryIntervals *, int, int);
int __untrack_memories(void *, size_t);
size_t __get_memtrack_size(struct MemoryIntervals *);
#ifdef _NOPL0
#define __mmi_lock() _NOPL0("__threadcalls", __mmi_lock)
#define __mmi_unlock() _NOPL0("__threadcalls", __mmi_unlock)
#else
#define __mmi_lock() (__threaded ? __mmi_lock() : 0)
#define __mmi_unlock() (__threaded ? __mmi_unlock() : 0)
#endif
#ifdef __x86_64__
/*
* AMD64 has 48-bit signed pointers (PML4T)

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_STDIO_FFLUSH_H_
#define COSMOPOLITAN_LIBC_STDIO_FFLUSH_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
@ -23,14 +22,6 @@ extern pthread_mutex_t __fflush_lock_obj;
void __fflush_lock(void);
void __fflush_unlock(void);
#ifdef _NOPL0
#define __fflush_lock() _NOPL0("__threadcalls", __fflush_lock)
#define __fflush_unlock() _NOPL0("__threadcalls", __fflush_unlock)
#else
#define __fflush_lock() (__threaded ? __fflush_lock() : 0)
#define __fflush_unlock() (__threaded ? __fflush_unlock() : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STDIO_FFLUSH_H_ */

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/errfuns.h"

View file

@ -17,13 +17,12 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"
/**
* Acquires reentrant lock on stdio object, blocking if needed.
*/
void(flockfile)(FILE *f) {
void flockfile(FILE *f) {
pthread_mutex_lock(&f->lock);
}

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h"
#include "libc/stdio/fflush.internal.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/stdio_ext.h"

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -19,7 +19,6 @@
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -18,7 +18,6 @@
*/
#include "libc/calls/calls.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -18,7 +18,6 @@
*/
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -20,7 +20,6 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"

View file

@ -17,13 +17,12 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"
/**
* Releases lock on stdio object.
*/
void(funlockfile)(FILE *f) {
void funlockfile(FILE *f) {
pthread_mutex_unlock(&f->lock);
}

View file

@ -18,7 +18,6 @@
*/
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -1,21 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_STDIO_LOCK_H_
#define COSMOPOLITAN_LIBC_STDIO_LOCK_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/tls.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef _NOPL1
#define flockfile(f) _NOPL1("__threadcalls", flockfile, f)
#define funlockfile(f) _NOPL1("__threadcalls", funlockfile, f)
#define ftrylockfile(f) _NOPL1("__threadcalls", ftrylockfile, f)
#else
#define flockfile(f) (__threaded ? flockfile(f) : 0)
#define funlockfile(f) (__threaded ? funlockfile(f) : 0)
#define ftrylockfile(f) (__threaded ? ftrylockfile(f) : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STDIO_LOCK_H_ */

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,6 @@
*/
#include "libc/calls/calls.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -18,7 +18,6 @@
*/
#include "libc/calls/struct/fd.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -20,7 +20,6 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/errfuns.h"

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -23,7 +23,6 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/nopl.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/limits.h"
#include "libc/mem/mem.h"
@ -71,11 +70,6 @@ static void sem_open_init(void) {
pthread_once(&g_semaphores.once, sem_open_setup);
}
#ifdef _NOPL0
#define sem_open_lock() _NOPL0("__threadcalls", sem_open_lock)
#define sem_open_unlock() _NOPL0("__threadcalls", sem_open_unlock)
#endif
static sem_t *sem_open_impl(const char *path, int oflag, unsigned mode,
unsigned value) {
int fd;

View file

@ -5,7 +5,6 @@
#include "libc/calls/blockcancel.internal.h"
#include "libc/calls/calls.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/nopl.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
@ -67,11 +66,6 @@ __attribute__((__constructor__)) static void localtime_init(void) {
localtime_funlock);
}
#ifdef _NOPL0
#define localtime_lock() _NOPL0("__threadcalls", localtime_lock)
#define localtime_unlock() _NOPL0("__threadcalls", localtime_unlock)
#endif
#ifndef TZ_ABBR_MAX_LEN
#define TZ_ABBR_MAX_LEN 16
#endif /* !defined TZ_ABBR_MAX_LEN */