Skip to content

Commit 2fc9e68

Browse files
sertonixLorenz (xha)
authored andcommitted
OpenBSD: fix tests
Co-authored-by: Lorenz (xha) <[email protected]> Signed-off-by: Sertonix <[email protected]>
1 parent 674f9b2 commit 2fc9e68

23 files changed

+218
-571
lines changed

configs/openbsd.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BINDIR = $(PREFIX)/bin
55
# variables used during build
66
PLATFORM = openbsd
77
ARCH = x86_64
8-
HARECFLAGS =
8+
HARECFLAGS = -N "" -m .main
99
QBEFLAGS =
1010
ASFLAGS =
1111
LDLINKFLAGS = -z nobtcfi
@@ -18,7 +18,7 @@ LIBS = -lm
1818
CC = cc
1919
# OpenBSD: gas is in the binutils package. as from the base system is too old.
2020
AS = gas
21-
LD = ld
21+
LD = cc
2222
QBE = qbe
2323

2424
# build locations

makefiles/freebsd.mk

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
RTSCRIPT = rt/hare.sc
22

3-
_rt_ha = rt/+$(PLATFORM)/syscallno.ha
3+
_rt_ha = \
4+
rt/malloc.ha \
5+
rt/+$(PLATFORM)/syscallno.ha \
6+
rt/+$(PLATFORM)/segmalloc.ha
7+
8+
_rt_s = \
9+
rt/+$(PLATFORM)/start+$(ARCH).s \
10+
rt/+$(PLATFORM)/syscall+$(ARCH).s

makefiles/linux.mk

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
RTSCRIPT = rt/hare.sc
22

3-
_rt_ha = rt/+$(PLATFORM)/syscallno+$(ARCH).ha
3+
_rt_ha = \
4+
rt/malloc.ha \
5+
rt/+$(PLATFORM)/syscallno+$(ARCH).ha \
6+
rt/+$(PLATFORM)/segmalloc.ha
7+
8+
_rt_s = \
9+
rt/+$(PLATFORM)/start+$(ARCH).s \
10+
rt/+$(PLATFORM)/syscall+$(ARCH).s

makefiles/netbsd.mk

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
RTSCRIPT = rt/hare+$(PLATFORM).sc
22

3-
_rt_ha = rt/+$(PLATFORM)/syscallno.ha
3+
_rt_ha = \
4+
rt/malloc.ha \
5+
rt/+$(PLATFORM)/syscallno.ha \
6+
rt/+$(PLATFORM)/segmalloc.ha
7+
8+
_rt_s = \
9+
rt/+$(PLATFORM)/start+$(ARCH).s \
10+
rt/+$(PLATFORM)/syscall+$(ARCH).s

makefiles/openbsd.mk

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
RTSCRIPT = rt/hare+$(PLATFORM).sc
22

3-
_rt_ha = rt/+$(PLATFORM)/syscallno.ha
3+
_rt_ha = \
4+
rt/malloc+libc.ha
5+
6+
_rt_s = \
7+
rt/+openbsd/platformstart.s

makefiles/tests.mk

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,21 @@ rt_ha = \
2424
rt/compile.ha \
2525
rt/cstrings.ha \
2626
rt/ensure.ha \
27-
rt/malloc.ha \
2827
rt/memcpy.ha \
2928
rt/memmove.ha \
3029
rt/memset.ha \
31-
rt/rtmain.ha \
3230
rt/strcmp.ha \
3331
rt/+$(PLATFORM)/errno.ha \
34-
rt/+$(PLATFORM)/segmalloc.ha \
3532
rt/+$(PLATFORM)/syscalls.ha \
33+
rt/+$(PLATFORM)/start.ha \
3634
$(_rt_ha)
3735

3836
$(HARECACHE)/rt.ssa: $(rt_ha)
3937
@mkdir -p -- $(HARECACHE)
4038
@printf 'HAREC\t%s\n' '$@'
4139
@$(TDENV) $(BINOUT)/harec $(HARECFLAGS) -o $@ -t $(HARECACHE)/rt.td.tmp -N rt $(rt_ha)
4240

43-
rt_s = $(HARECACHE)/rt.s rt/+$(PLATFORM)/start+$(ARCH).s rt/+$(PLATFORM)/syscall+$(ARCH).s
41+
rt_s = $(HARECACHE)/rt.s $(_rt_s)
4442
$(HARECACHE)/rt.o: $(rt_s)
4543
@printf 'AS\t%s\n' '$@'
4644
@$(AS) $(ASFLAGS) -o $@ $(rt_s)

