Fix Clang support

The amalgamated release is now confirmed to be working with Clang,
including its integrated assembler.

Fixes #41
This commit is contained in:
Justine Tunney 2021-02-06 00:24:35 -08:00
parent e06c90fafc
commit d7733579d3
103 changed files with 384 additions and 359 deletions

View file

@ -30,7 +30,7 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
void djbsort$avx2(int32_t *, long);
void djbsort_avx2(int32_t *, long);
size_t n;
int32_t *a, *b, *c;
@ -42,7 +42,7 @@ TEST(djbsort, test4) {
b = memcpy(gc(malloc(n * 4)), kA, n * 4);
c = memcpy(gc(malloc(n * 4)), kA, n * 4);
insertionsort(a, n);
djbsort$avx2(b, n);
djbsort_avx2(b, n);
djbsort(c, n);
ASSERT_EQ(0, memcmp(a, b, n * 4));
ASSERT_EQ(0, memcmp(a, c, n * 4));
@ -72,7 +72,7 @@ TEST(djbsort, test64) {
djbsort(c, n);
ASSERT_EQ(0, memcmp(a, c, n * 4));
if (X86_HAVE(AVX2)) {
djbsort$avx2(b, n);
djbsort_avx2(b, n);
ASSERT_EQ(0, memcmp(a, b, n * 4));
}
}

View file

@ -37,7 +37,7 @@ TEST(crc32, testBigText) {
EXPECT_EQ(0xc7adc04f, crc32(0, hyperion, size));
EXPECT_EQ(0xc7adc04f, crc32_z(0, hyperion, size));
EXPECT_EQ(0xc7adc04f,
0xffffffffu ^ crc32$pclmul(0 ^ 0xffffffffu, hyperion, size));
0xffffffffu ^ crc32_pclmul(0 ^ 0xffffffffu, hyperion, size));
}
}

View file

