summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile22
-rw-r--r--src/user/app/netstack/netstack.c2
-rw-r--r--src/user/app/tests/tests.c4
-rw-r--r--src/user/lib/_start2.c4
-rw-r--r--src/user/lib/elfreloc.c8
-rw-r--r--src/user/lib/include/limits.h2
-rw-r--r--src/user/linker.ld2
l---------sysroot/usr/include1
l---------sysroot/usr/local/include1
-rw-r--r--sysroot_alt/usr/include/limits.h3
m---------toolchain/gcc0
-rwxr-xr-xtools/dep_builders/binutils3
-rwxr-xr-xtools/dep_builders/gcc5
13 files changed, 32 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 714abab..0faf7a9 100644
--- a/Makefile
+++ b/Makefile
@@ -8,15 +8,14 @@ CHECK = sparse
CFLAGS += -g -std=gnu99 -O2 -ftrack-macro-expansion=0
CFLAGS += -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declaration
CFLAGS += -Wno-address-of-packed-member -Werror=incompatible-pointer-types
-CFLAGS += -Isrc/shared/include/
-KERNEL_CFLAGS = $(CFLAGS) -ffreestanding -mno-sse -mgeneral-regs-only -Isrc/
-LIBC_CFLAGS = $(CFLAGS) -Isrc/user/lib/include/ -ffreestanding -Isrc/
-USER_CFLAGS = $(CFLAGS) -Isrc/user/lib/include/
+KERNEL_CFLAGS = $(CFLAGS) -ffreestanding -mno-sse -mgeneral-regs-only \
+ --sysroot=$(shell pwd)/sysroot_alt/ -Isrc/ -Isrc/shared/include/
+LIBC_CFLAGS = $(CFLAGS) -ffreestanding -Isrc/
+USER_CFLAGS = $(CFLAGS)
SPARSEFLAGS = -$(KERNEL_CFLAGS) -Wno-non-pointer-null
-LFLAGS = -ffreestanding -O2 -nostdlib -lgcc -Wl,-zmax-page-size=4096 -Wl,--no-warn-mismatch
-# TODO optimize memory use
+
QFLAGS = -no-reboot -m 1g -gdb tcp::12366
ifdef NET_DIRECT
QFLAGS += -nic socket,model=rtl8139,connect=:1234,mac=52:54:00:ca:77:1a,id=n1
@@ -76,7 +75,10 @@ out/fs/boot/kernel: src/kernel/arch/amd64/linker.ld \
$(call from_sources, src/kernel/) \
$(call from_sources, src/shared/)
@mkdir -p $(@D)
- @$(CC) $(LFLAGS) -T $^ -o $@
+ @$(CC) \
+ -nostdlib \
+ -Wl,-zmax-page-size=4096 -Wl,--no-warn-mismatch -Wl,-no-pie \
+ -T $^ -o $@
@grub-file --is-x86-multiboot2 $@ || echo "$@ has an invalid multiboot2 header"
@grub-file --is-x86-multiboot2 $@ || rm $@; test -e $@
@@ -91,7 +93,7 @@ out/libm.a:
out/bootstrap: src/user/bootstrap/linker.ld $(call from_sources, src/user/bootstrap/) out/libc.a
@mkdir -p $(@D)
- @$(CC) $(LFLAGS) -Wl,-Map=% -T $^ -o $@
+ @$(CC) -nostdlib -Wl,-Map=% -T $^ -o $@
out/fs/boot/init: out/bootstrap out/initrd.tar
@mkdir -p $(@D)
@@ -105,9 +107,9 @@ out/fs.e2:
@mkfs.ext2 $@ 1024 > /dev/null
define userbin_template =
-out/initrd/bin/amd64/$(1): src/user/linker.ld $(call from_sources, src/user/app/$(1)) out/libc.a
+out/initrd/bin/amd64/$(1): $(call from_sources, src/user/app/$(1)) out/libc.a
@mkdir -p $$(@D)
- @$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $$^ -o $$@
+ @$(CC) -nostdlib $$^ -o $$@
endef
USERBINS := $(shell ls src/user/app)
$(foreach bin,$(USERBINS),$(eval $(call userbin_template,$(bin))))
diff --git a/src/user/app/netstack/netstack.c b/src/user/app/netstack/netstack.c
index 296fee2..55b716a 100644
--- a/src/user/app/netstack/netstack.c
+++ b/src/user/app/netstack/netstack.c
@@ -26,8 +26,6 @@ void network_thread(void *arg) { (void)arg;
void fs_thread(void *arg);
-__attribute__((visibility("hidden")))
-extern char _image_base[];
int main(int argc, char **argv) {
if (argc < 4) {
eprintf("usage: netstack iface ip gateway");
diff --git a/src/user/app/tests/tests.c b/src/user/app/tests/tests.c
index 2cb97cd..5cba682 100644
--- a/src/user/app/tests/tests.c
+++ b/src/user/app/tests/tests.c
@@ -3,7 +3,7 @@
#include <unistd.h>
__attribute__((visibility("hidden")))
-extern char _image_base[];
+extern char __executable_start[];
FILE *fail_trig;
@@ -15,7 +15,7 @@ void run_test(void (*fn)()) {
} else {
/* successful tests must return 0 */
if (_sys_await() != 0) {
- test_failf("%p, base %p", (void*)((void*)fn - (void*)_image_base), _image_base);
+ test_failf("%p, base %p", (void*)((void*)fn - (void*)__executable_start), __executable_start);
}
}
}
diff --git a/src/user/lib/_start2.c b/src/user/lib/_start2.c
index 954fcb4..f55feab 100644
--- a/src/user/lib/_start2.c
+++ b/src/user/lib/_start2.c
@@ -10,7 +10,7 @@
int main(int argc, char **argv, char **envp);
__attribute__((visibility("hidden")))
-extern char _image_base[];
+extern char __executable_start[];
const char *shortname(const char *path) {
if (!path) return "unknown program";
@@ -39,7 +39,7 @@ _Noreturn void _start2(struct execdata *ed) {
progname = shortname(ed->argv[0]);
setprogname(progname);
- _klogf("_start2 %s %p", progname, _image_base);
+ _klogf("_start2 %s %p", progname, __executable_start);
exit(main(ed->argc, ed->argv, ed->envp));
}
diff --git a/src/user/lib/elfreloc.c b/src/user/lib/elfreloc.c
index cf740f5..632f60f 100644
--- a/src/user/lib/elfreloc.c
+++ b/src/user/lib/elfreloc.c
@@ -5,7 +5,7 @@ __attribute__((visibility("hidden")))
extern struct Elf64_Dyn _DYNAMIC[];
__attribute__((visibility("hidden")))
-extern char _image_base[];
+extern char __executable_start[];
static struct Elf64_Dyn *dyn_gettag(Elf64_Xword tag) {
for (size_t i = 0;; i++) {
@@ -27,12 +27,12 @@ void elf_selfreloc(void) {
size_t relasz = dyn_gettag(DT_RELASZ)->d_val;
size_t relaent = dyn_gettag(DT_RELAENT)->d_val;
for (size_t o = 0; o < relasz; o += relaent) {
- struct Elf64_Rela *r = (void*)_image_base + rela_tag->d_ptr + o;
- uintptr_t *target = (void*)_image_base + r->r_offset;
+ struct Elf64_Rela *r = (void*)__executable_start + rela_tag->d_ptr + o;
+ uintptr_t *target = (void*)__executable_start + r->r_offset;
switch (ELF64_R_TYPE(r->r_info)) {
case R_X86_64_RELATIVE:
- *target = (uintptr_t)&_image_base + r->r_addend;
+ *target = (uintptr_t)&__executable_start + r->r_addend;
break;
default:
_klogf("elf: unsupported relocation type\n");
diff --git a/src/user/lib/include/limits.h b/src/user/lib/include/limits.h
index 065f8e0..3d74ded 100644
--- a/src/user/lib/include/limits.h
+++ b/src/user/lib/include/limits.h
@@ -1,5 +1,5 @@
#pragma once
-#include_next <limits.h>
#include <camellia/path.h> // just for PATH_MAX
+// #include_next <limits.h>
#define _POSIX2_RE_DUP_MAX 255
diff --git a/src/user/linker.ld b/src/user/linker.ld
index e638289..4925448 100644
--- a/src/user/linker.ld
+++ b/src/user/linker.ld
@@ -2,7 +2,7 @@ ENTRY(_start)
SECTIONS
{
- _image_base = .;
+ __executable_start = .;
.text BLOCK(4K) : ALIGN(4K)
{
*(.text)
diff --git a/sysroot/usr/include b/sysroot/usr/include
new file mode 120000
index 0000000..e7f2ad7
--- /dev/null
+++ b/sysroot/usr/include
@@ -0,0 +1 @@
+../../src/user/lib/include \ No newline at end of file
diff --git a/sysroot/usr/local/include b/sysroot/usr/local/include
new file mode 120000
index 0000000..09eec1e
--- /dev/null
+++ b/sysroot/usr/local/include
@@ -0,0 +1 @@
+../../../src/shared/include \ No newline at end of file
diff --git a/sysroot_alt/usr/include/limits.h b/sysroot_alt/usr/include/limits.h
new file mode 100644
index 0000000..d433a99
--- /dev/null
+++ b/sysroot_alt/usr/include/limits.h
@@ -0,0 +1,3 @@
+/* If this file isn't here, gcc fails trying to find limits.h in an nonexisting
+ * sysroot. As far as I can tell I can't just get it to chill out with command
+ * line arguments, so I need to make up a whole fake sysroot with a fake limits.h */
diff --git a/toolchain/gcc b/toolchain/gcc
-Subproject 9305ddf4b1e9b125abe13365b9c55775cc328d7
+Subproject a508774654ed884b0443c8df069ffb5605cd30b
diff --git a/tools/dep_builders/binutils b/tools/dep_builders/binutils
index 3e6b7b7..42dd04b 100755
--- a/tools/dep_builders/binutils
+++ b/tools/dep_builders/binutils
@@ -19,8 +19,9 @@ cd $BUILDDIR
../binutils/configure \
--target=x86_64-camellia \
--prefix="$PREFIX" \
- --with-sysroot \
+ --with-sysroot="$SYSROOT" \
--disable-nls \
--disable-werror
+mkdir -p gas/doc/ # stupid workaround for the broken build
make -j4
make install
diff --git a/tools/dep_builders/gcc b/tools/dep_builders/gcc
index 302bfdc..f3e72a0 100755
--- a/tools/dep_builders/gcc
+++ b/tools/dep_builders/gcc
@@ -19,9 +19,10 @@ cd $BUILDDIR
../gcc/configure \
--target=x86_64-camellia \
--prefix="$PREFIX" \
- --disable-nls \
- --without-headers \
+ --with-sysroot="$SYSROOT" \
--enable-languages=c,c++ \
+ --disable-nls \
+ --disable-gcov \
--disable-werror
make -j4 all-gcc
make -j4 all-target-libgcc