hare

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

commit 8a6c36e901acecc4c648fa97c3c7b19d253cae59
parent 3e04a9a48507f608097a38873a42ca5b5f1206d2
Author: Lorenz (xha) <me@xha.li>
Date:   Sat, 25 Nov 2023 15:18:04 +0100

cmd::hare: introduce ctx.libc

Signed-off-by: Lorenz (xha) <me@xha.li>

Diffstat:
Mcmd/hare/build.ha | 3++-
Mcmd/hare/build/types.ha | 2++
Mcmd/hare/build/util.ha | 14+++++++-------
3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/cmd/hare/build.ha b/cmd/hare/build.ha @@ -142,7 +142,8 @@ fn build(name: str, cmd: *getopt::command) (void | error) = { os::tryenv("LD", arch.ld_cmd), ]; set_arch_tags(&ctx.ctx.tags, arch); - if (len(ctx.libs) > 0) { + if (len(ctx.libs) > 0 || ctx.platform.need_libc) { + ctx.libc = true; merge_tags(&ctx.ctx.tags, "+libc")?; ctx.cmds[build::stage::BIN] = os::tryenv("CC", arch.cc_cmd); }; diff --git a/cmd/hare/build/types.ha b/cmd/hare/build/types.ha @@ -72,6 +72,8 @@ export type context = struct { submods: bool, // if true, the main function won't be checked by harec freestanding: bool, + // if true, we are linking with libc (using cc instead of ld) + libc: bool, cmds: [NSTAGES]str, diff --git a/cmd/hare/build/util.ha b/cmd/hare/build/util.ha @@ -86,7 +86,7 @@ fn get_flags(ctx: *context, t: *task) ([]str | error) = { case stage::O => yield "ASFLAGS"; case stage::BIN => - yield if (len(ctx.libs) > 0) "LDFLAGS" else "LDLINKFLAGS"; + yield if (ctx.libc) "LDFLAGS" else "LDLINKFLAGS"; }; match (shlex::split(os::tryenv(flags_env, ""))) { case let s: []str => @@ -110,12 +110,12 @@ fn get_flags(ctx: *context, t: *task) ([]str | error) = { append(flags, strings::dup("-L")); append(flags, strings::dup(ctx.libdirs[i])); }; - if (len(ctx.libs) == 0) { + if (ctx.libc) { + append(flags, strings::dup("-Wl,--gc-sections")); + } else { append(flags, strings::dup("--gc-sections")); append(flags, strings::dup("-z")); append(flags, strings::dup("noexecstack")); - } else { - append(flags, strings::dup("-Wl,--gc-sections")); }; return flags; }; @@ -124,14 +124,14 @@ fn get_flags(ctx: *context, t: *task) ([]str | error) = { if (len(ctx.ns) != 0 && t.idx == ctx.top) { append(flags, strings::dup("-N")); append(flags, unparse::identstr(ctx.ns)); - } else if (len(mod.ns) != 0 || len(ctx.libs) != 0) { + } else if (len(mod.ns) != 0 || ctx.libc) { append(flags, strings::dup("-N")); append(flags, unparse::identstr(mod.ns)); }; if (ctx.freestanding) { append(flags, strings::dup("-m")); append(flags, ""); - } else if (len(ctx.libs) != 0) { + } else if (ctx.libc) { append(flags, strings::dup("-m.main")); }; append(flags, strings::dup("-M")); @@ -258,7 +258,7 @@ fn get_args(ctx: *context, tmp: str, flags: []str, t: *task) []str = { append(args, strings::dup(srcs.o[i])); }; }; - if (len(ctx.libs) > 0) { + if (ctx.libc) { append(args, strings::dup("-Wl,--no-gc-sections")); }; for (let i = 0z; i < len(ctx.libs); i += 1) {