@ -68,7 +68,7 @@ TEST(memmove$pure, overlapping) {
b0 = rngset(malloc(N), N, rand64, -1);
b1 = memcpy(malloc(N), b0, N);
b2 = memcpy(malloc(N), b0, N);
ASSERT_EQ(b1 + j, memmove$pure(b1 + j, b1 + i, n));
ASSERT_EQ(b1 + j, memmove_pure(b1 + j, b1 + i, n));
ASSERT_EQ(b2 + j, PosixMemmove(b2 + j, b2 + i, n));
ASSERT_EQ(0, memcmp(b1, b2, N),
"j=%ld i=%ld n=%ld\n"

View file

@ -1,8 +1,8 @@
int main() {
int main(int argc, char *argv[]) {
int rc;
FILE *f;
f = fopen("/dev/null", "w");
fprintf(f, "hello world\n");
fprintf(f, "hello world %d\n", argc);
fclose(f);
rc = system("exit 42");
CHECK_NE(-1, rc);

View file

@ -93,6 +93,31 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
o/$(MODE)/test/libc/release/smokeclang.com.dbg: \
test/libc/release/smoke.c \
o/cosmopolitan.h \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@ACTION=CLANG build/compile clang \
-o $@ \
-Os \
-static \
-no-pie \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
.PHONY: o/$(MODE)/test/libc/release
o/$(MODE)/test/libc/release: \
o/$(MODE)/test/libc/release/smoke.com \

View file

@ -40,12 +40,12 @@ TEST(crc32c, test) {
strlen(hyperion) - strlen(FANATICS)));
}
FIXTURE(crc32c, pure) {
*(void **)(&crc32c) = (void *)crc32c$pure;
FIXTURE(crc32c, pure_) {
*(void **)(&crc32c) = (void *)crc32c_pure;
}
FIXTURE(crc32c, sse42) {
FIXTURE(crc32c, sse42_) {
if (X86_HAVE(SSE4_2)) {
*(void **)(&crc32c) = (void *)crc32c$sse42;
*(void **)(&crc32c) = (void *)crc32c_sse42;
}
}

View file

@ -23,7 +23,7 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
void *memccpy$pure(void *d, const void *s, int c, size_t n) {
void *memccpy_pure(void *d, const void *s, int c, size_t n) {
size_t i;
unsigned char *x;
const unsigned char *y;
@ -57,7 +57,7 @@ TEST(memccpy, memcpy) {
b2 = calloc(1, n);
b3 = calloc(1, n);
rngset(b1, n, rand64, -1);
e1 = memccpy$pure(b2, b1, 31337, n);
e1 = memccpy_pure(b2, b1, 31337, n);
e2 = memccpy(b3, b1, 31337, n);
n1 = e1 ? e1 - b2 : n;
n2 = e2 ? e2 - b3 : n;

View file

@ -174,7 +174,7 @@ void *MemCpy(void *, const void *, size_t);
#define BB(N) \
do { \
B(memmove$pure, N); \
B(memmove_pure, N); \
B(memcpy, N); \
B(MemCpy, N); \
fprintf(stderr, "\n"); \

View file

@ -70,7 +70,7 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) {
EXPECT_EQ(&buf[2], strchrnul(buf, 'z'));
}
char *strchr$pure(const char *s, int c) {
char *strchr_pure(const char *s, int c) {
char *r;
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
@ -85,7 +85,7 @@ TEST(strchr, fuzz) {
for (i = -2; i < 257; ++i) {
for (j = 0; j < 17; ++j) {
rngset(p, 63, rand64, -1);
ASSERT_EQ(strchr(p + j, i), strchr$pure(p + j, i));
ASSERT_EQ(strchr(p + j, i), strchr_pure(p + j, i));
}
}
free(p);
@ -103,7 +103,7 @@ BENCH(strchr, bench) {
strchr(VEIL("r", "hellzzzhellzzzeeAhellzzzhellzzzeeo"), 'o')));
}
char *memchr$pure(const char *m, int c, size_t n) {
char *memchr_pure(const char *m, int c, size_t n) {
const unsigned char *p, *pe;
for (c &= 0xff, p = (const unsigned char *)m, pe = p + n; p < pe; ++p) {
if (*p == c) return p;
@ -118,13 +118,13 @@ TEST(memchr, fuzz) {
for (i = -2; i < 257; ++i) {
for (j = 0; j < 17; ++j) {
rngset(p, 64, rand64, -1);
ASSERT_EQ(memchr(p + j, i, 64 - j), memchr$pure(p + j, i, 64 - j));
ASSERT_EQ(memchr(p + j, i, 64 - j), memchr_pure(p + j, i, 64 - j));
}
}
free(p);
}
char *strchrnul$pure(const char *s, int c) {
char *strchrnul_pure(const char *s, int c) {
char *r;
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
@ -139,13 +139,13 @@ TEST(strchrnul, fuzz) {
for (i = -2; i < 257; ++i) {
for (j = 0; j < 17; ++j) {
rngset(p, 63, rand64, -1);
ASSERT_EQ(strchrnul(p + j, i), strchrnul$pure(p + j, i));
ASSERT_EQ(strchrnul(p + j, i), strchrnul_pure(p + j, i));
}
}
free(p);
}
void *rawmemchr$pure(const void *m, int c) {
void *rawmemchr_pure(const void *m, int c) {
const unsigned char *s;
for (c &= 255, s = m;; ++s) {
if (*s == c) return s;
@ -160,7 +160,7 @@ TEST(rawmemchr, fuzz) {
for (j = 0; j < 17; ++j) {
rngset(p, 63, rand64, -1);
p[63] = i;
ASSERT_EQ(rawmemchr(p + j, i), rawmemchr$pure(p + j, i));
ASSERT_EQ(rawmemchr(p + j, i), rawmemchr_pure(p + j, i));
}
}
free(p);

View file

@ -485,14 +485,14 @@ TEST(wcsncmp, testTwosComplementBane) {
test/libc/str/strcmp_test.c § benchmarks
*/
testonly noinline int strcmp$pure(const char *a, const char *b) {
testonly noinline int strcmp_pure(const char *a, const char *b) {
for (; *a == *b; a++, b++) {
if (!*a) break;
}
return (*a & 0xff) - (*b & 0xff);
}
testonly noinline int strcasecmp$pure(const char *a, const char *b) {
testonly noinline int strcasecmp_pure(const char *a, const char *b) {
for (; *a && *b; a++, b++) {
if (!(*a == *b || tolower(*a & 0xff) == tolower(*b & 0xff))) {
break;
@ -542,38 +542,38 @@ BENCH(bench_00_strcmp, bench) {
fprintf(stderr, "\n");
EZBENCH2("strcmp [2 diff]", donothing,
EXPROPRIATE(strcmp(VEIL("r", "hi"), VEIL("r", "there"))));
EZBENCH2("strcmp$pure [2 diff]", donothing,
EXPROPRIATE(strcmp$pure(VEIL("r", "hi"), VEIL("r", "there"))));
EZBENCH2("strcmp_pure [2 diff]", donothing,
EXPROPRIATE(strcmp_pure(VEIL("r", "hi"), VEIL("r", "there"))));
fprintf(stderr, "\n");
EZBENCH2("strcmp [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp$pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
EXPROPRIATE(strcmp$pure(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp_pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
fprintf(stderr, "\n");
EZBENCH2("strcmp [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp$pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
EXPROPRIATE(strcmp$pure(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp_pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
fprintf(stderr, "\n");
EZBENCH2("strcmp [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp$pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
EXPROPRIATE(strcmp$pure(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp_pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
fprintf(stderr, "\n");
EZBENCH2("strcmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp$pure [short dupe]", randomize_buf2str_dupe(size, data, dupe),
EXPROPRIATE(strcmp$pure(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp_pure [short dupe]", randomize_buf2str_dupe(size, data, dupe),
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
fprintf(stderr, "\n");
EZBENCH2("strcmp [long dupe]", longstringislong_dupe(size, data, dupe),
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp$pure [long dupe]", longstringislong_dupe(size, data, dupe),
EXPROPRIATE(strcmp$pure(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcmp_pure [long dupe]", longstringislong_dupe(size, data, dupe),
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
}
BENCH(bench_01_strcasecmp, bench) {
@ -591,14 +591,14 @@ BENCH(bench_01_strcasecmp, bench) {
fprintf(stderr, "\n");
EZBENCH2("strcasecmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcasecmp$pure [short dupe]",
EZBENCH2("strcasecmp_pure [short dupe]",
randomize_buf2str_dupe(size, data, dupe),
EXPROPRIATE(strcasecmp$pure(VEIL("r", data), VEIL("r", dupe))));
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
fprintf(stderr, "\n");
EZBENCH2("strcasecmp [long dupe]", longstringislong_dupe(size, data, dupe),
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
EZBENCH2("strcasecmp$pure [long dupe]",
EZBENCH2("strcasecmp_pure [long dupe]",
longstringislong_dupe(size, data, dupe),
EXPROPRIATE(strcasecmp$pure(VEIL("r", data), VEIL("r", dupe))));
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
}

View file

@ -33,7 +33,7 @@ wchar_t u32[] = L"utf32 ☻";
TEST(strlen, usageExample_c11) {
_Alignas(16) char ugh[] = "eeeeeeeeeeeeeee\017";
EXPECT_EQ(1, strlen$pure(ugh + 15));
EXPECT_EQ(1, strlen_pure(ugh + 15));
EXPECT_EQ(6 + 3, strlen(u8));
EXPECT_EQ(7, strlen16(u16));
EXPECT_EQ(7, wcslen(u32));
@ -146,10 +146,10 @@ TEST(strlen, fuzz) {
for (n = 2; n < 1026; ++n) {
b = rngset(calloc(1, n), n - 1, rand64, -1);
n1 = strlen(b);
n2 = strlen$pure(b);
n2 = strlen_pure(b);
ASSERT_EQ(n1, n2, "%#.*s", n, b);
n1 = strlen(b + 1);
n2 = strlen$pure(b + 1);
n2 = strlen_pure(b + 1);
ASSERT_EQ(n1, n2);
free(b);
}
@ -157,27 +157,27 @@ TEST(strlen, fuzz) {
BENCH(strlen, bench) {
extern size_t strlen_(const char *) asm("strlen");
extern size_t strlen$pure_(const char *) asm("strlen$pure");
extern size_t strlen_pure_(const char *) asm("strlen_pure");
static char b[2048];
memset(b, -1, sizeof(b) - 1);
EZBENCH2("strlen 1", donothing, strlen_(""));
EZBENCH2("strlen$pure 1", donothing, strlen$pure_(""));
EZBENCH2("strlen_pure 1", donothing, strlen_pure_(""));
EZBENCH2("strlen 2", donothing, strlen_("1"));
EZBENCH2("strlen$pure 2", donothing, strlen$pure_("1"));
EZBENCH2("strlen_pure 2", donothing, strlen_pure_("1"));
EZBENCH2("strlen 7", donothing, strlen_("123456"));
EZBENCH2("strlen$pure 7", donothing, strlen$pure_("123456"));
EZBENCH2("strlen_pure 7", donothing, strlen_pure_("123456"));
EZBENCH2("strlen 8", donothing, strlen_("1234567"));
EZBENCH2("strlen$pure 8", donothing, strlen$pure_("1234567"));
EZBENCH2("strlen_pure 8", donothing, strlen_pure_("1234567"));
EZBENCH2("strlen 9", donothing, strlen_("12345678"));
EZBENCH2("strlen$pure 9", donothing, strlen$pure_("12345678"));
EZBENCH2("strlen_pure 9", donothing, strlen_pure_("12345678"));
EZBENCH2("strlen 11", donothing, strlen_("12345678aa"));
EZBENCH2("strlen$pure 11", donothing, strlen$pure_("12345678aa"));
EZBENCH2("strlen_pure 11", donothing, strlen_pure_("12345678aa"));
EZBENCH2("strlen 13", donothing, strlen_("12345678aabb"));
EZBENCH2("strlen$pure 13", donothing, strlen$pure_("12345678aabb"));
EZBENCH2("strlen_pure 13", donothing, strlen_pure_("12345678aabb"));
EZBENCH2("strlen 16", donothing, strlen_("123456781234567"));
EZBENCH2("strlen$pure 16", donothing, strlen$pure_("123456781234567"));
EZBENCH2("strlen_pure 16", donothing, strlen_pure_("123456781234567"));
EZBENCH2("strlen 17", donothing, strlen_("123456781234567e"));
EZBENCH2("strlen$pure 17", donothing, strlen$pure_("123456781234567e"));
EZBENCH2("strlen_pure 17", donothing, strlen_pure_("123456781234567e"));
EZBENCH2("strlen 1023", donothing, strlen_(b));
EZBENCH2("strlen$pure 1023", donothing, strlen$pure_(b));
EZBENCH2("strlen_pure 1023", donothing, strlen_pure_(b));
}

View file

@ -28,15 +28,15 @@
#define MAKESTRING(NAME, VALUE) \
char *NAME = strcpy(malloc(sizeof(VALUE) + 16), VALUE)
char *strstr$kmp(const char *haystak, const char *needle) {
char *strstr_kmp(const char *haystak, const char *needle) {
return memmem(haystak, strlen(haystak), needle, strlen(needle));
}
char *(*strstri)(const char *, const char *) = strstr$kmp;
char *(*strstri)(const char *, const char *) = strstr_kmp;
FIXTURE(strstr, sse42) {
FIXTURE(strstr, sse42_) {
if (X86_HAVE(SSE4_2)) {
strstri = strstr$sse42;
strstri = strstr_sse42;
}
}