harec

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

commit 0b4d9df6e0219b0fdb099f745e4319ed2c628e13
parent f861e7f3e0d47772d63a1a111e435daec26bd400
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 11 Feb 2021 11:31:10 -0500

Implement equiv. of -ffunction-sections

Diffstat:
Mrt/hare.sc | 49+++++++++++++++++++++++++++++--------------------
Msrc/emit.c | 6+++++-
Mtests/configure | 2+-
3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/rt/hare.sc b/rt/hare.sc @@ -1,26 +1,35 @@ SECTIONS { - . = 0x10000; - .text : { *(.text) } - . = 0x8000000; - .data : { *(.data) } + . = 0x10000; + .text : { + KEEP (*(.text)) + *(.text.*) + } + . = 0x8000000; + .data : { + KEEP (*(.data)) + *(.data.*) + } - .init_array : { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - } + .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 = .); - } + .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 = .); - } + .test_array : { + PROVIDE_HIDDEN (__test_array_start = .); + KEEP (*(.test_array)) + PROVIDE_HIDDEN (__test_array_end = .); + } - .bss : { *(.bss) } + .bss : { + KEEP (*(.bss)) + *(.bss.*) + } } diff --git a/src/emit.c b/src/emit.c @@ -174,7 +174,9 @@ static void emit_func(struct qbe_def *def, FILE *out) { assert(def->kind == Q_FUNC); - fprintf(out, "%sfunction", def->exported ? "export " : ""); + fprintf(out, "%sfunction section \".text.%s\" \"ax\"", + def->exported ? "export " : "", + def->name); if (def->func.returns->stype != Q__VOID) { fprintf(out, " "); emit_qtype(def->func.returns, true, out); @@ -241,6 +243,8 @@ emit_data(struct qbe_def *def, FILE *out) def->data.section, def->data.secflags); } else if (def->data.section) { fprintf(out, "section \"%s\" ", def->data.section); + } else { + fprintf(out, "section \".data.%s\" ", def->name); } fprintf(out, "$%s = { ", def->name); diff --git a/tests/configure b/tests/configure @@ -32,7 +32,7 @@ tests/$t: libhart.a tests/$t.ha @HARECACHE=\$(HARECACHE) ./harec -o tests/$t.ssa tests/$t.ha @\$(QBE) -o tests/$t.s tests/$t.ssa @\$(AS) -o tests/$t.o tests/$t.s - @\$(LD) -T rt/hare.sc -o tests/$t $rtstart tests/$t.o libhart.a + @\$(LD) --gc-sections -T rt/hare.sc -o tests/$t $rtstart tests/$t.o libhart.a @rm tests/$t.s tests/$t.ssa tests/$t.o check: tests/$t