Fix MODE=aarch64 build

This commit is contained in:
Justine Tunney 2023-06-08 05:17:28 -07:00
parent 8767e9ad6a
commit 7512318a2a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
9 changed files with 96 additions and 80 deletions

BIN
build/bootstrap/chmod.com Executable file

Binary file not shown.

View file

@ -69,6 +69,7 @@ CP = build/bootstrap/cp.com
RM = build/bootstrap/rm.com -f
GZIP = build/bootstrap/gzip.com
ECHO = build/bootstrap/echo.com
CHMOD = build/bootstrap/chmod.com
TOUCH = build/bootstrap/touch.com
PKG = build/bootstrap/package.com
MKDEPS = build/bootstrap/mkdeps.com

View file

@ -24,6 +24,7 @@
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h"
#include "libc/intrin/likely.h"
#include "libc/log/libfatal.internal.h"
#include "libc/math.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
@ -41,7 +42,7 @@ privileged void __sigenter_wsl(int sig, struct siginfo *info, ucontext_t *ctx) {
ctx->uc_mcontext.fpregs = &ctx->__fpustate;
for (i = 0; i < 8; ++i) {
long double nan = NAN;
__builtin_memcpy(ctx->__fpustate.st + i, &nan, 16);
__memcpy(ctx->__fpustate.st + i, &nan, 16);
}
}
((sigaction_f)(__executable_start + rva))(sig, info, ctx);

View file

@ -453,7 +453,7 @@ static privileged void linuxthreadstate2xnu(
static privileged void CopyFpXmmRegs(void *d, const void *s) {
size_t i;
for (i = 0; i < (8 + 16) * 16; i += 16) {
__builtin_memcpy((char *)d + i, (const char *)s + i, 16);
__memcpy((char *)d + i, (const char *)s + i, 16);
}
}
@ -527,7 +527,8 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
}
#elif defined(__aarch64__)
if (xnuctx->uc_mcontext) {
memcpy(g.uc.uc_mcontext.regs, &xnuctx->uc_mcontext->__ss.__x, 33 * 8);
__memcpy(g.uc.uc_mcontext.regs, &xnuctx->uc_mcontext->__ss.__x,
33 * 8);
}
#endif /* __x86_64__ */
}
@ -561,7 +562,8 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
}
#elif defined(__aarch64__)
if (xnuctx->uc_mcontext) {
memcpy(&xnuctx->uc_mcontext->__ss.__x, g.uc.uc_mcontext.regs, 33 * 8);
__memcpy(&xnuctx->uc_mcontext->__ss.__x, g.uc.uc_mcontext.regs,
33 * 8);
}
#endif /* __x86_64__ */
}

View file