rt/rtmain.ha rt/+freebsd/start.ha

File renamed without changes.

rt/+linux/start.ha

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@symbol("main") fn main() void;
2+
3+
const @symbol("__init_array_start") init_start: [*]*fn() void;
4+
const @symbol("__init_array_end") init_end: [*]*fn() void;
5+
const @symbol("__fini_array_start") fini_start: [*]*fn() void;
6+
const @symbol("__fini_array_end") fini_end: [*]*fn() void;
7+
8+
let argc: size = 0;
9+
let argv: *[*]*const u8 = null: *[*]*const u8;
10+
let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
11+
12+
export let status = 0;
13+
14+
export fn start_ha(iv: *[*]uintptr) never = {
15+
const ninit = (&init_end: uintptr - &init_start: uintptr): size
16+
/ size(*fn() void);
17+
for (let i = 0z; i < ninit; i += 1) {
18+
init_start[i]();
19+
};
20+
21+
argc = iv[0]: size;
22+
argv = &iv[1]: *[*]*const u8;
23+
envp = &argv[argc + 1]: *[*]nullable *const u8;
24+
25+
main();
26+
27+
const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
28+
/ size(*fn() void);
29+
for (let i = 0z; i < nfini; i += 1) {
30+
fini_start[i]();
31+
};
32+
33+
exit(status);
34+
};

rt/+netbsd/start.ha

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@symbol("main") fn main() void;
2+
3+
const @symbol("__init_array_start") init_start: [*]*fn() void;
4+
const @symbol("__init_array_end") init_end: [*]*fn() void;
5+
const @symbol("__fini_array_start") fini_start: [*]*fn() void;
6+
const @symbol("__fini_array_end") fini_end: [*]*fn() void;
7+
8+
let argc: size = 0;
9+
let argv: *[*]*const u8 = null: *[*]*const u8;
10+
let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
11+
12+
export let status = 0;
13+
14+
export fn start_ha(iv: *[*]uintptr) never = {
15+
const ninit = (&init_end: uintptr - &init_start: uintptr): size
16+
/ size(*fn() void);
17+
for (let i = 0z; i < ninit; i += 1) {
18+
init_start[i]();
19+
};
20+
21+
argc = iv[0]: size;
22+
argv = &iv[1]: *[*]*const u8;
23+
envp = &argv[argc + 1]: *[*]nullable *const u8;
24+
25+
main();
26+
27+
const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
28+
/ size(*fn() void);
29+
for (let i = 0z; i < nfini; i += 1) {
30+
fini_start[i]();
31+
};
32+
33+
exit(status);
34+
};

rt/+openbsd/platformstart.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.section ".preinit_array"
2+
.balign 8
3+
.init.initfunc.0:
4+
.quad preinit_hare+0

rt/+openbsd/segmalloc.ha

-10
This file was deleted.

rt/+openbsd/start+aarch64.s

-8
This file was deleted.

rt/+openbsd/start+riscv64.s

-6
This file was deleted.

rt/+openbsd/start+x86_64.s

-16
This file was deleted.

rt/+openbsd/start.ha

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// (c) Hare authors <https://harelang.org>
3+
4+
let argc: size = 0;
5+
let argv: *[*]*const u8 = null: *[*]*const u8;
6+
let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
7+
8+
export let status = 0;
9+
10+
// The real main function.
11+
@symbol(".main") fn main() void;
12+
13+
// The setup of envp and args is done here. This is called by crt0 before
14+
// normal init functions are called.
15+
export @symbol("preinit_hare") fn preinit_hare(
16+
c_argc: int,
17+
c_argv: *[*]*const u8,
18+
c_envp: *[*]nullable *const u8
19+
) void = {
20+
argc = c_argc: size;
21+
argv = c_argv;
22+
envp = c_envp;
23+
};
24+
25+
// The purpose of this "fake" main function is to make sure we exit with the
26+
// correct exit code in the case that rt::exit() is not called from within the
27+
// program. The intilization and finilization functions are not run from here,
28+
// they are ran by crt0.
29+
export @symbol("main") fn _main() void = {
30+
main();
31+
exit(status);
32+
};

rt/+openbsd/syscall+aarch64.s

-69
This file was deleted.

rt/+openbsd/syscall+riscv64.s

-69
This file was deleted.

0 commit comments

Comments
 (0)