harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e35dfedfc91e1211bac026e16a174836958bada1
parent 9e4e4d40ca274f1dc50e87700b291b6a35833890
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  4 Feb 2021 11:53:55 -0500

docs/runtime.txt: detail @test support

Diffstat:
Mdocs/runtime.txt | 20++++++++++++++++++++
Art/hare.sc | 26++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/docs/runtime.txt b/docs/runtime.txt @@ -24,3 +24,23 @@ globals available to the current unit: The runtime must call each initialization function, then call the `main` function (of type `fn() void`), then call all of the finalization functions, before terminating the program normally. + +When building with +test (harec -T +test), @test functions will be emitted, and +an ELF section, .test_array, will be populated similarly to init_array. The +startup code can enumerate the available tests like so: + + type test = struct { + name: str, + func: *fn() void, + }; + + const @symbol("__test_array_start") test_start: [*]test; + const @symbol("__test_array_end") test_end: [*]test; + +In order to use these symbols, a custom linker script must be used. A sample is +provided in rt/hare.sc which is compatible with GNU's ld and LLVM's lld. + +It is expected that, when built in +test mode, the runtime will execute these +test functions instead of calling main. Under these conditions, the runtime is +still expected to call the @init and @fini functions as well, respectively +before and after running the tests. diff --git a/rt/hare.sc b/rt/hare.sc @@ -0,0 +1,26 @@ +SECTIONS { + . = 0x10000; + .text : { *(.text) } + . = 0x8000000; + .data : { *(.data) } + + .init_array : { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + + .fini_array : { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + } + + .test_array : { + PROVIDE_HIDDEN (__test_array_start = .); + KEEP (*(.test_array)) + PROVIDE_HIDDEN (__test_array_end = .); + } + + .bss : { *(.bss) } +}