@ -11,13 +11,13 @@ COSMOPOLITAN_C_START_
#define __ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
forceinline int __strcmp(const char *l, const char *r) {
__funline int __strcmp(const char *l, const char *r) {
size_t i = 0;
while (l[i] == r[i] && r[i]) ++i;
return (l[i] & 255) - (r[i] & 255);
}
forceinline char *__stpcpy(char *d, const char *s) {
__funline char *__stpcpy(char *d, const char *s) {
size_t i;
for (i = 0;; ++i) {
if (!(d[i] = s[i])) {
@ -26,7 +26,7 @@ forceinline char *__stpcpy(char *d, const char *s) {
}
}
forceinline void *__repstosb(void *di, char al, size_t cx) {
__funline void *__repstosb(void *di, char al, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
asm("rep stosb"
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
@ -39,7 +39,7 @@ forceinline void *__repstosb(void *di, char al, size_t cx) {
#endif
}
forceinline void *__repmovsb(void *di, const void *si, size_t cx) {
__funline void *__repmovsb(void *di, const void *si, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
asm("rep movsb"
: "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di)
@ -53,7 +53,7 @@ forceinline void *__repmovsb(void *di, const void *si, size_t cx) {
#endif
}
forceinline void *__mempcpy(void *d, const void *s, size_t n) {
__funline void *__mempcpy(void *d, const void *s, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
((char *)d)[i] = ((const char *)s)[i];
@ -61,7 +61,7 @@ forceinline void *__mempcpy(void *d, const void *s, size_t n) {
return (char *)d + n;
}
forceinline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
__funline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
char t;
size_t i, a, b;
i = 0;
@ -80,22 +80,22 @@ forceinline char *__uintcpy(char p[hasatleast 21], uint64_t x) {
return p + i;
}
forceinline char *__intcpy(char p[hasatleast 21], int64_t x) {
__funline char *__intcpy(char p[hasatleast 21], int64_t x) {
if (x < 0) *p++ = '-', x = -(uint64_t)x;
return __uintcpy(p, x);
}
forceinline char *__fixcpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
__funline char *__fixcpy(char p[hasatleast 17], uint64_t x, uint8_t k) {
while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
*p = '\0';
return p;
}
forceinline char *__hexcpy(char p[hasatleast 17], uint64_t x) {
__funline char *__hexcpy(char p[hasatleast 17], uint64_t x) {
return __fixcpy(p, x, ROUNDUP(x ? (__builtin_clzll(x) ^ 63) + 1 : 1, 4));
}
forceinline const void *__memchr(const void *s, unsigned char c, size_t n) {
__funline const void *__memchr(const void *s, unsigned char c, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
if (((const unsigned char *)s)[i] == c) {
@ -105,7 +105,7 @@ forceinline const void *__memchr(const void *s, unsigned char c, size_t n) {
return 0;
}
forceinline char *__strstr(const char *haystack, const char *needle) {
__funline char *__strstr(const char *haystack, const char *needle) {
size_t i;
for (;;) {
for (i = 0;; ++i) {
@ -118,8 +118,8 @@ forceinline char *__strstr(const char *haystack, const char *needle) {
return 0;
}
forceinline char16_t *__strstr16(const char16_t *haystack,
const char16_t *needle) {
__funline char16_t *__strstr16(const char16_t *haystack,
const char16_t *needle) {
size_t i;
for (;;) {
for (i = 0;; ++i) {
@ -132,7 +132,7 @@ forceinline char16_t *__strstr16(const char16_t *haystack,
return 0;
}
forceinline char *__getenv(char **p, const char *s) {
__funline char *__getenv(char **p, const char *s) {
size_t i, j;
if (p) {
for (i = 0; p[i]; ++i) {
@ -152,7 +152,7 @@ forceinline char *__getenv(char **p, const char *s) {
return 0;
}
forceinline const char *__strchr(const char *s, unsigned char c) {
__funline const char *__strchr(const char *s, unsigned char c) {
char *r;
for (;; ++s) {
if ((*s & 255) == c) return s;
@ -160,14 +160,14 @@ forceinline const char *__strchr(const char *s, unsigned char c) {
}
}
forceinline unsigned long __atoul(const char *p) {
__funline unsigned long __atoul(const char *p) {
int c;
unsigned long x = 0;
while ('0' <= (c = *p++) && c <= '9') x *= 10, x += c - '0';
return x;
}
forceinline long __atol(const char *p) {
__funline long __atol(const char *p) {
int s = *p;
unsigned long x;
if (s == '-' || s == '+') ++p;
@ -176,6 +176,41 @@ forceinline long __atol(const char *p) {
return x;
}
__funline void *__memset(void *a, int c, unsigned long n) {
char *d = a;
unsigned long i;
for (i = 0; i < n; ++i) {
d[i] = c;
}
return d;
}
__funline void *__memcpy(void *a, const void *b, unsigned long n) {
char *d = a;
unsigned long i;
const char *s = b;
for (i = 0; i < n; ++i) {
d[i] = s[i];
}
return d;
}
__funline void *__memmove(void *a, const void *b, unsigned long n) {
char *d = a;
unsigned long i;
const char *s = b;
if (d > s) {
for (i = n; i--;) {
d[i] = s[i];
}
} else {
for (i = 0; i < n; ++i) {
d[i] = s[i];
}
}
return d;
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_LOG_LIBFATAL_INTERNAL_H_ */

View file

@ -5,3 +5,4 @@ o/third_party/qemu/qemu-aarch64: \
third_party/qemu/qemu-aarch64.gz
@$(MKDIR) $(@D)
@$(GZIP) $(ZFLAGS) -cd <$< >$@
@$(CHMOD) 0755 $@

View file

@ -20,6 +20,7 @@
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/log/libfatal.internal.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -1227,7 +1228,7 @@ privileged static void xed_decode_instruction_length(
*/
privileged struct XedDecodedInst *xed_decoded_inst_zero_set_mode(
struct XedDecodedInst *p, int mmode) {
__builtin_memset(p, 0, sizeof(*p));
__memset(p, 0, sizeof(*p));
xed_operands_set_mode(&p->op, mmode);
return p;
}
@ -1244,7 +1245,7 @@ privileged struct XedDecodedInst *xed_decoded_inst_zero_set_mode(
*/
privileged int xed_instruction_length_decode(struct XedDecodedInst *xedd,
const void *itext, size_t bytes) {
__builtin_memcpy(xedd->bytes, itext, MIN(15, bytes));
__memcpy(xedd->bytes, itext, MIN(15, bytes));
xedd->op.max_bytes = MIN(15, bytes);
xed_decode_instruction_length(xedd);
if (!xedd->op.out_of_bytes) {

View file

@ -17,14 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/getopt/getopt.h"
#define USAGE \
@ -42,78 +38,58 @@ FLAGS\n\
const char *prog;
wontreturn void PrintUsage(int rc, FILE *f) {
fputs("usage: ", f);
fputs(prog, f);
fputs(USAGE, f);
static void Print(int fd, const char *s, ...) {
va_list va;
char buf[2048];
va_start(va, s);
buf[0] = 0;
do {
strlcat(buf, s, sizeof(buf));
} while ((s = va_arg(va, const char *)));
write(fd, buf, strlen(buf));
va_end(va);
}
static wontreturn void SysExit(const char *path, const char *func) {
const char *errstr;
if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN";
Print(2, path, ": ", func, " failed with ", errstr, "\n", NULL);
exit(1);
}
static wontreturn void PrintUsage(int fd, int rc) {
Print(fd, "USAGE\n\n ", program_invocation_name, USAGE, NULL);
exit(rc);
}
void GetOpts(int argc, char *argv[]) {
static void GetOpts(int argc, char *argv[]) {
int opt;
while ((opt = getopt(argc, argv, "?h")) != -1) {
switch (opt) {
case 'h':
case '?':
PrintUsage(EXIT_SUCCESS, stdout);
PrintUsage(1, 0);
default:
PrintUsage(EX_USAGE, stderr);
PrintUsage(2, 1);
}
}
}
int main(int argc, char *argv[]) {
int i, mode;
char buf[PATH_MAX];
{
printf("curdir %s\n", getcwd(buf, sizeof(buf)));
printf("tmp:");
struct dirent *e;
DIR *d;
if ((d = opendir("tmp"))) {
while ((e = readdir(d))) {
printf(" %s", e->d_name);
}
closedir(d);
} else {
printf(" dir not found");
}
printf("\n");
}
{
printf("curdir %s\n", getcwd(buf, sizeof(buf)));
printf("bin:");
struct dirent *e;
DIR *d;
if ((d = opendir("bin"))) {
while ((e = readdir(d))) {
printf(" %s", e->d_name);
}
closedir(d);
} else {
printf(" dir not found");
}
printf("\n");
}
prog = argc > 0 ? argv[0] : "mv.com";
char buf[PATH_MAX], *endptr;
GetOpts(argc, argv);
if (argc - optind < 2) {
PrintUsage(EX_USAGE, stderr);
PrintUsage(2, 1);
}
mode = strtol(argv[optind], &endptr, 8) & 07777;
if (*endptr) {
Print(2, "chmod: invalid mode octal\n", NULL);
exit(1);
}
mode = strtol(argv[optind], 0, 8) & 07777;
for (i = optind + 1; i < argc; ++i) {
if (chmod(argv[i], mode) == -1) {
const char *s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": ", stderr);
fputs(argv[i], stderr);
fputs(": ", stderr);
fputs(s, stderr);
fputs("\n", stderr);
exit(1);
SysExit(argv[i], "chmod");
}
}
return 0;

View file

@ -86,7 +86,6 @@ void Print(int fd, const char *s, ...) {
do {
strlcat(buf, s, sizeof(buf));
} while ((s = va_arg(va, const char *)));
strlcat(buf, "\n", sizeof(buf));
write(fd, buf, strlen(buf));
va_end(va);
}