hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 72f7faaf96f289b8a1e420a257ee631fc087de0e
parent 228884adc643282a7811d86ce53c0a6f6c971d20
Author: Alexey Yerin <yyp@disroot.org>
Date:   Tue, 14 Sep 2021 21:39:00 +0300

cmd/hare: move archive files to the end of ld command

Fixes issues with linking when an archive is scheduled too early.

>From ld manual: "The linker will search an archive only once, at the
location where it is specified on the command line. If the archive
defines a symbol which was undefined in some object which appeared
before the archive on the command line, the linker will include the
appropriate file(s) from the archive."

To get symbols from archive to all other objects, archives must be
placed after everything else.

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mcmd/hare/schedule.ha | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -70,9 +70,18 @@ fn sched_ld(plan: *plan, output: str, depend: *task...) *task = { "-o", output, ]), }); + + let archives: []str = []; + defer free(archives); + for (let i = 0z; i < len(depend); i += 1) { - append(task.cmd, depend[i].output); + if (strings::has_suffix(depend[i].output, ".a")) { + append(archives, depend[i].output); + } else { + append(task.cmd, depend[i].output); + }; }; + append(task.cmd, archives...); append(plan.scheduled, task); return task; };