Improve cosmocc toolchain

- Decouple zlib from libc
- Add some underscores to mostly internal names
This commit is contained in:
Justine Tunney 2023-03-05 23:52:17 -08:00
parent 713d4424c6
commit ba180e754d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
25 changed files with 128 additions and 42 deletions

4
libc/isystem/sys/vfs.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_
#include "libc/calls/struct/statfs.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_ */

View file

@ -1,4 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_
#include "third_party/zlib/zlib.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_ */

View file

@ -26,12 +26,12 @@
/**
* Returns maximum number of open files.
*/
long GetMaxFd(void) {
long _GetMaxFd(void) {
int rc;
if (IsNetbsd()) {
if ((rc = __sys_fcntl(0, F_MAXFD, 0)) != -1) {
return rc;
}
}
return GetResourceLimit(RLIMIT_NOFILE);
return _GetResourceLimit(RLIMIT_NOFILE);
}

View file

@ -21,7 +21,7 @@
#include "libc/macros.internal.h"
#include "libc/sysv/consts/rlim.h"
long GetResourceLimit(int resource) {
long _GetResourceLimit(int resource) {
struct rlimit rl;
getrlimit(resource, &rl);
if (rl.rlim_cur == RLIM_INFINITY) return -1;

View file

@ -30,7 +30,7 @@
#include "libc/x/x.h"
#include "libc/zip.h"
#include "libc/zipos/zipos.internal.h"
#include "third_party/zlib/puff.h"
#include "third_party/puff/puff.h"
static pthread_spinlock_t g_lock;
_Hide struct SymbolTable *__symtab; // for kprintf

View file

@ -20,7 +20,7 @@
#include "libc/intrin/weaken.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "third_party/zlib/puff.h"
#include "third_party/puff/puff.h"
#include "third_party/zlib/zlib.h"
/**
@ -54,7 +54,7 @@ int __inflate(void *out, size_t outsize, const void *in, size_t insize) {
rc = rc;
}
} else {
rc = puff(out, &outsize, in, &insize);
rc = _puff(out, &outsize, in, &insize);
}
STRACE("inflate([%#.*hhs%s], %'zu, %#.*hhs%s, %'zu) → %d", MIN(40, outsize),
out, outsize > 40 ? "..." : "", outsize, MIN(40, insize), in,

View file

@ -44,9 +44,9 @@ int GetDosEnviron(const char16_t *, char *, size_t, char **, size_t);
bool __intercept_flag(int *, char *[], const char *);
int sys_mprotect_nt(void *, size_t, int) _Hide;
int __inflate(void *, size_t, const void *, size_t);
noasan void *Mmap(void *addr, size_t size, int prot, int flags, int fd,
int64_t off) _Hide;
noasan int Munmap(char *, size_t) _Hide;
noasan void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
int64_t off) _Hide;
noasan int _Munmap(char *, size_t) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -33,7 +33,7 @@
/**
* Returns true if ELF executable uses dynamic loading magic.
*/
bool IsDynamicExecutable(const char *prog) {
bool _IsDynamicExecutable(const char *prog) {
bool res;
Elf64_Ehdr *e;
Elf64_Phdr *p;

View file

@ -238,8 +238,8 @@ static textwindows dontinline noasan void *MapMemories(char *addr, size_t size,
return addr;
}
noasan inline void *Mmap(void *addr, size_t size, int prot, int flags, int fd,
int64_t off) {
noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
int64_t off) {
char *p = addr;
struct DirectMap dm;
int a, b, i, f, m, n, x;
@ -494,7 +494,7 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
#endif
__mmi_lock();
if (!__isfdkind(fd, kFdZip)) {
res = Mmap(addr, size, prot, flags, fd, off);
res = _Mmap(addr, size, prot, flags, fd, off);
} else {
res = _weaken(__zipos_Mmap)(
addr, size, prot, flags,

View file

@ -53,7 +53,7 @@ static noasan void MunmapShadow(char *p, size_t n) {
// to be >1mb since we can only unmap it if it's aligned, and
// as such we poison the edges if there are any.
__repstosb((void *)a, kAsanUnmapped, x - a);
Munmap((void *)x, y - x);
_Munmap((void *)x, y - x);
__repstosb((void *)y, kAsanUnmapped, b - y);
} else {
// otherwise just poison and assume reuse
@ -113,7 +113,7 @@ static noasan void MunmapImpl(char *p, size_t n) {
}
}
noasan int Munmap(char *p, size_t n) {
noasan int _Munmap(char *p, size_t n) {
unsigned i;
char poison;
intptr_t a, b, x, y;
@ -157,7 +157,7 @@ int munmap(void *p, size_t n) {
int rc;
size_t toto;
__mmi_lock();
rc = Munmap(p, n);
rc = _Munmap(p, n);
#if SYSDEBUG
toto = __strace > 0 ? GetMemtrackSize(&_mmi) : 0;
#endif

View file

@ -30,7 +30,7 @@
// @return file descriptor
// @note only works on .com binary (not .com.dbg)
// @note only supports linux, freebsd, openbsd, and netbsd
OpenExecutable:
_OpenExecutable:
push %rbp
mov %rsp,%rbp
pushq __NR_open(%rip) # -0x08(%rbp)
@ -198,7 +198,7 @@ OpenExecutable:
pop %rbx
leave
ret
9: .endfn OpenExecutable,globl
9: .endfn _OpenExecutable,globl
.weak ape_rom_vaddr
.weak ape_rom_filesz

View file

@ -94,12 +94,12 @@ void _peekall(void);
void _savexmm(void *);
void _weakfree(void *);
void free_s(void *) paramsnonnull() libcesque;
int OpenExecutable(void);
int _OpenExecutable(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
long GetResourceLimit(int);
long GetMaxFd(void);
long _GetResourceLimit(int);
long _GetMaxFd(void);
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
void __printargs(const char *);
@ -108,7 +108,7 @@ int __arg_max(void);
void __print_maps(void);
void __warn_if_powersave(void);
const char *__describe_os(void);
bool IsDynamicExecutable(const char *);
bool _IsDynamicExecutable(const char *);
void _restorewintty(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);

View file

@ -45,7 +45,7 @@ LIBC_RUNTIME_A_DIRECTDEPS = \
LIBC_STUBS \
LIBC_SYSV \
LIBC_SYSV_CALLS \
THIRD_PARTY_ZLIB \
THIRD_PARTY_PUFF \
THIRD_PARTY_XED
LIBC_RUNTIME_A_DEPS := \

View file

@ -41,11 +41,11 @@ long sysconf(int name) {
case _SC_ARG_MAX:
return _ARG_MAX;
case _SC_CHILD_MAX:
return GetResourceLimit(RLIMIT_NPROC);
return _GetResourceLimit(RLIMIT_NPROC);
case _SC_CLK_TCK:
return CLK_TCK;
case _SC_OPEN_MAX:
return GetMaxFd();
return _GetMaxFd();
case _SC_PAGESIZE:
return FRAMESIZE;
case _SC_NPROCESSORS_ONLN:

View file

@ -64,7 +64,7 @@ noasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags,
const int tempProt = !IsXnu() ? prot | PROT_WRITE : PROT_WRITE;
void *outAddr =
Mmap(addr, size, tempProt, (flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0);
_Mmap(addr, size, tempProt, (flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0);
if (outAddr == MAP_FAILED) {
return MAP_FAILED;
}
@ -82,7 +82,7 @@ noasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags,
return outAddr;
} while (0);
const int e = errno;
Munmap(outAddr, size);
_Munmap(outAddr, size);
errno = e;
strace_enabled(+1);
return MAP_FAILED;

View file

@ -40,7 +40,7 @@ LIBC_ZIPOS_A_DIRECTDEPS = \
LIBC_STUBS \
LIBC_SYSV_CALLS \
LIBC_NT_KERNEL32 \
THIRD_PARTY_ZLIB
THIRD_PARTY_PUFF
LIBC_ZIPOS_A_DEPS := \
$(call uniq,$(foreach zipos,$(LIBC_ZIPOS_A_DIRECTDEPS),$($(zipos))))