aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 11:55:55 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 12:34:01 -0800
commite97c8c469db0aa27985dab2879dc1f14905c7387 (patch)
treef10f7ed68f1ad5212eebb0985ef040c5e96235ba
parenta9bfe650038afea8b751175cac16f6027345e45f (diff)
chore: simplify makefiles
-rw-r--r--.gitignore2
-rw-r--r--Makefile2
-rwxr-xr-xbin/updatedirs2
-rw-r--r--include/base.h1
-rw-r--r--include/base/io.h64
-rw-r--r--rules.mk18
-rw-r--r--share/dynamic.mk6
-rw-r--r--share/paths.mk10
-rw-r--r--src/base/bufio/dump.c66
-rw-r--r--src/base/bufio/get.c17
-rw-r--r--src/base/bufio/internal.h2
-rw-r--r--src/base/bufio/read.c36
-rw-r--r--src/base/bufio/reader.c28
-rw-r--r--src/base/bufio/refill.h28
-rw-r--r--src/base/bufio/rules.mk10
-rw-r--r--src/base/bufio/unget.c18
-rw-r--r--src/base/fmt/do.c6
-rw-r--r--src/base/fmt/float.c12
-rw-r--r--src/base/fmt/open.c5
-rw-r--r--src/base/fmt/rules.mk3
-rw-r--r--src/base/fmt/test.c2
-rw-r--r--src/base/rules.mk9
-rw-r--r--src/base/test.c112
-rw-r--r--src/base/utf/rules.mk9
-rw-r--r--src/cmd/rules.mk3
-rw-r--r--src/rules.mk8
-rw-r--r--sys/linux/src/write.c2
-rw-r--r--sys/rt/boot.c2
-rw-r--r--sys/rt/stack.c6
-rw-r--r--sys/rules.mk12
30 files changed, 95 insertions, 406 deletions
diff --git a/.gitignore b/.gitignore
index aad5c06..5b7262d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,7 @@ sys/libdraw
sys/libimage
sys/libterm
-src/libutf/*-14.0.0.c
+src/base/utf/*-14.0.0.c
.dep/
.clangd
diff --git a/Makefile b/Makefile
index 793d888..9cfa8e4 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ CFLAGS := -g -march=native -fno-strict-aliasing -fwrapv -fms-extensions -Wno-mic
STATIC := -ffreestanding -nodefaultlibs -nostartfiles -nostdinc -static
AFLAGS := -g
INCS := -I $(SYS_DIR)/$(OS)/$(ARCH) -I $(SYS_DIR)/$(OS)/port -I $(INC_DIR) -isystem $(INC_DIR)/vendor/libc
-ELIBS := -L$(LIB_DIR) -lc
+ELIBS := $(SYS) -L$(LIB_DIR) -lc
# Named generic rules (must be evaluated lazily)
COMPILE = @echo "CC "$(@:$(OBJ_DIR)/%=%);\
diff --git a/bin/updatedirs b/bin/updatedirs
index 663c51a..228747a 100755
--- a/bin/updatedirs
+++ b/bin/updatedirs
@@ -1,7 +1,7 @@
#!/bin/python
import os
-ROOT = "/home/nolln/root"
+ROOT = "/home/nolln/u"
SRC = "src"
BUILD = "obj"
TEST = "test"
diff --git a/include/base.h b/include/base.h
index 8152cb7..a7e9319 100644
--- a/include/base.h
+++ b/include/base.h
@@ -29,6 +29,7 @@ typedef wchar_t wchar;
#include <base/error.h>
#include <base/io.h>
+/* no dependencies */
#include <base/fmt.h>
#include <base/utf.h>
#include <base/coro.h>
diff --git a/include/base/io.h b/include/base/io.h
index f8c0bcc..5e0f1e0 100644
--- a/include/base/io.h
+++ b/include/base/io.h
@@ -96,46 +96,46 @@ int io·flush(io·Stream *s);
int io·seek(io·Stream *s, long off, enum SeekPos whence);
long io·tell(io·Stream *s);
-/* basic os helpers */
-
-int os·exists(byte *path, int flag);
-byte *os·dirname(byte *path);
-byte *os·basename(byte *path);
-int os·sep(void);
-
-/* io interfaces */
/* buffered i/o */
typedef struct io·Buffer io·Buffer;
+#define iota(x) (1 << (x))
enum
{
- bufio·size = 2*4096,
- bufio·ungets = 8,
- bufio·eof = -1,
- bufio·err = -2,
-
- bufio·nil = 1 << 0,
- bufio·rdr = 1 << 1,
- bufio·wtr = 1 << 2,
- bufio·end = 1 << 3,
+ io·BufEof = -1,
+ io·BufErr = -2,
+ io·BufUngets = 8,
+ io·BufMagic = 0x314159,
+ io·BufLen = 2*4096,
+
+ /* state */
+ io·BufNil = iota(0),
+ io·BufRdr = iota(1),
+ io·BufWtr = iota(2),
+ io·BufEnd = iota(3)
};
+#undef iota
struct io·Buffer
{
- int state;
- int runesize;
- void *h;
- union {
- io·Reader rdr;
- io·Writer wtr;
- };
- vlong size;
- byte *beg, *pos, *end;
- byte buf[bufio·size + bufio·ungets];
+ int state, id, flag;
+ struct{
+ int in; /* negative number of bytes at end */
+ int out; /* number of bytes at start */
+ int line; /* number of bytes after last readline */
+ } off;
+ intptr pos, cap; /* position in file, capacity of buffer */
+ uchar *b,*g,*e; /* start, good bytes, end of byte pointers */
+ uchar bytes[];
};
-int bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h);
-void bufio·finireader(io·Buffer *buf);
-int bufio·getbyte(io·Buffer *buf);
-int bufio·ungetbyte(io·Buffer *buf, byte c);
-int bufio·read(io·Buffer *buf, int sz, int n, void *out);
+int bio·init(io·Buffer *io, int fd, int mode);
+int bio·initcap(io·Buffer *io, int fd, int mode, int cap);
+
+/* basic os helpers */
+/* XXX: find a better location for this */
+int os·exists(byte *path, int flag);
+byte *os·dirname(byte *path);
+byte *os·basename(byte *path);
+int os·sep(void);
+
diff --git a/rules.mk b/rules.mk
index e8be45d..d89035e 100644
--- a/rules.mk
+++ b/rules.mk
@@ -1,5 +1,5 @@
# Standard housekeeping
-.PHONY: all debug release system bins libs tests clean target install
+.PHONY: all debug release clean target install
.SUFFIXES:
all: targets
@@ -9,8 +9,8 @@ debug: CFLAGS += -DDEBUG -g -fsanitize=address
debug: INCS := -I $(INC_DIR)
debug: ELIBS := -fsanitize=address
debug: STATIC :=
-debug: CINIT :=
-debug: CFINI :=
+debug: INIT :=
+debug: FINI :=
debug: targets
release: CFLAGS += -O2 -mtune=native -flto #-DNDEBUG
@@ -48,14 +48,18 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
$(OBJ_DIR)/%: $(SRC_DIR)/%.c
$(COMPLINK)
+$(TST_DIR)/%: TLIBS=$(OBJ_DIR)/base/base.a $(SYS)
+$(TST_DIR)/%: $(SRC_DIR)/%.c
+ $(COMPLINK)
+
# iterate through source directory tree
DIR := src
include $(DIR)/rules.mk
-system: $(RUNTIME) $(SYS)
-bins: system $(BINS)
-tests: system $(TEST)
-targets: libs bins tests
+$(BINS): | $(LIBS) $(RUNTIME) $(SYS)
+$(TEST): | $(LIBS) $(RUNTIME) $(SYS)
+
+targets: $(LIBS) $(BINS) $(TEST)
clean:
@echo removing system layer
diff --git a/share/dynamic.mk b/share/dynamic.mk
index b7ec24d..f5f2956 100644
--- a/share/dynamic.mk
+++ b/share/dynamic.mk
@@ -3,9 +3,3 @@ $(BINS_$(d)): INIT =
$(BINS_$(d)): FINI =
$(BINS_$(d)): ELIBS =
$(BINS_$(d)): INCS = -I $(SYS_DIR)/$(OS)/$(ARCH) -I $(SYS_DIR)/$(OS)/port -I $(INC_DIR)
-
-$(TEST_$(d)): STATIC =
-$(TEST_$(d)): INIT =
-$(TEST_$(d)): FINI =
-$(TEST_$(d)): ELIBS =
-$(TEST_$(d)): INCS = -I $(SYS_DIR)/$(OS)/$(ARCH) -I $(SYS_DIR)/$(OS)/port -I $(INC_DIR)
diff --git a/share/paths.mk b/share/paths.mk
index 112c254..978d87d 100644
--- a/share/paths.mk
+++ b/share/paths.mk
@@ -15,14 +15,6 @@ LIBS += $(LIBS_$(d))
BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
BINS += $(BINS_$(d))
-# Testing infrastructure
-
-UNIT_$(d) := $(CHECK_$(d):.c=.o)
-UNIT_$(d) := $(patsubst %(SRC_DIR)/%, $(OBJ_DIR)/%, $(UNIT_$(d)))
-OBJS += $(UNIT_$(d))
-
-TEST_$(d) := $(patsubst $(SRC_DIR)/%, $(TEST_DIR)/%, $(TEST_$(d):.c=))
-TEST += $(TEST_$(d))
-
# useful path
o := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(d))
+t := $(patsubst $(SRC_DIR)/%, $(TST_DIR)/%, $(d))
diff --git a/src/base/bufio/dump.c b/src/base/bufio/dump.c
deleted file mode 100644
index 0b527e2..0000000
--- a/src/base/bufio/dump.c
+++ /dev/null
@@ -1,66 +0,0 @@
-// -----------------------------------------------------------------------
-// reader
-
-#if 0
-rune
-bufio·getrune(io·Buffer *buf)
-{
- ubyte b;
- int i;
- byte str[UTFmax+1];
- rune r;
-
- // NOTE: I'm worried about the sign here...
- b = bufio·getbyte(buf);
- if (b < RuneSelf) {
- buf->runesize = 1;
- return b;
- }
-
- i = 0;
- str[i++] = b;
-
-nextbyte:
- b = bufio·getbyte(buf);
- if (b < 0) return b;
- if (i >= arrlen(str)) return RuneErr;
- str[i++] = b;
- if (!utf8·fullrune(str, i))
- goto nextbyte;
-
- buf->runesize = utf8·bytetorune(&r, str);
- if (r == RuneErr && b == 1) {
- errorf("illegal UTF-8 sequence");
- for (; i >= 0; i--)
- errorf("%s%.2x", i > 0 ? " " : "", *(ubyte*)(str+i));
- errorf("\n");
-
- buf->runesize = 0;
- } else
- for (; i > buf->runesize; i--)
- bufio·ungetbyte(buf, str[i]);
-
- return r;
-}
-
-// TODO: Check that we are given the correct rune!
-error
-bufio·ungetrune(io·Buffer *buf, rune r)
-{
- if (buf->state & bufio·rdr) {
- errorf("attempted to unget on non-active reader");
- return bufio·err;
- }
-
- if (buf->pos == buf->buf) {
- errorf("attempted to unget past end of buffer");
- return bufio·err;
- }
-
- buf->pos -= buf->runesize;
- return 0;
-}
-#endif
-
-// -----------------------------------------------------------------------
-// writer
diff --git a/src/base/bufio/get.c b/src/base/bufio/get.c
deleted file mode 100644
index 9f10c88..0000000
--- a/src/base/bufio/get.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "internal.h"
-#include "refill.h"
-
-int
-bufio·getbyte(io·Buffer *buf)
-{
-getbyte:
- if(buf->pos < buf->end)
- return *buf->pos++;
-
- memmove(buf->buf, buf->end - bufio·ungets, bufio·ungets);
-
- if(refill(buf) <= 0)
- return bufio·eof;
-
- goto getbyte;
-}
diff --git a/src/base/bufio/internal.h b/src/base/bufio/internal.h
index 302c035..a1a006a 100644
--- a/src/base/bufio/internal.h
+++ b/src/base/bufio/internal.h
@@ -1,4 +1,2 @@
-#pragma once
-
#include <u.h>
#include <base.h>
diff --git a/src/base/bufio/read.c b/src/base/bufio/read.c
deleted file mode 100644
index 09a9f83..0000000
--- a/src/base/bufio/read.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "internal.h"
-#include "refill.h"
-
-int
-bufio·read(io·Buffer *buf, int sz, int n, void *out)
-{
- byte *wtr;
- int nr, rem, diff;
-
- if(n == 0 || buf->state & bufio·end)
- return bufio·err;
-
- assert(buf->state & bufio·rdr);
-
- wtr = out;
- rem = n*sz;
-
- while(rem > 0){
- diff = buf->end - buf->pos;
- nr = MIN(diff, rem);
- if(!nr){
- if(buf->state & bufio·end)
- break;
- if(refill(buf) <= 0)
- break;
-
- continue;
- }
- memmove(wtr, buf->pos, nr);
- wtr += nr;
- buf->pos += nr;
- rem -= nr;
- }
-
- return n - rem/sz;
-}
diff --git a/src/base/bufio/reader.c b/src/base/bufio/reader.c
deleted file mode 100644
index 39ea63e..0000000
--- a/src/base/bufio/reader.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "internal.h"
-
-int
-bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h)
-{
- if (buf->state) {
- errorf("attemped to initialize an active buffer, state is '%d'", buf->state);
- return bufio·err;
- }
- buf->state = bufio·rdr;
- buf->runesize = 0;
- buf->h = h;
- buf->rdr = rdr;
- buf->beg = buf->buf + bufio·ungets;
- buf->pos = buf->beg;
- buf->end = buf->pos;
- buf->size = bufio·size - bufio·ungets;
-
- return 0;
-}
-
-void
-bufio·finireader(io·Buffer *buf)
-{
- buf->state = bufio·nil;
- buf->runesize = 0;
- buf->rdr = (io·Reader){ .read = nil };
-}
diff --git a/src/base/bufio/refill.h b/src/base/bufio/refill.h
deleted file mode 100644
index 41e357e..0000000
--- a/src/base/bufio/refill.h
+++ /dev/null
@@ -1,28 +0,0 @@
-int
-refill(io·Buffer *buf)
-{
- int n;
-
- if(buf->state & bufio·end)
- return bufio·err;
-
- memcpy(buf->buf, buf->pos - bufio·ungets, bufio·ungets);
-
- n = buf->rdr.read(buf->h, 1, buf->size, buf->beg);
- if(n < 0)
- return bufio·err;
- if(n == 0){
- buf->state |= bufio·end;
- return 0;
- }
-
- buf->pos = buf->beg;
- buf->end = buf->pos + n;
-
- // TEST: put a physical EOF byte at the end
- // this would allow for an unget operation
- if(n < buf->size)
- *buf->end++ = EOF;
-
- return n;
-}
diff --git a/src/base/bufio/rules.mk b/src/base/bufio/rules.mk
index 84f283f..8089e77 100644
--- a/src/base/bufio/rules.mk
+++ b/src/base/bufio/rules.mk
@@ -1,5 +1,5 @@
-SRCS_$(d)+=\
- $(d)/bufio/get.c\
- $(d)/bufio/read.c\
- $(d)/bufio/reader.c\
- $(d)/bufio/unget.c\
+# SRCS_$(d)+=\
+# $(d)/bufio/get.c\
+# $(d)/bufio/read.c\
+# $(d)/bufio/reader.c\
+# $(d)/bufio/unget.c\
diff --git a/src/base/bufio/unget.c b/src/base/bufio/unget.c
deleted file mode 100644
index 1951384..0000000
--- a/src/base/bufio/unget.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "internal.h"
-
-int
-bufio·ungetbyte(io·Buffer *buf, byte c)
-{
- if(!(buf->state & bufio·rdr)) {
- errorf("attempted to unget on non-active reader");
- return bufio·err;
- }
-
- if(buf->pos == buf->buf) {
- errorf("attempted to unget past end of buffer");
- return bufio·err;
- }
-
- buf->pos--;
- return 0;
-}
diff --git a/src/base/fmt/do.c b/src/base/fmt/do.c
index bd2e65c..71b005e 100644
--- a/src/base/fmt/do.c
+++ b/src/base/fmt/do.c
@@ -363,9 +363,9 @@ fmtstring(fmt·State *io)
static int
fmterror(fmt·State *io)
{
- char *s;
- s = strerror(errno);
- return copystring(io, s);
+ int c;
+ c = va_arg(io->args, int);
+ return copystring(io, sys·errormsg(c));
}
static int
diff --git a/src/base/fmt/float.c b/src/base/fmt/float.c
index 63ea80f..8a42dfc 100644
--- a/src/base/fmt/float.c
+++ b/src/base/fmt/float.c
@@ -529,7 +529,7 @@ fmtstrtod(char *as, char **aas)
ex = -ex;
dp += ex;
if(dp < -Maxe){
- errno = ERANGE;
+ /* errno = ERANGE; */
goto ret0; /* underflow by exp */
} else
if(dp > +Maxe)
@@ -617,7 +617,7 @@ retnan:
retinf:
/* Unix strtod requires these. Plan 9 would return Inf(0) or Inf(-1). */
- errno = ERANGE;
+ /* errno = ERANGE; */
if(flag & Fsign)
return -HUGE_VAL;
return HUGE_VAL;
@@ -630,7 +630,7 @@ out:
d = -d;
d = ldexp(d, bp - Prec*Nbits);
if(d == 0) /* underflow */
- errno = ERANGE;
+ /* errno = ERANGE; */
return d;
}
@@ -694,12 +694,10 @@ fmtexp(char *p, int e, int ucase)
static void
dtoa(double f, char *s, int *exp, int *neg, int *len)
{
- int c, d, e2, e, ee, i, ndigit, oerrno;
+ int c, d, e2, e, ee, i, ndigit;
char buf[NSIGNIF+10];
double g;
- oerrno = errno;
-
*neg = 0;
if(f < 0){
f = -f;
@@ -785,7 +783,7 @@ dtoa(double f, char *s, int *exp, int *neg, int *len)
*exp = e;
*len = ndigit;
- errno = oerrno;
+ /* errno = oerrno; */
}
diff --git a/src/base/fmt/open.c b/src/base/fmt/open.c
index 8aadef5..b6829bb 100644
--- a/src/base/fmt/open.c
+++ b/src/base/fmt/open.c
@@ -3,11 +3,12 @@
static int
flush(fmt·State *io)
{
- int n, fd;
+ int fd;
+ intptr n;
fd = (uintptr)io->file;
n = io->buffer.cur - io->buffer.beg;
- if(n && write(fd, io->buffer.beg, n) != n)
+ if(n && sys·write(fd, n, io->buffer.beg, &n))
return -1;
io->buffer.cur = io->buffer.beg;
diff --git a/src/base/fmt/rules.mk b/src/base/fmt/rules.mk
index fdfdac0..8effa9e 100644
--- a/src/base/fmt/rules.mk
+++ b/src/base/fmt/rules.mk
@@ -17,5 +17,4 @@ SRCS_$(d)+=\
$(d)/fmt/panic.c\
$(d)/fmt/write.c
-CHECK_$(d)+=\
- $(d)/fmt/test.c
+TEST += $(TST_DIR)/base/fmt/test
diff --git a/src/base/fmt/test.c b/src/base/fmt/test.c
index d81a62e..73f5e7c 100644
--- a/src/base/fmt/test.c
+++ b/src/base/fmt/test.c
@@ -1,7 +1,5 @@
#include <u.h>
#include <base.h>
-#include <libutf.h>
-#include <libfmt.h>
typedef struct Complex
{
diff --git a/src/base/rules.mk b/src/base/rules.mk
index 0a262c7..64f0797 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -6,9 +6,6 @@ include share/push.mk
SRCS_$(d):=\
$(d)/arg.c
-CHECK_$(d):=\
- $(d)/test.c
-
include $(d)/bufio/rules.mk
include $(d)/coro/rules.mk
include $(d)/error/rules.mk
@@ -28,13 +25,11 @@ include $(d)/utf/rules.mk
# outputs
LIBS_$(d) := $(d)/base.a
+TEST += $(TST_DIR)/base/test
+
include share/paths.mk
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
-$(TEST_$(d)): TLIBS = $(LIBS_$(d))
-$(TEST_$(d)): $(UNIT_$(d)) $(LIBS_$(d))
- $(LINK)
-
include share/pop.mk
diff --git a/src/base/test.c b/src/base/test.c
index a29be1d..de53125 100644
--- a/src/base/test.c
+++ b/src/base/test.c
@@ -4,111 +4,6 @@
#include <time.h>
-uintptr
-printtest(Coro *c, uintptr d)
-{
- printf("--> Recieved %lu\n", d);
- d = coro·yield(c, d+10);
- printf("--> Now %lu\n", d);
-
- return d;
-}
-
-uintptr
-sequence(Coro *c, uintptr start)
-{
- int d = start;
- for (;;) {
- coro·yield(c, d++);
- }
-
- return d;
-}
-
-struct PrimeMsg
-{
- Coro *seq;
- int p;
-};
-
-uintptr
-filter(Coro *c, uintptr data)
-{
- int x, p;
- Coro *seq;
- struct PrimeMsg *msg;
-
- // Need to copy relevant variables onto the local stack
- // Data is volatile.
- msg = (struct PrimeMsg*)data;
- seq = msg->seq;
- p = msg->p;
-
- for (;;) {
- x = coro·yield(seq, x);
- if (x % p != 0) {
- x = coro·yield(c, x);
- }
- }
-
- return 0;
-}
-
-error
-test·coro()
-{
- int i;
- Coro *c[4];
- uintptr d;
-
- printf("Starting singleton test\n");
-
- for (i = 0; i < arrlen(c); i++) {
- c[i] = coro·make(0, &printtest);
- }
-
- /* Singleton test */
- d = 0;
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[0], d);
- }
-
- printf("Starting triplet test\n");
-
- /* Triplet test */
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[1], d);
- d = coro·yield(c[2], d+100);
- d = coro·yield(c[3], d+200);
- }
-
- for (i = 0; i < arrlen(c); i++) {
- coro·free(c[i]);
- }
-
- /* Prime sieve */
- printf("Starting prime test\n");
- uintptr num;
- Coro *cur, *seq[50];
-
- num = 2;
- seq[0] = coro·make(4096, &sequence);
- cur = *seq;
-
- num = coro·yield(cur, num);
- for (i = 1; i < arrlen(seq); i++) {
- seq[i] = coro·make(4096, &filter);
- struct PrimeMsg msg = {
- .seq = cur,
- .p = num,
- };
- cur = seq[i];
- num = coro·yield(cur, (uintptr)&msg);
- printf("--> prime number %lu\n", num);
- }
- return 0;
-}
-
int
less(void* a, void* b)
{
@@ -119,7 +14,7 @@ less(void* a, void* b)
return ai - bi;
}
-error
+int
test·sort()
{
clock_t t;
@@ -155,10 +50,10 @@ test·sort()
return 0;
}
-error
+int
main()
{
- error err;
+ int err;
#if 0
if (err = test·coro(), err) {
errorf("test fail: coroutine");
@@ -167,4 +62,5 @@ main()
if (err = test·sort(), err) {
errorf("test fail: coroutine");
}
+ return 0;
}
diff --git a/src/base/utf/rules.mk b/src/base/utf/rules.mk
index 446c113..dfe2da1 100644
--- a/src/base/utf/rules.mk
+++ b/src/base/utf/rules.mk
@@ -22,7 +22,8 @@ NEED_OBJS=\
$(OBJ_DIR)/base/error/panicf.o\
$(OBJ_DIR)/base/io/readln.o\
$(OBJ_DIR)/base/io/open.o\
- $(OBJ_DIR)/base/io/close.o
+ $(OBJ_DIR)/base/io/close.o\
+ $(d)/utf/vendor/common.o
$(d)/utf/vendor/common.o: $(d)/utf/vendor/common.c
$(COMPILE)
@@ -32,7 +33,7 @@ $(d)/utf/vendor/UnicodeData-$(UNICODE).txt:
@echo "GET UnicodeData.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/UnicodeData.txt > $@
-$(d)/utf/vendor/mkrunetype: $(d)/utf/vendor/mkrunetype.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkrunetype: $(d)/utf/vendor/mkrunetype.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
GENS += $(d)/utf/vendor/mkrunetype
@@ -49,7 +50,7 @@ $(d)/utf/vendor/EmojiData-$(UNICODE).txt:
@echo "GET EmojiData.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/emoji/emoji-data.txt > $@
-$(d)/utf/vendor/mkrunewidth: $(d)/utf/vendor/mkrunewidth.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkrunewidth: $(d)/utf/vendor/mkrunewidth.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
GENS += $(d)/utf/vendor/mkrunewidth
@@ -62,7 +63,7 @@ $(d)/utf/vendor/GraphemeBreakProperty-$(UNICODE).txt:
@echo "GET GraphemeBreakProperty.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/auxiliary/GraphemeBreakProperty.txt > $@
-$(d)/utf/vendor/mkgraphemedata: $(d)/utf/vendor/mkgraphemedata.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkgraphemedata: $(d)/utf/vendor/mkgraphemedata.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
$(d)/utf/graphemedata-$(UNICODE).c: $(d)/utf/vendor/mkgraphemedata $(d)/utf/vendor/GraphemeBreakProperty-$(UNICODE).txt
diff --git a/src/cmd/rules.mk b/src/cmd/rules.mk
index 8a9cfab..ea53737 100644
--- a/src/cmd/rules.mk
+++ b/src/cmd/rules.mk
@@ -29,7 +29,4 @@ include $(DIR)/rules.mk
DIR := $(d)/term
include $(DIR)/rules.mk
-# DIR := $(d)/wm
-# include $(DIR)/rules.mk
-
include share/pop.mk
diff --git a/src/rules.mk b/src/rules.mk
index 368479c..8e8594c 100644
--- a/src/rules.mk
+++ b/src/rules.mk
@@ -8,10 +8,10 @@ include $(DIR)/rules.mk
DIR := $(d)/base
include $(DIR)/rules.mk
-DIR := $(d)/libmath
-include $(DIR)/rules.mk
+# DIR := $(d)/libmath
+# include $(DIR)/rules.mk
-DIR := $(d)/libbio
-include $(DIR)/rules.mk
+# DIR := $(d)/libbio
+# include $(DIR)/rules.mk
include share/pop.mk
diff --git a/sys/linux/src/write.c b/sys/linux/src/write.c
index 7863673..4e09d82 100644
--- a/sys/linux/src/write.c
+++ b/sys/linux/src/write.c
@@ -4,5 +4,5 @@ int
sys·write(int fd, uintptr len, void *buf, intptr *ret)
{
long err = *ret = syscall(·Write, fd, buf, len);
- return err;
+ return error(err);
}
diff --git a/sys/rt/boot.c b/sys/rt/boot.c
index 76f5599..320a596 100644
--- a/sys/rt/boot.c
+++ b/sys/rt/boot.c
@@ -4,6 +4,7 @@
/* tell linker to go find */
int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv);
+void rt·guardstack(void);
#define NAUX 38
static void
@@ -19,6 +20,7 @@ rt·init(char **env, char *program)
rt·context.sysinfo = aux[AT_SYSINFO];
rt·context.pagesize = aux[AT_PAGESZ];
+ rt·guardstack();
}
int
diff --git a/sys/rt/stack.c b/sys/rt/stack.c
index 5ab7a8a..0785760 100644
--- a/sys/rt/stack.c
+++ b/sys/rt/stack.c
@@ -2,7 +2,8 @@
#include <arch/atomic.h>
/* unprefixed names determined by gcc */
-uintptr __stack_chk_guard;
+uintptr rt·stackguard;
+weakalias(rt·stackguard, __stack_chk_guard);
void
rt·guardstack(void)
@@ -11,7 +12,8 @@ rt·guardstack(void)
}
void
-__stack_chk_fail(void)
+rt·stackfail(void)
{
atomic·crash();
}
+weakalias(rt·stackfail, __stack_chk_fail);
diff --git a/sys/rules.mk b/sys/rules.mk
index 3113915..4bba9aa 100644
--- a/sys/rules.mk
+++ b/sys/rules.mk
@@ -1,9 +1,11 @@
# rules for rt
+# -- rt1 initialization --
RT1 := $(OBJ_DIR)/rt/rt1.a
RTI := $(OBJ_DIR)/rt/rti.o
-# rt2 = user program
+# -- rt2 = user program --
RTN := $(OBJ_DIR)/rt/rtn.o
RT3 := $(OBJ_DIR)/rt/rt3.a
+# -- rt3 finalization --
RUNTIME := $(RT1) $(RTI) $(RTN) $(RT3)
RT1_SRC := \
@@ -12,12 +14,14 @@ RT1_SRC := \
$(SYS_DIR)/rt/boot.c\
$(SYS_DIR)/rt/thunk.c
+RT1_OBJ := $(filter %.o, $(RT1_SRC:.c=.o))
+RT1_OBJ := $(patsubst $(SYS_DIR)/rt/%, $(OBJ_DIR)/rt/%, $(RT1_OBJ))
+
RT3_SRC := \
+ $(SYS_DIR)/rt/stack.c\
$(SYS_DIR)/rt/dummy.c\
- $(SYS_DIR)/rt/exit.c\
+ $(SYS_DIR)/rt/exit.c
-RT1_OBJ := $(filter %.o, $(RT1_SRC:.c=.o))
-RT1_OBJ := $(patsubst $(SYS_DIR)/rt/%, $(OBJ_DIR)/rt/%, $(RT1_OBJ))
RT3_OBJ := $(filter %.o, $(RT3_SRC:.c=.o))
RT3_OBJ := $(patsubst $(SYS_DIR)/rt/%, $(OBJ_DIR)/rt/%, $(RT3_OBJ))