commit c6c3fef5166e4061cab5a5959cfc7e10fc069def
parent a135713defeb03f4aca798cc4257b0f66efdae97
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Wed, 3 Jun 2026 11:18:42 -0700
obj/link: single-source no-location as SRCLOC_NONE; drop 22 no_loc() copies
Replace the per-TU `static SrcLoc no_loc(void)` helper (duplicated verbatim
across 22 obj/ and link/ writers) with one SRCLOC_NONE macro in core/core.h.
Mechanical: 397 call sites rewritten, 22 definitions removed.
Diffstat:
23 files changed, 402 insertions(+), 513 deletions(-)
diff --git a/src/api/compile.c b/src/api/compile.c
@@ -54,16 +54,8 @@ const KitFrontendVTable kit_asm_frontend_vtable = {
NULL, /* free_options */
};
-static SrcLoc no_loc(void) {
- SrcLoc loc;
- loc.file_id = 0;
- loc.line = 0;
- loc.col = 0;
- return loc;
-}
-
static _Noreturn void panic_bad_options(Compiler* c, const char* msg) {
- compiler_panic(c, no_loc(), "bad kit options: %.*s",
+ compiler_panic(c, SRCLOC_NONE, "bad kit options: %.*s",
SLICE_ARG(slice_from_cstr(msg)));
}
diff --git a/src/core/core.h b/src/core/core.h
@@ -45,6 +45,11 @@ typedef u32 BytesId;
typedef KitSrcLoc SrcLoc;
+// Canonical "no source location" — single source of truth. Replaces the
+// per-TU `static SrcLoc no_loc(void)` helpers formerly duplicated across the
+// obj/ and link/ writers (used mostly as the location arg to compiler_panic).
+#define SRCLOC_NONE ((SrcLoc){0, 0, 0})
+
typedef struct SrcRange {
SrcLoc begin;
SrcLoc end;
diff --git a/src/emu/emu.c b/src/emu/emu.c
@@ -55,14 +55,6 @@ struct KitEmu {
int exit_code;
};
-static SrcLoc no_loc(void) {
- SrcLoc l;
- l.file_id = 0;
- l.line = 0;
- l.col = 0;
- return l;
-}
-
/* The block function call ABI: u64 entry(EmuThread*). Cast through
* a typedef so the call site reads cleanly in the dispatcher. */
typedef u64 (*EmuBlockFn)(EmuThread*);
@@ -251,7 +243,7 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
heap = c->ctx->heap;
e = (KitEmu*)heap->alloc(heap, sizeof(*e), _Alignof(KitEmu));
- if (!e) compiler_panic(c, no_loc(), "emu: out of memory");
+ if (!e) compiler_panic(c, SRCLOC_NONE, "emu: out of memory");
memset(e, 0, sizeof(*e));
e->c = c;
e->opt_level = opts->optimize;
@@ -265,7 +257,7 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
st = emu_resolve_config(c, opts, &resolved);
if (st != KIT_OK) {
- compiler_panic(c, no_loc(), "emu: unsupported guest executable");
+ compiler_panic(c, SRCLOC_NONE, "emu: unsupported guest executable");
}
e->guest_target = resolved.target;
@@ -303,24 +295,24 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
if (resolved.os->emu_init_process_private &&
resolved.os->emu_init_process_private(c, &e->process) != KIT_OK) {
- compiler_panic(c, no_loc(), "emu: failed to initialize OS process state");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to initialize OS process state");
}
if (resolved.os->emu_init_thread_private &&
resolved.os->emu_init_thread_private(c, &e->process, &e->main_thread) !=
KIT_OK) {
- compiler_panic(c, no_loc(), "emu: failed to initialize OS thread state");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to initialize OS thread state");
}
/* 1. Load the guest executable through the object-format emu hook. */
st = resolved.obj_format->emu->load_executable(c, &load_opts,
&e->process.image);
if (st != KIT_OK) {
- compiler_panic(c, no_loc(), "emu: failed to load guest executable");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to load guest executable");
}
if (resolved.os->emu_init_process &&
resolved.os->emu_init_process(c, &e->process, &load_opts,
&e->process.image) != KIT_OK) {
- compiler_panic(c, no_loc(), "emu: failed to initialize guest process");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to initialize guest process");
}
/* 2. Allocate per-thread CPU state and seed PC/SP. */
@@ -332,7 +324,7 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
(resolved.os->emu_init_thread &&
resolved.os->emu_init_thread(c, &e->process, &e->main_thread) !=
KIT_OK)) {
- compiler_panic(c, no_loc(), "emu: failed to initialize guest CPU state");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to initialize guest CPU state");
}
/* 3. In INTERP mode, attach an interp sink so each translated block is also
@@ -347,7 +339,7 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
KitInterpHost ihost;
e->interp_prog = kit_interp_program_new((KitCompiler*)c);
if (!e->interp_prog)
- compiler_panic(c, no_loc(), "emu: failed to create interpreter program");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to create interpreter program");
kit_interp_program_attach(e->interp_prog, (KitCompiler*)c);
memset(&ihost, 0, sizeof(ihost));
ihost.resolve_sym = emu_runtime_extern_resolver;
@@ -355,11 +347,11 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) {
kit_interp_program_set_host(e->interp_prog, &ihost);
e->interp_stack = kit_interp_stack_new(e->interp_prog);
if (!e->interp_stack)
- compiler_panic(c, no_loc(), "emu: failed to create interpreter stack");
+ compiler_panic(c, SRCLOC_NONE, "emu: failed to create interpreter stack");
}
#else
if (e->mode == KIT_EMU_MODE_INTERP)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emu: interpreter mode not enabled in this build");
#endif
@@ -412,7 +404,7 @@ static void emu_keep_jit(KitEmu* e, KitJit* jit) {
KitJit** grown =
(KitJit**)heap->realloc(heap, e->jits, sizeof(*e->jits) * old_cap,
sizeof(*e->jits) * new_cap, _Alignof(KitJit*));
- if (!grown) compiler_panic(e->c, no_loc(), "emu: out of memory");
+ if (!grown) compiler_panic(e->c, SRCLOC_NONE, "emu: out of memory");
e->jits = grown;
e->jits_cap = new_cap;
}
@@ -460,7 +452,7 @@ static void* translate_block(KitEmu* e, u64 guest_pc) {
heap = e->c->ctx->heap;
insts = (KitDecodedInsn*)heap->alloc(
heap, sizeof(*insts) * EMU_MAX_INSTS_PER_BLOCK, _Alignof(KitDecodedInsn));
- if (!insts) compiler_panic(e->c, no_loc(), "emu: out of memory");
+ if (!insts) compiler_panic(e->c, SRCLOC_NONE, "emu: out of memory");
st = arch->decode->decode_block(e->c, host_pc, decode_len, guest_pc, insts,
EMU_MAX_INSTS_PER_BLOCK, &ninsts);
if (st != KIT_OK || ninsts == 0) {
@@ -481,7 +473,7 @@ static void* translate_block(KitEmu* e, u64 guest_pc) {
st = kit_cg_new(e->c, &cg);
if (st == KIT_OK) st = kit_cg_begin_obj(cg, (KitObjBuilder*)ob, &copts);
if (st != KIT_OK || !cg)
- compiler_panic(e->c, no_loc(), "emu: kit_cg_new failed");
+ compiler_panic(e->c, SRCLOC_NONE, "emu: kit_cg_new failed");
block_name = emu_block_sym_name(e->c, guest_pc);
memset(&block_decl, 0, sizeof(block_decl));
@@ -494,7 +486,7 @@ static void* translate_block(KitEmu* e, u64 guest_pc) {
block_decl.sym.visibility = KIT_CG_VIS_DEFAULT;
block_sym = kit_cg_decl(cg, block_decl);
if (block_sym == KIT_CG_SYM_NONE)
- compiler_panic(e->c, no_loc(), "emu: failed to declare block symbol");
+ compiler_panic(e->c, SRCLOC_NONE, "emu: failed to declare block symbol");
memset(&ctx, 0, sizeof(ctx));
ctx.compiler = e->c;
@@ -507,11 +499,11 @@ static void* translate_block(KitEmu* e, u64 guest_pc) {
st = arch->emu->lift_block(e->c, cg, insts, ninsts, &ctx);
heap->free(heap, insts, sizeof(*insts) * EMU_MAX_INSTS_PER_BLOCK);
insts = NULL;
- if (st != KIT_OK) compiler_panic(e->c, no_loc(), "emu: failed to lift block");
+ if (st != KIT_OK) compiler_panic(e->c, SRCLOC_NONE, "emu: failed to lift block");
st = kit_cg_end_obj(cg);
if (st != KIT_OK)
- compiler_panic(e->c, no_loc(), "emu: kit_cg_end_obj failed");
+ compiler_panic(e->c, SRCLOC_NONE, "emu: kit_cg_end_obj failed");
kit_cg_free(cg);
obj_finalize(ob);
@@ -529,7 +521,7 @@ static void* translate_block(KitEmu* e, u64 guest_pc) {
if (st == KIT_OK) st = kit_link_session_jit(sess, &jit);
if (sess) kit_link_session_free(sess);
if (st != KIT_OK || !jit)
- compiler_panic(e->c, no_loc(), "emu: failed to publish JIT block");
+ compiler_panic(e->c, SRCLOC_NONE, "emu: failed to publish JIT block");
entry = kit_jit_lookup(jit, *(KitSlice*)&block_slice);
if (!entry) {
@@ -618,14 +610,14 @@ static u64 emu_interp_run_block(KitEmu* e, KitInterpFunc* ifn,
kit_interp_stack_reset(e->interp_stack);
if (kit_interp_call_args_on(e->interp_stack, ifn, &arg, 1u) != KIT_OK)
- compiler_panic(e->c, no_loc(), "emu: failed to seed interpreter frame");
+ compiler_panic(e->c, SRCLOC_NONE, "emu: failed to seed interpreter frame");
s = kit_interp_resume(e->interp_stack, &ret);
if (s == KIT_INTERP_DONE) return (u64)ret;
{
const char* why = kit_interp_stack_trap_reason(e->interp_stack);
- compiler_panic(e->c, no_loc(),
+ compiler_panic(e->c, SRCLOC_NONE,
"emu: cannot interpret block at guest_pc=0x%llx: %s",
(unsigned long long)emu_cpu_pc(thread->cpu),
why ? why : "unsupported operation");
@@ -664,7 +656,7 @@ KitStatus kit_emu_step(KitEmu* e, uint32_t nblocks) {
entry = kit_emu_lookup(e, pc);
if (!entry) {
- compiler_panic(e->c, no_loc(),
+ compiler_panic(e->c, SRCLOC_NONE,
"emu: failed to translate block at guest_pc=0x%llx",
(unsigned long long)pc);
}
@@ -685,7 +677,7 @@ KitStatus kit_emu_step(KitEmu* e, uint32_t nblocks) {
e->done = 1;
e->exit_code = emu_cpu_exit_code(cpu);
} else if (trap == EMU_TRAP_FAULT) {
- compiler_panic(e->c, no_loc(), "emu: guest faulted at pc=0x%llx",
+ compiler_panic(e->c, SRCLOC_NONE, "emu: guest faulted at pc=0x%llx",
(unsigned long long)next_pc);
}
}
diff --git a/src/link/link.c b/src/link/link.c
@@ -26,11 +26,6 @@
/* ---- SrcLoc helper ---- */
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* SymHash is a HASHMAP_DEFINE instance — see link_internal.h. The thin
* symhash_* wrappers there preserve the historic insert-if-absent / by-
* value get API. */
@@ -103,7 +98,7 @@ void link_free(Linker* l) {
static LinkInput* inputs_push(Linker* l, LinkInputId* id_out) {
u32 idx;
LinkInput* in = LinkInputs_push(&l->inputs, &idx);
- if (!in) compiler_panic(l->c, no_loc(), "link: out of memory growing inputs");
+ if (!in) compiler_panic(l->c, SRCLOC_NONE, "link: out of memory growing inputs");
*id_out = (LinkInputId)(idx + 1u);
in->id = *id_out;
return in;
@@ -133,7 +128,7 @@ LinkInputId link_add_obj_bytes(Linker* l, const char* name, const u8* data,
impl = obj_format_lookup_bin(fmt);
if (!impl || !impl->read)
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_obj_bytes: unsupported object format "
"(fmt=%u) for '%.*s'",
(u32)fmt,
@@ -142,7 +137,7 @@ LinkInputId link_add_obj_bytes(Linker* l, const char* name, const u8* data,
ob = impl->read(l->c, name, data, len);
if (!ob)
compiler_panic(
- l->c, no_loc(), "link_add_obj_bytes: %.*s returned NULL for '%.*s'",
+ l->c, SRCLOC_NONE, "link_add_obj_bytes: %.*s returned NULL for '%.*s'",
SLICE_ARG(slice_from_cstr(reader_name)),
SLICE_ARG(name ? slice_from_cstr(name) : SLICE_LIT("(unnamed)")));
in = inputs_push(l, &id);
@@ -174,7 +169,7 @@ LinkInputId link_add_dso_bytes(Linker* l, const char* name, const u8* data,
if (!l || !data || !len) return LINK_INPUT_NONE;
if (!obj_format_dso_reader_for_bytes(data, len, &fmt, &reader))
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_dso_bytes: unsupported DSO format "
"(fmt=%u) for '%.*s'",
(u32)fmt,
@@ -183,7 +178,7 @@ LinkInputId link_add_dso_bytes(Linker* l, const char* name, const u8* data,
ob = reader.read(l->c, name, data, len, &soname);
if (!ob)
compiler_panic(
- l->c, no_loc(), "link_add_dso_bytes: %.*s returned NULL for '%.*s'",
+ l->c, SRCLOC_NONE, "link_add_dso_bytes: %.*s returned NULL for '%.*s'",
SLICE_ARG(slice_from_cstr(reader_name)),
SLICE_ARG(name ? slice_from_cstr(name) : SLICE_LIT("(unnamed)")));
in = inputs_push(l, &id);
@@ -229,7 +224,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
if (kit_ar_iter_new(kit_compiler_context(l->c), &in_arc, &it) != KIT_OK ||
!it)
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_archive_bytes: '%.*s' is not a valid ar archive",
SLICE_ARG(name ? slice_from_cstr(name) : SLICE_LIT("(unnamed)")));
@@ -243,7 +238,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
ar = LinkArchives_push(&l->archives, NULL);
if (!ar)
- compiler_panic(l->c, no_loc(), "link: out of memory growing archives");
+ compiler_panic(l->c, SRCLOC_NONE, "link: out of memory growing archives");
ar->name = name ? pool_intern_slice(l->c->global, slice_from_cstr(name)) : 0;
ar->order = l->next_input_order++;
ar->whole_archive = whole_archive;
@@ -255,7 +250,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
_Alignof(LinkArchiveMember))
: NULL;
if (n && !ar->members)
- compiler_panic(l->c, no_loc(), "link: oom on archive members");
+ compiler_panic(l->c, SRCLOC_NONE, "link: oom on archive members");
if (n) memset(ar->members, 0, sizeof(*ar->members) * n);
/* Pass 2: parse each member as object. ar.c's iterator skips the
@@ -266,7 +261,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
if (kit_ar_iter_new(kit_compiler_context(l->c), &in_arc, &it) != KIT_OK ||
!it)
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_archive_bytes: ar_iter_init failed on '%.*s' "
"second pass",
SLICE_ARG(name ? slice_from_cstr(name) : SLICE_LIT("(unnamed)")));
@@ -296,7 +291,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
}
if (!member_impl || !member_impl->read)
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_archive_bytes: unsupported member "
"format (fmt=%u) for '%.*s' in archive '%.*s'",
(u32)mfmt,
@@ -305,7 +300,7 @@ LinkInputId link_add_archive_bytes(Linker* l, const char* name, const u8* data,
ob = member_impl->read(l->c, mem.name.s, mem.data, mem.size);
if (!ob)
compiler_panic(
- l->c, no_loc(),
+ l->c, SRCLOC_NONE,
"link_add_archive_bytes: object read failed for "
"member '%.*s' of archive '%.*s'",
SLICE_ARG(mem.name.len ? mem.name : SLICE_LIT("(unnamed)")),
@@ -430,7 +425,7 @@ void link_capture_debug_inputs(Linker* l, LinkImage* img) {
_Alignof(ObjBuilder*));
img->dbg_objs_owned = (u8*)h->alloc(h, sizeof(*img->dbg_objs_owned) * n, 1u);
if (!img->dbg_objs || !img->dbg_objs_owned)
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_capture_debug_inputs: oom on dbg arrays");
memset(img->dbg_objs, 0, sizeof(*img->dbg_objs) * n);
memset(img->dbg_objs_owned, 0, sizeof(*img->dbg_objs_owned) * n);
@@ -598,7 +593,7 @@ static void link_image_cleanup(void* arg) {
LinkImage* link_image_alloc(Compiler* c) {
Heap* h = (Heap*)c->ctx->heap;
LinkImage* img = (LinkImage*)h->alloc(h, sizeof(*img), _Alignof(LinkImage));
- if (!img) compiler_panic(c, no_loc(), "link: out of memory allocating image");
+ if (!img) compiler_panic(c, SRCLOC_NONE, "link: out of memory allocating image");
memset(img, 0, sizeof(*img));
img->c = c;
img->heap = h;
@@ -627,7 +622,7 @@ void link_image_free(LinkImage* img) {
LinkImage* link_resolve_at(Linker* l, uintptr_t base_va) {
(void)base_va;
if (!l) return NULL;
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link_resolve_at: incremental resolution not yet "
"implemented");
return NULL;
@@ -636,7 +631,7 @@ LinkImage* link_resolve_at(Linker* l, uintptr_t base_va) {
void link_resolve_extend(Linker* l, LinkImage* img) {
(void)img;
if (!l) return;
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link_resolve_extend: incremental resolution not "
"yet implemented");
}
@@ -651,7 +646,7 @@ void link_emit_image_writer(LinkImage* img, Writer* w) {
fmt->link_emit(img, w);
return;
}
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_emit_image_writer: unsupported obj format %u",
(u32)img->c->target.obj);
}
diff --git a/src/link/link_jit.c b/src/link/link_jit.c
@@ -34,15 +34,10 @@ KitObjFile* kit_objfile_internal_new(const KitContext* ctx,
void kit_objfile_internal_free(KitObjFile*);
#define jit_view_objfile_free(f) kit_objfile_internal_free(f)
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
static const KitJitHost* jit_host_from_linker(Linker* l, Compiler* c) {
const KitJitHost* host = l ? l->jit_host : NULL;
if (!host)
- compiler_panic(c, no_loc(), "kit_jit: link jit host is required for JIT");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit: link jit host is required for JIT");
return host;
}
@@ -50,7 +45,7 @@ static const KitExecMem* require_execmem_h(const KitJitHost* host,
Compiler* c) {
const KitExecMem* m = host ? host->execmem : NULL;
if (!m || !m->reserve || !m->protect || !m->release) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: jit host execmem is required for JIT");
}
return m;
@@ -222,7 +217,7 @@ static i64 jit_rv_pcrel_lo12_disp(LinkImage* img, KitExecMemRegion* segs,
hi_P = (u64)vaddr_to_runtime(img, segs, hi->write_vaddr);
return (i64)hi_S + hi->addend - (i64)hi_P;
}
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"kit_jit: RV PCREL_LO12 at 0x%llx has no paired PCREL_HI20",
(unsigned long long)auipc_image_vaddr);
return 0;
@@ -243,14 +238,14 @@ static void jit_copy_input_section_bytes(LinkImage* img,
if (ls->input_id == LINK_INPUT_NONE) continue;
input_idx = ls->input_id - 1u;
if (ls->segment_id == LINK_SEG_NONE || ls->segment_id > img->nsegments)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit_from_image: section has invalid segment");
seg = &img->segments[ls->segment_id - 1u];
ob = (input_idx < img->dbg_objs_n) ? img->dbg_objs[input_idx] : NULL;
if (!ob && l && input_idx < LinkInputs_count(&l->inputs))
ob = LinkInputs_at(&l->inputs, input_idx)->obj;
if (!ob)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit_from_image: input section bytes unavailable");
s = obj_section_get(ob, ls->obj_section_id);
if (!s || s->sem == SSEM_NOBITS || s->kind == SEC_BSS) continue;
@@ -288,7 +283,7 @@ static void jit_patch_tlv_descriptors(KitJit* jit) {
Heap* h = (Heap*)c->ctx->heap;
u8* is_tlv_bootstrap = (u8*)h->alloc(h, nsyms + 1u, 1u);
if (!is_tlv_bootstrap)
- compiler_panic(c, no_loc(), "kit_jit: oom on tlv-bootstrap bitmap");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit: oom on tlv-bootstrap bitmap");
memset(is_tlv_bootstrap, 0, nsyms + 1u);
int any_tlv = 0;
for (u32 si = 0; si < nsyms; ++si) {
@@ -305,7 +300,7 @@ static void jit_patch_tlv_descriptors(KitJit* jit) {
const KitJitTls* tls = jit->jit_host ? jit->jit_host->tls : NULL;
if (!tls || !tls->ctx_new || !tls->ctx_destroy)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: image needs TLV thunk but jit host tls is NULL "
"or incomplete");
@@ -316,14 +311,14 @@ static void jit_patch_tlv_descriptors(KitJit* jit) {
if (img->tls_filesz) {
init_bytes = (const u8*)vaddr_to_write(img, jit->segs, img->tls_vaddr);
if (!init_bytes)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: tls_vaddr does not map to any segment");
}
size_t align = img->tls_align ? (size_t)img->tls_align : 1u;
void* ctx = tls->ctx_new(tls->user, init_bytes, (size_t)img->tls_filesz,
(size_t)img->tls_memsz, align);
if (!ctx)
- compiler_panic(c, no_loc(), "kit_jit: jit_tls->ctx_new returned NULL");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit: jit_tls->ctx_new returned NULL");
jit->tls_vtable = tls;
jit->tls_ctx = ctx;
@@ -348,18 +343,18 @@ static void jit_patch_tlv_descriptors(KitJit* jit) {
}
}
if (!r16 || r16->target == LINK_SYM_NONE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: TLV descriptor missing data-symbol reloc");
const LinkSymbol* data_sym = LinkSyms_at(&img->syms, r16->target - 1);
if (!data_sym || !data_sym->defined)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: TLV descriptor data symbol is undefined");
u64 offset_in_image = (data_sym->vaddr + (u64)r16->addend) - img->tls_vaddr;
u8* write = (u8*)vaddr_to_write(img, jit->segs, desc_vaddr);
if (!write)
- compiler_panic(c, no_loc(), "kit_jit: TLV descriptor vaddr does not map");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit: TLV descriptor vaddr does not map");
wr_u64_le(write + 0u, (u64)thunk_addr);
wr_u64_le(write + 8u, (u64)(uintptr_t)ctx);
wr_u64_le(write + 16u, offset_in_image);
@@ -413,7 +408,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
}
}
if (image_base & (page - 1u))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit_from_image: segment vaddr not page-aligned");
append_start = image_end;
append_total = JIT_APPEND_RX_SLACK + JIT_APPEND_R_SLACK +
@@ -432,7 +427,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
metrics_scope_begin(c, "jit.reserve");
if (mem->reserve(mem->user, (size_t)master_size, master_prot, &master) !=
0) {
- compiler_panic(c, no_loc(), "kit_jit_from_image: execmem.reserve failed");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit_from_image: execmem.reserve failed");
}
metrics_scope_end(c, "jit.reserve");
}
@@ -443,7 +438,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
_Alignof(KitExecMemRegion));
if (!segs) {
mem->release(mem->user, &master);
- compiler_panic(c, no_loc(), "kit_jit_from_image: oom on segment table");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit_from_image: oom on segment table");
}
memset(segs, 0, sizeof(*segs) * img->nsegments);
}
@@ -478,7 +473,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
}
if (needs_input_materialize) {
if (!img->linker || !img->linker->jit_mode)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit_from_image: segment bytes are not materialized");
jit_copy_input_section_bytes(img, segs);
}
@@ -583,7 +578,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
perms_for(seg->flags)) != 0) {
mem->release(mem->user, &master);
if (segs) heap->free(heap, segs, sizeof(*segs) * img->nsegments);
- compiler_panic(c, no_loc(), "kit_jit_from_image: execmem.protect failed");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit_from_image: execmem.protect failed");
}
}
if (append_total) {
@@ -620,7 +615,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
uintptr_t slot_rt = vaddr_to_runtime(img, segs, slot_vaddr);
void* impl;
if (!resolver_rt || !slot_rt)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"kit_jit: iplt vaddr does not map to runtime");
impl = ((ResolverFn)resolver_rt)();
*(void**)(uintptr_t)slot_rt = impl;
@@ -631,7 +626,7 @@ KitJit* kit_jit_from_image(LinkImage* img) {
if (!jit) {
mem->release(mem->user, &master);
if (segs) heap->free(heap, segs, sizeof(*segs) * img->nsegments);
- compiler_panic(c, no_loc(), "kit_jit_from_image: oom on jit handle");
+ compiler_panic(c, SRCLOC_NONE, "kit_jit_from_image: oom on jit handle");
}
jit->c = c;
jit->image = img;
@@ -866,7 +861,7 @@ static void jit_apply_one_reloc(KitJit* jit, const LinkRelocApply* r) {
(r->kind == R_RV_PCREL_LO12_I) ? R_RV_LO12_I : R_RV_LO12_S;
P_bytes = (u8*)vaddr_to_write(img, jit->segs, r->write_vaddr);
if (!P_bytes)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: relocation site is unmapped");
link_reloc_apply(jit->c, alias, P_bytes, (u64)disp, 0,
(u64)vaddr_to_runtime(img, jit->segs, r->write_vaddr));
@@ -882,7 +877,7 @@ static void jit_apply_one_reloc(KitJit* jit, const LinkRelocApply* r) {
P = (u64)vaddr_to_runtime(img, jit->segs, r->write_vaddr);
P_bytes = (u8*)vaddr_to_write(img, jit->segs, r->write_vaddr);
if (!P_bytes)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: relocation site is unmapped");
if (tgt->bind == SB_WEAK && tgt->kind == SK_ABS && tgt->vaddr == 0) {
if (r->kind == R_AARCH64_ADR_PREL_PG_HI21 ||
@@ -939,7 +934,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
for (i = 0; i < SEG_NBUCKETS; ++i) old_cursor[i] = jit->append_cursor[i];
if (!jit || !ob || !jit->linker || obj_compiler(ob) != jit->c)
- compiler_panic(jit ? jit->c : NULL, no_loc(),
+ compiler_panic(jit ? jit->c : NULL, SRCLOC_NONE,
"kit_jit_append_obj: object is not appendable");
/* Preflight duplicate strong definitions and unresolved references before
@@ -961,7 +956,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
size_t namelen = nm_s.len;
obj_format_demangle_c(jit->c, &nm, &namelen);
obj_symiter_free(it);
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: duplicate global '%.*s'",
(int)namelen, nm);
}
@@ -1000,7 +995,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
if (!ok) {
obj_format_demangle_c(jit->c, &nm, &nlen);
obj_symiter_free(it);
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: undefined reference to '%.*s'",
(int)nlen, nm);
}
@@ -1042,11 +1037,11 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
b = link_bucket_for(s->flags);
vaddr = ALIGN_UP(cursor[b], (u64)(s->align ? s->align : 1u));
if (vaddr + size > jit->append_limit[b])
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: append slack exhausted");
ps = JitAppendSecs_push(&secs, &sec_idx);
if (!ps)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: oom on section plan");
ps->obj_sec = (ObjSecId)i;
ps->obj_atom = has_atoms ? aid : OBJ_ATOM_NONE;
@@ -1092,7 +1087,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
size_t namelen = nm_s.len;
obj_format_demangle_c(jit->c, &nm, &namelen);
obj_symiter_free(it);
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: duplicate global '%.*s'",
(int)namelen, nm);
}
@@ -1196,11 +1191,11 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
continue;
}
obj_format_demangle_c(jit->c, &nm, &nlen);
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: undefined reference to '%.*s'",
(int)nlen, nm);
}
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: undefined anonymous symbol");
}
@@ -1212,7 +1207,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
h, img->input_maps, sizeof(*img->input_maps) * img->ninput_maps,
sizeof(*img->input_maps) * (new_input_idx + 1u), _Alignof(InputMap));
if (!maps)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: oom growing input maps");
img->input_maps = maps;
while (img->ninput_maps < new_input_idx) {
@@ -1244,7 +1239,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
h, jit->segs, sizeof(*jit->segs) * old_nsegs,
sizeof(*jit->segs) * (old_nsegs + nsecs), _Alignof(KitExecMemRegion));
if (!nsections || !nsegments || !nsegbytes || !nsegcaps || !njsegs)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: oom growing image tables");
img->sections = nsections;
img->segments = nsegments;
@@ -1350,7 +1345,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
(u8*)jit->master.runtime + (uintptr_t)(page_lo - jit->image_base);
if (mem->protect(mem->user, rt, (size_t)(page_hi - page_lo),
perms_for(seg->flags)) != 0) {
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: execmem.protect failed");
}
}
@@ -1370,7 +1365,7 @@ static void jit_append_obj_inner(KitJit* jit, ObjBuilder* ob) {
h, img->dbg_objs_owned, sizeof(*img->dbg_objs_owned) * old_dbg_n,
sizeof(*img->dbg_objs_owned) * (new_input_idx + 1u), 1u);
if (!nd || !no)
- compiler_panic(jit->c, no_loc(),
+ compiler_panic(jit->c, SRCLOC_NONE,
"kit_jit_append_obj: oom growing debug inputs");
img->dbg_objs = nd;
img->dbg_objs_owned = no;
diff --git a/src/link/link_layout.c b/src/link/link_layout.c
@@ -28,11 +28,6 @@
LinkImage* link_image_alloc(Compiler*); /* defined in link.c */
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* Page size used for ELF segment alignment. We pull from env->execmem
* when present (matches the eventual JIT mapping granularity) and fall
* back to 16 KiB otherwise — large enough for any current Linux/aarch64
@@ -99,7 +94,7 @@ static int link_pie_ro_section_needs_write(const ObjBuilder* ob, ObjSecId sid) {
static LinkSymbol* append_symbol_slot(LinkImage* img) {
u32 idx;
LinkSymbol* s = LinkSyms_push(&img->syms, &idx);
- if (!s) compiler_panic(img->c, no_loc(), "link: oom growing symbols");
+ if (!s) compiler_panic(img->c, SRCLOC_NONE, "link: oom growing symbols");
s->id = (LinkSymId)(idx + 1u);
return s;
}
@@ -114,7 +109,7 @@ LinkSymId link_append_symbol(LinkImage* img, const LinkSymbol* tmpl) {
LinkRelocApply* link_append_reloc_slot(LinkImage* img) {
LinkRelocApply* r = LinkRelocs_push(&img->relocs, NULL);
- if (!r) compiler_panic(img->c, no_loc(), "link: oom growing relocs");
+ if (!r) compiler_panic(img->c, SRCLOC_NONE, "link: oom growing relocs");
return r;
}
@@ -225,7 +220,7 @@ void link_layout_sections(Linker* l, LinkImage* img, const GcLive* g) {
_Alignof(LinkSection))
: NULL;
if (total_kept && !img->sections)
- compiler_panic(img->c, no_loc(), "link: oom on sections");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on sections");
/* Pass 1: collect kept sections into a flat list. */
PlaceEntry* entries =
@@ -239,13 +234,13 @@ void link_layout_sections(Linker* l, LinkImage* img, const GcLive* g) {
PlaceGroupHash group_map;
u32 ngroups = 0;
if (total_kept && !entries)
- compiler_panic(img->c, no_loc(), "link: oom on placement entries");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on placement entries");
if (total_kept && !groups)
- compiler_panic(img->c, no_loc(), "link: oom on placement groups");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on placement groups");
if (total_kept) {
PlaceGroupHash_init_cap(&group_map, h, place_group_hash_cap(total_kept));
if (!group_map.slots)
- compiler_panic(img->c, no_loc(), "link: oom on placement group map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on placement group map");
}
{
u32 e = 0;
@@ -395,7 +390,7 @@ void link_layout_sections(Linker* l, LinkImage* img, const GcLive* g) {
: NULL;
if (nseg &&
(!img->segments || !img->segment_bytes || !img->segment_bytes_cap))
- compiler_panic(img->c, no_loc(), "link: oom on segments");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on segments");
if (nseg) {
memset(img->segment_bytes, 0, sizeof(*img->segment_bytes) * nseg);
memset(img->segment_bytes_cap, 0, sizeof(*img->segment_bytes_cap) * nseg);
@@ -455,7 +450,7 @@ void link_layout_sections(Linker* l, LinkImage* img, const GcLive* g) {
img->segment_bytes[bucket_seg[b] - 1] =
(u8*)h->alloc(h, (size_t)seg->file_size, 16);
if (!img->segment_bytes[bucket_seg[b] - 1])
- compiler_panic(img->c, no_loc(), "link: oom on segment bytes");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on segment bytes");
img->segment_bytes_cap[bucket_seg[b] - 1] = (size_t)seg->file_size;
memset(img->segment_bytes[bucket_seg[b] - 1], 0,
(size_t)seg->file_size);
@@ -523,7 +518,7 @@ static u64 eval_link_expr(Linker* l, LinkImage* img, u64 dot,
Sym name = pool_intern_slice(l->c->global, e->v.name);
LinkSymId id = symhash_get(&img->globals, name);
if (id == LINK_SYM_NONE) {
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"linker script: undefined symbol '%.*s' in expression",
SLICE_ARG(pool_slice(l->c->global, name)));
}
@@ -572,7 +567,7 @@ static u64 eval_link_expr(Linker* l, LinkImage* img, u64 dot,
case KIT_LE_MAX:
case KIT_LE_MIN:
default:
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"linker script: expression kind %u not supported",
(unsigned)e->kind);
return 0;
@@ -649,7 +644,7 @@ static void apply_asn(Linker* l, LinkImage* img, u64* dot,
switch ((KitLinkAsnKind)asn->kind) {
case KIT_LAS_DOT:
if (v < *dot)
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"linker script: dot moved backwards (%llu -> %llu)",
(unsigned long long)*dot, (unsigned long long)v);
*dot = v;
@@ -693,19 +688,19 @@ static void link_layout_sections_scripted(Linker* l, LinkImage* img,
_Alignof(LinkSection))
: NULL;
if (total_kept && !img->sections)
- compiler_panic(img->c, no_loc(), "link: oom on sections");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on sections");
u8** claimed = NULL;
if (LinkInputs_count(&l->inputs)) {
u32 ni = LinkInputs_count(&l->inputs);
claimed = (u8**)h->alloc(h, sizeof(*claimed) * ni, _Alignof(u8*));
- if (!claimed) compiler_panic(img->c, no_loc(), "link: oom on claim map");
+ if (!claimed) compiler_panic(img->c, SRCLOC_NONE, "link: oom on claim map");
for (ii = 0; ii < ni; ++ii) {
ObjBuilder* ob = LinkInputs_at(&l->inputs, ii)->obj;
u32 nsec = obj_section_count(ob);
claimed[ii] = (u8*)h->alloc(h, nsec, 1);
if (!claimed[ii])
- compiler_panic(img->c, no_loc(), "link: oom on claim row");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on claim row");
memset(claimed[ii], 0, nsec);
}
}
@@ -733,7 +728,7 @@ static void link_layout_sections_scripted(Linker* l, LinkImage* img,
: NULL;
if (nseg_max &&
(!img->segments || !img->segment_bytes || !img->segment_bytes_cap))
- compiler_panic(img->c, no_loc(), "link: oom on segments");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on segments");
if (nseg_max) {
memset(img->segment_bytes, 0, sizeof(*img->segment_bytes) * nseg_max);
memset(img->segment_bytes_cap, 0,
@@ -883,7 +878,7 @@ static void link_layout_sections_scripted(Linker* l, LinkImage* img,
img->segment_bytes[img->nsegments] =
(u8*)h->alloc(h, (size_t)file_size_accum, 16);
if (!img->segment_bytes[img->nsegments])
- compiler_panic(img->c, no_loc(), "link: oom on scripted segment bytes");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on scripted segment bytes");
img->segment_bytes_cap[img->nsegments] = (size_t)file_size_accum;
memset(img->segment_bytes[img->nsegments], 0, (size_t)file_size_accum);
}
@@ -991,7 +986,7 @@ void link_layout_commons(Linker* l, LinkImage* img) {
h, img->sections, sizeof(*img->sections) * img->nsections,
sizeof(*img->sections) * new_nsec, _Alignof(LinkSection));
if (!nsec)
- compiler_panic(img->c, no_loc(), "link: oom on common section");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on common section");
img->sections = nsec;
}
commsec = &img->sections[img->nsections];
@@ -1093,7 +1088,7 @@ void link_layout_debug(Linker* l, LinkImage* img) {
LinkSection* ns = (LinkSection*)h->realloc(
h, img->sections, sizeof(*img->sections) * img->nsections,
sizeof(*img->sections) * new_nsec, _Alignof(LinkSection));
- if (!ns) compiler_panic(img->c, no_loc(), "link: oom on debug sections");
+ if (!ns) compiler_panic(img->c, SRCLOC_NONE, "link: oom on debug sections");
img->sections = ns;
}
@@ -1104,7 +1099,7 @@ void link_layout_debug(Linker* l, LinkImage* img) {
DbgNameAcc* acc =
(DbgNameAcc*)h->alloc(h, sizeof(*acc) * ndbg, _Alignof(DbgNameAcc));
if (!img->dbg_bytes || !img->dbg_size || !acc)
- compiler_panic(img->c, no_loc(), "link: oom on debug registry");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on debug registry");
memset(img->dbg_bytes, 0, sizeof(*img->dbg_bytes) * ndbg);
memset(img->dbg_size, 0, sizeof(*img->dbg_size) * ndbg);
@@ -1162,7 +1157,7 @@ void link_layout_debug(Linker* l, LinkImage* img) {
/* Copy this contribution's bytes into its own registry buffer. */
buf = (u8*)h->alloc(h, size, 1);
- if (!buf) compiler_panic(img->c, no_loc(), "link: oom on debug bytes");
+ if (!buf) compiler_panic(img->c, SRCLOC_NONE, "link: oom on debug bytes");
buf_read(&s->bytes, 0u, buf, (size_t)size);
img->dbg_bytes[slot] = buf;
img->dbg_size[slot] = size;
@@ -1212,7 +1207,7 @@ LinkImage* link_resolve(Linker* l) {
_Alignof(InputMap))
: NULL;
if (LinkInputs_count(&l->inputs) && !img->input_maps)
- compiler_panic(l->c, no_loc(), "link: oom on input maps");
+ compiler_panic(l->c, SRCLOC_NONE, "link: oom on input maps");
if (LinkInputs_count(&l->inputs))
memset(img->input_maps, 0,
sizeof(*img->input_maps) * LinkInputs_count(&l->inputs));
diff --git a/src/link/link_reloc_layout.c b/src/link/link_reloc_layout.c
@@ -24,11 +24,6 @@
#include "link/link_arch.h"
#include "link/link_internal.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* Nominal (non-zero) width reported for the variable-length ULEB128
* RISC-V relocs. See the comment in reloc_width(): this value only has
* to be non-zero to pass the "supported kind" gate — the byte-exact
@@ -404,7 +399,7 @@ u32 link_iplt_alloc_segments(LinkImage* img, u32 nseg) {
sizeof(*img->segment_bytes_cap) * img->nsegments,
sizeof(*img->segment_bytes_cap) * new_nseg, _Alignof(size_t));
if (!nsegs || !nsbufs || !nscaps)
- compiler_panic(img->c, no_loc(), "link: oom on iplt segments");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on iplt segments");
img->segments = nsegs;
img->segment_bytes = nsbufs;
img->segment_bytes_cap = nscaps;
@@ -419,7 +414,7 @@ u32 link_iplt_alloc_sections(LinkImage* img, u32 nsec) {
h, img->sections, sizeof(*img->sections) * img->nsections,
sizeof(*img->sections) * new_nsec, _Alignof(LinkSection));
if (!nsections)
- compiler_panic(img->c, no_loc(), "link: oom on iplt sections");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on iplt sections");
img->sections = nsections;
return base;
}
@@ -465,7 +460,7 @@ LinkSectionId link_synth_region(LinkImage* img, Linker* l, Sym name, u16 perms,
bytes = (u8*)h->alloc(h, (size_t)size, 16);
img->segment_bytes[seg_idx] = bytes;
img->segment_bytes_cap[seg_idx] = (size_t)size;
- if (!bytes) compiler_panic(img->c, no_loc(), "link: oom on synth region bytes");
+ if (!bytes) compiler_panic(img->c, SRCLOC_NONE, "link: oom on synth region bytes");
memset(bytes, 0, (size_t)size);
img->nsegments += 1u;
@@ -559,7 +554,7 @@ void link_layout_jit_stubs(Linker* l, LinkImage* img, u32 map_size,
stub_map = (LinkSymId*)h->alloc(h, sizeof(*stub_map) * map_size,
_Alignof(LinkSymId));
- if (!stub_map) compiler_panic(img->c, no_loc(), "link: oom on stub map");
+ if (!stub_map) compiler_panic(img->c, SRCLOC_NONE, "link: oom on stub map");
memset(stub_map, 0, sizeof(*stub_map) * map_size);
for (ii = 0; ii < LinkInputs_count(&l->inputs); ++ii) {
@@ -582,7 +577,7 @@ void link_layout_jit_stubs(Linker* l, LinkImage* img, u32 map_size,
if (!tgt || tgt->kind != SK_ABS) continue;
if (stub_map[target] != LINK_SYM_NONE) continue;
if (VEC_GROW(h, targets, tcap, ntarget + 1u))
- compiler_panic(img->c, no_loc(), "link: oom on stub target list");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on stub target list");
targets[ntarget] = target;
stub_map[target] = (LinkSymId)(ntarget + 1u);
ntarget++;
@@ -678,7 +673,7 @@ void link_layout_got(Linker* l, LinkImage* img, u32 map_size,
got_map =
(LinkSymId*)h->alloc(h, sizeof(*got_map) * map_size, _Alignof(LinkSymId));
- if (!got_map) compiler_panic(img->c, no_loc(), "link: oom on got map");
+ if (!got_map) compiler_panic(img->c, SRCLOC_NONE, "link: oom on got map");
memset(got_map, 0, sizeof(*got_map) * map_size);
for (ii = 0; ii < LinkInputs_count(&l->inputs); ++ii) {
@@ -698,7 +693,7 @@ void link_layout_got(Linker* l, LinkImage* img, u32 map_size,
if (target == LINK_SYM_NONE) continue;
if (got_map[target] != LINK_SYM_NONE) continue;
if (VEC_GROW(h, slot_targets, slot_cap, nslot + 1u))
- compiler_panic(img->c, no_loc(), "link: oom on got slot list");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on got slot list");
slot_targets[nslot] = target;
got_map[target] = (LinkSymId)(nslot + 1u);
nslot++;
@@ -761,7 +756,7 @@ void link_layout_iplt(Linker* l, LinkImage* img) {
Sym ifunc_init_name = 0;
const LinkArchDesc* arch = link_arch_desc_for(l->c);
if (!arch)
- compiler_panic(img->c, no_loc(), "link: layout_iplt: no arch descriptor");
+ compiler_panic(img->c, SRCLOC_NONE, "link: layout_iplt: no arch descriptor");
for (i = 0; i < LinkSyms_count(&img->syms); ++i) {
const LinkSymbol* s = LinkSyms_at(&img->syms, i);
@@ -786,7 +781,7 @@ void link_layout_iplt(Linker* l, LinkImage* img) {
ifunc_init_sym = symhash_get(&img->globals, ifunc_init_name);
if (ifunc_init_sym == LINK_SYM_NONE ||
!LinkSyms_at(&img->syms, ifunc_init_sym - 1)->defined) {
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: STT_GNU_IFUNC requires '__kit_ifunc_init' "
"to be defined (link in libkit_rt.a or provide "
"your own implementation)");
@@ -815,7 +810,7 @@ void link_layout_iplt(Linker* l, LinkImage* img) {
img->iplt_pairs = (u64*)h->alloc(
h, sizeof(*img->iplt_pairs) * 2u * (size_t)nifunc, _Alignof(u64));
if (!img->iplt_pairs)
- compiler_panic(img->c, no_loc(), "link: oom on iplt pairs");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on iplt pairs");
img->niplt = nifunc;
slot_idx = 0;
@@ -930,7 +925,7 @@ void link_resolve_entry(Linker* l, LinkImage* img) {
Slice nm_s = pool_slice(l->c->global, l->entry_name);
const char* nm = nm_s.s;
size_t namelen = nm_s.len;
- compiler_panic(l->c, no_loc(), "link: entry symbol '%.*s' not defined",
+ compiler_panic(l->c, SRCLOC_NONE, "link: entry symbol '%.*s' not defined",
(int)namelen, nm);
}
s = LinkSyms_at(&img->syms, id - 1);
@@ -938,7 +933,7 @@ void link_resolve_entry(Linker* l, LinkImage* img) {
Slice nm_s = pool_slice(l->c->global, l->entry_name);
const char* nm = nm_s.s;
size_t namelen = nm_s.len;
- compiler_panic(l->c, no_loc(), "link: entry symbol '%.*s' is undefined",
+ compiler_panic(l->c, SRCLOC_NONE, "link: entry symbol '%.*s' is undefined",
(int)namelen, nm);
}
img->entry_sym = id;
@@ -969,15 +964,15 @@ void link_emit_relocations(Linker* l, LinkImage* img, const LinkSymId* got_map,
r->kind == R_RV_ALIGN)
continue;
if (r->sym == OBJ_SYM_NONE || r->sym >= m->nsym)
- compiler_panic(l->c, no_loc(), "link: reloc references unknown symbol");
+ compiler_panic(l->c, SRCLOC_NONE, "link: reloc references unknown symbol");
target = m->sym[r->sym];
if (target == LINK_SYM_NONE)
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link: reloc references unmapped symbol");
if (got_map && reloc_uses_got(r->kind)) {
LinkSymId slot = got_map[target];
if (slot == LINK_SYM_NONE)
- compiler_panic(l->c, no_loc(), "link: GOT slot missing for symbol");
+ compiler_panic(l->c, SRCLOC_NONE, "link: GOT slot missing for symbol");
target = slot;
}
if (stub_map && arch && arch->needs_jit_call_stub &&
@@ -1002,7 +997,7 @@ void link_emit_relocations(Linker* l, LinkImage* img, const LinkSymId* got_map,
rec.target = target;
rec.addend = r->addend;
if (rec.width == 0)
- compiler_panic(l->c, no_loc(), "link: unsupported reloc kind %u",
+ compiler_panic(l->c, SRCLOC_NONE, "link: unsupported reloc kind %u",
(unsigned)r->kind);
/* The ULEB128 SET/SUB relocs are variable-width (their true length is
* read from the bytes at apply time, so rec.width is only a sentinel).
@@ -1011,7 +1006,7 @@ void link_emit_relocations(Linker* l, LinkImage* img, const LinkSymId* got_map,
* external object. */
if ((rec.kind == R_RV_SET_ULEB128 || rec.kind == R_RV_SUB_ULEB128) &&
rec.offset >= ls->size)
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link: ULEB128 reloc offset past section end");
*link_append_reloc_slot(img) = rec;
}
diff --git a/src/link/link_relocatable.c b/src/link/link_relocatable.c
@@ -17,11 +17,6 @@
#include "link/link.h"
#include "link/link_internal.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
typedef struct RelObjSecMap {
ObjSecId out_sec;
u32 delta;
@@ -88,7 +83,7 @@ static RelGlobal* rel_global_for(Linker* l, RelGlobal** globals, u32* nglobals,
RelGlobal* g;
if (hit != LINK_SYM_NONE) return &(*globals)[hit - 1u];
if (VEC_GROW(l->heap, *globals, *cap, *nglobals + 1u))
- compiler_panic(l->c, no_loc(), "link -r: oom on global symbols");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom on global symbols");
g = &(*globals)[*nglobals];
memset(g, 0, sizeof(*g));
g->name = name;
@@ -151,7 +146,7 @@ static void rel_record_global(Linker* l, RelGlobal** globals, u32* nglobals,
const char* nm = nm_s.s;
size_t namelen = nm_s.len;
obj_format_demangle_c(l->c, &nm, &namelen);
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link -r: duplicate definition of global symbol '%.*s'",
(int)namelen, nm);
}
@@ -186,7 +181,7 @@ static ObjSymId rel_copy_symbol(Linker* l, ObjBuilder* out,
force_common ? SK_COMMON : (SymKind)s->kind, sec, value,
force_common ? common_size : s->size, align);
if (id == OBJ_SYM_NONE)
- compiler_panic(l->c, no_loc(), "link -r: oom copying symbol");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom copying symbol");
if (s->flags) obj_symbol_set_flags(out, id, s->flags);
obj_sym_mark_referenced(out, id);
return id;
@@ -198,7 +193,7 @@ static ObjSymId rel_global_out(Linker* l, ObjBuilder* out, RelInputMap* maps,
if (g->out_sym != OBJ_SYM_NONE) return g->out_sym;
if (g->has_def) {
s = rel_input_sym(l, g->def_input_idx, g->def_sym);
- if (!s) compiler_panic(l->c, no_loc(), "link -r: bad global symbol map");
+ if (!s) compiler_panic(l->c, SRCLOC_NONE, "link -r: bad global symbol map");
g->out_sym =
rel_copy_symbol(l, out, maps, g->def_input_idx, s, s->kind == SK_COMMON,
g->common_size, g->common_align);
@@ -208,7 +203,7 @@ static ObjSymId rel_global_out(Linker* l, ObjBuilder* out, RelInputMap* maps,
g->has_undef ? (SymBind)g->undef_bind : SB_GLOBAL, SK_UNDEF,
OBJ_SEC_NONE, 0, 0);
if (id == OBJ_SYM_NONE)
- compiler_panic(l->c, no_loc(), "link -r: oom creating undef symbol");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom creating undef symbol");
obj_sym_mark_referenced(out, id);
g->out_sym = id;
}
@@ -247,14 +242,14 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps,
u32 nsec;
u32 in_eflags;
if (in->kind == LINK_INPUT_DSO_BYTES)
- compiler_panic(l->c, no_loc(), "link -r: DSO inputs are not supported");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: DSO inputs are not supported");
if (!ob) continue;
if (obj_get_elf_e_flags(ob, &in_eflags)) {
if (!have_eflags) {
eflags = in_eflags;
have_eflags = 1;
} else if (eflags != in_eflags) {
- compiler_panic(l->c, no_loc(), "link -r: incompatible ELF e_flags");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: incompatible ELF e_flags");
}
}
nsec = obj_section_count(ob);
@@ -262,7 +257,7 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps,
maps[ii].section = (RelObjSecMap*)l->heap->alloc(
l->heap, sizeof(*maps[ii].section) * nsec, _Alignof(RelObjSecMap));
if (!maps[ii].section)
- compiler_panic(l->c, no_loc(), "link -r: oom on section map");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom on section map");
memset(maps[ii].section, 0, sizeof(*maps[ii].section) * nsec);
for (j = 1; j < nsec; ++j) {
const Section* s = obj_section_get(ob, (ObjSecId)j);
@@ -275,7 +270,7 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps,
s->flags, s->align, s->entsize, OBJ_SEC_NONE,
s->info);
if (out_sec == OBJ_SEC_NONE)
- compiler_panic(l->c, no_loc(), "link -r: oom copying section");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom copying section");
if (s->ext_kind != OBJ_EXT_NONE || s->ext_type || s->ext_flags)
obj_section_set_ext(out, out_sec, (ObjExtKind)s->ext_kind,
s->ext_type, s->ext_flags);
@@ -286,7 +281,7 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps,
} else if (s->bytes.total) {
u8* flat = (u8*)l->heap->alloc(l->heap, s->bytes.total, 1u);
if (!flat)
- compiler_panic(l->c, no_loc(), "link -r: oom copying section bytes");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom copying section bytes");
buf_flatten(&s->bytes, flat);
obj_write(out, out_sec, flat, s->bytes.total);
l->heap->free(l->heap, flat, s->bytes.total);
@@ -342,7 +337,7 @@ static void rel_copy_symbols(Linker* l, ObjBuilder* out, RelInputMap* maps,
maps[ii].sym = (ObjSymId*)l->heap->alloc(
l->heap, sizeof(*maps[ii].sym) * nsym, _Alignof(ObjSymId));
if (!maps[ii].sym)
- compiler_panic(l->c, no_loc(), "link -r: oom on symbol map");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom on symbol map");
memset(maps[ii].sym, 0, sizeof(*maps[ii].sym) * nsym);
it = obj_symiter_new(in->obj);
while (obj_symiter_next(it, &e)) {
@@ -377,7 +372,7 @@ static void rel_copy_groups(Linker* l, ObjBuilder* out, RelInputMap* maps) {
sig = maps[ii].sym[g->signature];
out_gid = obj_group(out, g->name, sig, g->flags);
if (out_gid == OBJ_GROUP_NONE)
- compiler_panic(l->c, no_loc(), "link -r: oom copying group");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom copying group");
for (j = 0; j < g->nsections; ++j) {
ObjSecId in_sec = g->sections[j];
ObjSecId out_sec = OBJ_SEC_NONE;
@@ -435,7 +430,7 @@ void link_emit_relocatable_writer(Linker* l, Writer* w) {
h = l->heap;
if (l->script)
- compiler_panic(l->c, no_loc(), "link -r: linker scripts are not supported");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: linker scripts are not supported");
link_ingest_archives(l);
ninputs = LinkInputs_count(&l->inputs);
@@ -443,11 +438,11 @@ void link_emit_relocatable_writer(Linker* l, Writer* w) {
_Alignof(RelInputMap))
: NULL;
if (ninputs && !maps)
- compiler_panic(l->c, no_loc(), "link -r: oom on input maps");
+ compiler_panic(l->c, SRCLOC_NONE, "link -r: oom on input maps");
if (ninputs) memset(maps, 0, sizeof(*maps) * ninputs);
out = obj_new(l->c);
- if (!out) compiler_panic(l->c, no_loc(), "link -r: obj_new failed");
+ if (!out) compiler_panic(l->c, SRCLOC_NONE, "link -r: obj_new failed");
cleanup = compiler_defer(l->c, rel_obj_cleanup, out);
symhash_init(&globals_by_name, h);
diff --git a/src/link/link_resolve.c b/src/link/link_resolve.c
@@ -23,11 +23,6 @@
#include "link/link_arch.h"
#include "link/link_internal.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- per-input symbol/section maps ---- */
typedef struct AtomSortRec {
@@ -102,33 +97,33 @@ void link_input_map_alloc(LinkImage* img, InputMap* m, ObjBuilder* ob,
m->nsym = nsym;
m->sym = (LinkSymId*)h->alloc(h, sizeof(*m->sym) * nsym, _Alignof(LinkSymId));
if (!m->sym)
- compiler_panic(img->c, no_loc(), "link: oom on input symbol map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input symbol map");
memset(m->sym, 0, sizeof(*m->sym) * nsym);
m->nsection = nsection;
m->section = (LinkSectionId*)h->alloc(h, sizeof(*m->section) * nsection,
_Alignof(LinkSectionId));
if (!m->section)
- compiler_panic(img->c, no_loc(), "link: oom on input section map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input section map");
memset(m->section, 0, sizeof(*m->section) * nsection);
m->natom = natom;
m->atom = (LinkSectionId*)h->alloc(h, sizeof(*m->atom) * (natom ? natom : 1u),
_Alignof(LinkSectionId));
- if (!m->atom) compiler_panic(img->c, no_loc(), "link: oom on input atom map");
+ if (!m->atom) compiler_panic(img->c, SRCLOC_NONE, "link: oom on input atom map");
memset(m->atom, 0, sizeof(*m->atom) * (natom ? natom : 1u));
m->sym_atom = (ObjAtomId*)h->alloc(
h, sizeof(*m->sym_atom) * (nsym ? nsym : 1u), _Alignof(ObjAtomId));
if (!m->sym_atom)
- compiler_panic(img->c, no_loc(), "link: oom on input symbol atom map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input symbol atom map");
memset(m->sym_atom, 0, sizeof(*m->sym_atom) * (nsym ? nsym : 1u));
m->nreloc = nreloc;
m->reloc_atom = (ObjAtomId*)h->alloc(
h, sizeof(*m->reloc_atom) * (nreloc ? nreloc : 1u), _Alignof(ObjAtomId));
if (!m->reloc_atom)
- compiler_panic(img->c, no_loc(), "link: oom on input reloc atom map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input reloc atom map");
memset(m->reloc_atom, 0, sizeof(*m->reloc_atom) * (nreloc ? nreloc : 1u));
m->section_has_atoms = (u8*)h->alloc(h, nsection ? nsection : 1u, 1);
if (!m->section_has_atoms)
- compiler_panic(img->c, no_loc(), "link: oom on input section atom map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input section atom map");
memset(m->section_has_atoms, 0, nsection ? nsection : 1u);
m->section_atom_first = (u32*)h->alloc(
h, sizeof(*m->section_atom_first) * (nsection ? nsection : 1u),
@@ -137,20 +132,20 @@ void link_input_map_alloc(LinkImage* img, InputMap* m, ObjBuilder* ob,
h, sizeof(*m->section_atom_count) * (nsection ? nsection : 1u),
_Alignof(u32));
if (!m->section_atom_first || !m->section_atom_count)
- compiler_panic(img->c, no_loc(), "link: oom on input section atom ranges");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input section atom ranges");
memset(m->section_atom_first, 0,
sizeof(*m->section_atom_first) * (nsection ? nsection : 1u));
memset(m->section_atom_count, 0,
sizeof(*m->section_atom_count) * (nsection ? nsection : 1u));
m->comdat_discarded = (u8*)h->alloc(h, nsection ? nsection : 1u, 1);
if (!m->comdat_discarded)
- compiler_panic(img->c, no_loc(), "link: oom on input comdat map");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on input comdat map");
memset(m->comdat_discarded, 0, nsection ? nsection : 1u);
if (natom > 1u) {
atoms = (AtomSortRec*)h->alloc(h, sizeof(*atoms) * natom,
_Alignof(AtomSortRec));
- if (!atoms) compiler_panic(img->c, no_loc(), "link: oom on atom sort map");
+ if (!atoms) compiler_panic(img->c, SRCLOC_NONE, "link: oom on atom sort map");
for (i = 1; i < natom; ++i) {
const ObjAtom* a = obj_atom_get(ob, (ObjAtomId)i);
if (!a || a->removed || a->section_id == OBJ_SEC_NONE ||
@@ -170,7 +165,7 @@ void link_input_map_alloc(LinkImage* img, InputMap* m, ObjBuilder* ob,
m->section_atom_ids = (ObjAtomId*)h->alloc(
h, sizeof(*m->section_atom_ids) * nactive, _Alignof(ObjAtomId));
if (!m->section_atom_ids)
- compiler_panic(img->c, no_loc(), "link: oom on section atom ids");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on section atom ids");
for (i = 0; i < nactive; ++i) {
ObjSecId sid = atoms[i].section_id;
m->section_atom_ids[i] = atoms[i].id;
@@ -309,7 +304,7 @@ void link_resolve_symbols(Linker* l, LinkImage* img) {
Slice nm_s = pool_slice(l->c->global, s->name);
const char* nm = nm_s.s;
size_t namelen = nm_s.len;
- compiler_panic(l->c, no_loc(),
+ compiler_panic(l->c, SRCLOC_NONE,
"link: duplicate definition of "
"global symbol '%.*s'",
(int)namelen, nm);
@@ -483,7 +478,7 @@ void link_resolve_undefs(Linker* l, LinkImage* img) {
const char* nm = nm_s.s ? nm_s.s : "";
size_t namelen = nm_s.len;
obj_format_demangle_c(l->c, &nm, &namelen);
- compiler_panic(l->c, no_loc(), "link: undefined reference to '%.*s'",
+ compiler_panic(l->c, SRCLOC_NONE, "link: undefined reference to '%.*s'",
(int)namelen, nm);
}
}
@@ -529,18 +524,18 @@ void link_gc_live_alloc(GcLive* g, Linker* l, Heap* h) {
: NULL;
if (LinkInputs_count(&l->inputs) &&
(!g->marks || !g->atom_marks || !g->nsec || !g->natom))
- compiler_panic(l->c, no_loc(), "link: oom on gc live map");
+ compiler_panic(l->c, SRCLOC_NONE, "link: oom on gc live map");
for (ii = 0; ii < LinkInputs_count(&l->inputs); ++ii) {
u32 nsec = obj_section_count(LinkInputs_at(&l->inputs, ii)->obj);
u32 natom = obj_atom_count(LinkInputs_at(&l->inputs, ii)->obj);
g->nsec[ii] = nsec;
g->natom[ii] = natom;
g->marks[ii] = (u8*)h->alloc(h, nsec ? nsec : 1u, 1);
- if (!g->marks[ii]) compiler_panic(l->c, no_loc(), "link: oom on gc marks");
+ if (!g->marks[ii]) compiler_panic(l->c, SRCLOC_NONE, "link: oom on gc marks");
memset(g->marks[ii], 0, nsec);
g->atom_marks[ii] = (u8*)h->alloc(h, natom ? natom : 1u, 1);
if (!g->atom_marks[ii])
- compiler_panic(l->c, no_loc(), "link: oom on gc atom marks");
+ compiler_panic(l->c, SRCLOC_NONE, "link: oom on gc atom marks");
memset(g->atom_marks[ii], 0, natom);
}
}
@@ -841,7 +836,7 @@ static void include_archive_member(Linker* l, const LinkArchive* ar,
if (mem->included) return;
in = LinkInputs_push(&l->inputs, &idx);
if (!in)
- compiler_panic(l->c, no_loc(), "link: oom growing inputs (archive member)");
+ compiler_panic(l->c, SRCLOC_NONE, "link: oom growing inputs (archive member)");
id = (LinkInputId)(idx + 1u);
in->id = id;
/* PE/COFF short-import shim: read_coff_short_import stashes the
@@ -1017,7 +1012,7 @@ void link_synth_coff_ctor_dtor_list(Linker* l) {
}
obj_finalize(ob);
in = LinkInputs_push(&l->inputs, &idx);
- if (!in) compiler_panic(l->c, no_loc(), "link: oom growing inputs (synth)");
+ if (!in) compiler_panic(l->c, SRCLOC_NONE, "link: oom growing inputs (synth)");
in->id = (LinkInputId)(idx + 1u);
in->kind = LINK_INPUT_OBJ_BYTES;
in->order = l->next_input_order++;
diff --git a/src/obj/coff/emit.c b/src/obj/coff/emit.c
@@ -44,11 +44,6 @@
#include "obj/coff/coff.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
static int coff_rel32_absorbs_minus4(KitArchKind arch, RelocKind kind,
i64 addend) {
if (arch != KIT_ARCH_X86_64 || addend != -4) return 0;
@@ -262,16 +257,16 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
const ObjCoffArchOps* coff =
fmt && fmt->coff_arch ? fmt->coff_arch(c->target.arch) : NULL;
if (!coff || !coff->reloc_to) {
- compiler_panic(c, no_loc(), "emit_coff: unsupported target arch %u",
+ compiler_panic(c, SRCLOC_NONE, "emit_coff: unsupported target arch %u",
(u32)c->target.arch);
}
u16 machine = coff->machine;
u32 (*reloc_to)(u32) = coff->reloc_to;
if (c->target.big_endian) {
- compiler_panic(c, no_loc(), "emit_coff: big-endian COFF not supported");
+ compiler_panic(c, SRCLOC_NONE, "emit_coff: big-endian COFF not supported");
}
if (c->target.ptr_size != 8) {
- compiler_panic(c, no_loc(), "emit_coff: ptr_size %u (expected 8)",
+ compiler_panic(c, SRCLOC_NONE, "emit_coff: ptr_size %u (expected 8)",
(u32)c->target.ptr_size);
}
@@ -345,7 +340,7 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
CSec* cs = &secs[ci];
u32 nr = obj_reloc_count(ob, cs->obj_sec);
if (nr > 0xFFFFu) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_coff: section %u has %u relocs (max 65535)",
(u32)cs->obj_sec, nr);
}
@@ -432,7 +427,7 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
const ObjSym* s = e.sym;
if (s->removed) continue;
if (s->kind == SK_IFUNC) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_coff: SK_IFUNC has no PE/COFF representation");
}
/* Don't re-emit SK_SECTION symbols — section symbols are
@@ -576,7 +571,7 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
if (r->removed) continue;
if (r->section_id != cs->obj_sec) continue;
if (r->sym == OBJ_SYM_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_coff: reloc without symbol not supported "
"(sec=%u offset=%u kind=%u)",
(u32)r->section_id, (u32)r->offset, (u32)r->kind);
@@ -589,7 +584,7 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
* encode a separate explicit addend. kit's MCEmitter writes
* the addend inline for COFF targets, so this branch only
* fires for inputs synthesized by external tools. */
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_coff: explicit nonzero addend not supported "
"(sec=%u offset=%u kind=%u addend=%lld)",
(u32)r->section_id, (u32)r->offset, (u32)r->kind,
@@ -600,7 +595,7 @@ void emit_coff(Compiler* c, ObjBuilder* ob, Writer* w) {
* unsupported-input sentinel; treat that as a panic unless the
* input really is R_NONE. */
if (wire == 0 && r->kind != R_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_coff: unsupported relocation kind %u for arch %u",
(u32)r->kind, (u32)c->target.arch);
}
diff --git a/src/obj/coff/link.c b/src/obj/coff/link.c
@@ -68,11 +68,6 @@
* export name table), so 0 is the canonical "no hint" value. */
#define PE_IMPORT_HINT_NONE 0u
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- PE/Win64 layout constants ----
*
* Centralised here so the wire-format numbers in this TU stay named
@@ -282,14 +277,14 @@ static u64 coff_symbol_final_va(const LinkImage* img,
const char* what) {
const LinkSymbol* s = LinkSyms_at(&img->syms, id - 1);
if (!s->defined || s->kind == SK_ABS) {
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_emit_coff: `%.*s` is not a defined section-bound "
"symbol",
SLICE_ARG(slice_from_cstr(what)));
}
const LinkSection* sec = coff_symbol_section(img, s);
if (!sec) {
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_emit_coff: `%.*s` has no containing section",
SLICE_ARG(slice_from_cstr(what)));
}
@@ -310,7 +305,7 @@ static void coff_plan_tls_layout(LinkImage* img, CoffSection out[COFF_NBUCKETS],
tls->tls_size = out[COFF_BUCKET_TLS].size;
tls->tls_index_sym = coff_find_tls_index_sym(img);
if (tls->tls_index_sym == LINK_SYM_NONE) {
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_emit_coff: .tls section requires `_tls_index` "
"(provided by mingw libmingwex / tlsmcrt.o) — none of "
"the linked inputs define it");
@@ -514,7 +509,7 @@ static int coff_collect_imports(LinkImage* img, CoffImportTable* it) {
if (!s->imported) continue;
if (s->name == 0) continue;
if (s->dso_input_id == LINK_INPUT_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: imported symbol has no providing DSO");
}
/* img->globals only carries defined globals/weaks; imported undefs
@@ -532,12 +527,12 @@ static int coff_collect_imports(LinkImage* img, CoffImportTable* it) {
if (dup) continue;
}
if (s->dso_input_id - 1u >= LinkInputs_count(&l->inputs)) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: import dso_input_id out of range");
}
in = LinkInputs_at(&l->inputs, s->dso_input_id - 1u);
if (in->soname == 0) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: providing DSO has no soname; cannot "
"emit IMAGE_IMPORT_DESCRIPTOR.Name");
}
@@ -550,13 +545,13 @@ static int coff_collect_imports(LinkImage* img, CoffImportTable* it) {
}
if (dll_idx == (u32)-1) {
if (VEC_GROW(heap, it->dlls, dll_cap, it->ndlls + 1u))
- compiler_panic(c, no_loc(), "link_emit_coff: oom on import dlls");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom on import dlls");
dll_idx = it->ndlls++;
memset(&it->dlls[dll_idx], 0, sizeof(it->dlls[dll_idx]));
it->dlls[dll_idx].soname = in->soname;
}
if (VEC_GROW(heap, it->imports, imp_cap, it->nimports + 1u))
- compiler_panic(c, no_loc(), "link_emit_coff: oom on imports");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom on imports");
memset(&it->imports[it->nimports], 0, sizeof(it->imports[it->nimports]));
it->imports[it->nimports].sym = s->id;
it->imports[it->nimports].dll_idx = dll_idx;
@@ -640,7 +635,7 @@ static void coff_plan_idata_layout(LinkImage* img, CoffImportTable* it) {
size_t nlen = 0;
const char* nm = coff_import_lookup_name(c, s, &nlen);
if (!nm || nlen == 0)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: imported symbol has empty name");
it->imports[i].hint_off = off;
/* hint (2 B) + name (nlen + 1) + optional pad to even. */
@@ -658,7 +653,7 @@ static void coff_plan_idata_layout(LinkImage* img, CoffImportTable* it) {
const char* nm = nm_s.s;
size_t nlen = nm_s.len;
if (!nm || nlen == 0)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: providing DSO has empty soname");
it->dlls[d].name_off = off;
off += (u32)nlen + 1u;
@@ -682,7 +677,7 @@ static void coff_append_stubs(LinkImage* img, CoffImportTable* it,
u32 stub_align;
u64 cur;
if (!arch || arch->stub_size == 0 || !arch->emit_iat_stub) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: arch has no COFF IAT stub emitter");
}
stub_size = arch->stub_size;
@@ -728,7 +723,7 @@ static void coff_emit_stubs(LinkImage* img, const CoffImportTable* it,
u32 text_rva = out[COFF_BUCKET_TEXT].rva;
u32 idata_rva = out[COFF_BUCKET_IDATA].rva;
if (!arch || !arch->emit_iat_stub) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: arch has no COFF IAT stub emitter");
}
for (u32 i = 0; i < it->nimports; ++i) {
@@ -753,7 +748,7 @@ static void coff_emit_idata(LinkImage* img, const CoffImportTable* it,
u8* buf;
/* Allocate the bucket buffer (idata_size is already block-aligned). */
buf = (u8*)heap->alloc(heap, it->idata_size, _Alignof(u64));
- if (!buf) compiler_panic(c, no_loc(), "link_emit_coff: oom on .idata buffer");
+ if (!buf) compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom on .idata buffer");
memset(buf, 0, it->idata_size);
idata->bytes = buf;
idata->size = it->idata_size;
@@ -824,7 +819,7 @@ static void coff_import_vaddr_build(LinkImage* img, const CoffImportTable* it,
iv->by_sym = (u64*)heap->alloc(heap, sizeof(u64) * (size_t)(iv->nsyms + 1u),
_Alignof(u64));
if (!iv->by_sym)
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link_emit_coff: oom on import vaddr table");
memset(iv->by_sym, 0, sizeof(u64) * (size_t)(iv->nsyms + 1u));
for (u32 i = 0; i < it->nimports; ++i) {
@@ -867,10 +862,10 @@ static u16 coff_machine_or_panic(Compiler* c) {
fmt && fmt->coff_arch ? fmt->coff_arch(c->target.arch) : NULL;
u16 m;
if (!arch)
- compiler_panic(c, no_loc(), "link_emit_coff: no COFF arch descriptor");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: no COFF arch descriptor");
m = arch->machine;
if (m != IMAGE_FILE_MACHINE_AMD64 && m != IMAGE_FILE_MACHINE_ARM64)
- compiler_panic(c, no_loc(), "link_emit_coff: unsupported machine 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: unsupported machine 0x%x",
(unsigned)m);
return m;
}
@@ -1027,7 +1022,7 @@ static void coff_build_buckets(LinkImage* img, CoffSection out[COFF_NBUCKETS],
_Alignof(const LinkSection*))
: NULL;
if (img->nsections && (!tls_sorted || !crt_sorted))
- compiler_panic(c, no_loc(), "link_emit_coff: oom sorting sections");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom sorting sections");
for (i = 0; i < img->nsections; ++i) {
const LinkSection* ls = &img->sections[i];
@@ -1200,7 +1195,7 @@ static void coff_build_reloc_section(LinkImage* img,
}
reloc->bytes = (u8*)heap->alloc(heap, blob_size, 4);
if (!reloc->bytes && blob_size)
- compiler_panic(c, no_loc(), "link_emit_coff: oom on .reloc blob");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom on .reloc blob");
memset(reloc->bytes, 0, blob_size);
reloc->size = blob_size;
/* Stash allocation size for free path. */
@@ -1286,7 +1281,7 @@ static void coff_apply_all_relocs(LinkImage* img,
if (tgt->imported) {
/* IAT-routed: stub vaddr (functions) / slot vaddr (data). */
if (!iv || iv->by_sym[r->target - 1u] == 0)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: imported target lacks IAT slot");
S = iv->by_sym[r->target - 1u];
} else if (tgt->kind == SK_ABS) {
@@ -1294,7 +1289,7 @@ static void coff_apply_all_relocs(LinkImage* img,
} else if (tgt->defined) {
tgt_sec = coff_symbol_section(img, tgt);
if (!tgt_sec) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: symbol vaddr 0x%llx has no "
"containing section",
(unsigned long long)tgt->vaddr);
@@ -1305,7 +1300,7 @@ static void coff_apply_all_relocs(LinkImage* img,
sym_off;
} else {
/* Undef and not imported — shouldn't survive resolve_undefs. */
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: unresolved non-imported symbol");
}
/* COFF-only section-relative kinds: the SECREL value is the
@@ -1317,7 +1312,7 @@ static void coff_apply_all_relocs(LinkImage* img,
r->kind == R_COFF_AARCH64_SECREL_LOW12A ||
r->kind == R_COFF_AARCH64_SECREL_HIGH12A) {
if (!tgt->defined || tgt->kind == SK_ABS) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: COFF SECREL/SECTION requires a "
"defined section-bound target symbol");
}
@@ -1490,14 +1485,14 @@ void link_emit_coff(LinkImage* img, Writer* w) {
Compiler* c = img->c;
u16 machine = coff_machine_or_panic(c);
if (img->entry_sym == LINK_SYM_NONE)
- compiler_panic(c, no_loc(), "link_emit_coff: no resolved entry symbol");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: no resolved entry symbol");
/* ---- pass 1: build buckets + per-section delta map ---- */
CoffSection out[COFF_NBUCKETS];
CoffSecMap* map = (CoffSecMap*)heap->alloc(
heap, sizeof(CoffSecMap) * (img->nsections + 1u), _Alignof(CoffSecMap));
if (!map && img->nsections)
- compiler_panic(c, no_loc(), "link_emit_coff: oom on section map");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_coff: oom on section map");
memset(map, 0, sizeof(CoffSecMap) * (img->nsections + 1u));
/* coff_build_buckets stashes per-bucket allocation caps in size_raw;
@@ -1653,12 +1648,12 @@ void link_emit_coff(LinkImage* img, Writer* w) {
* value. */
const LinkSymbol* entry_sym = LinkSyms_at(&img->syms, img->entry_sym - 1);
if (!entry_sym->defined || entry_sym->kind == SK_ABS)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: entry symbol is not a defined "
"image-relative function");
const LinkSection* entry_sec = coff_section_at(img, entry_sym->vaddr);
if (!entry_sec)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_coff: entry symbol has no containing "
"section");
u8 entry_bucket = map[entry_sec->id - 1].bucket;
diff --git a/src/obj/coff/read.c b/src/obj/coff/read.c
@@ -23,11 +23,6 @@
#include "obj/coff/coff.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- section-header scratch ---- */
typedef struct CSecRec {
@@ -169,7 +164,7 @@ static void resolve_sym_name(const u8* rec, const u8* strtab, u32 strtab_size,
static ObjBuilder* read_coff_short_import(Compiler* c, const char* name,
const u8* data, size_t len) {
if (len < COFF_IMPORT_OBJECT_HEADER_SIZE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: short-import record shorter than header");
/* Sig1 / Sig2 already checked by the caller. */
@@ -181,14 +176,14 @@ static ObjBuilder* read_coff_short_import(Compiler* c, const char* name,
u16 type_flags = coff_rd_u16(data + 18);
if ((u64)COFF_IMPORT_OBJECT_HEADER_SIZE + (u64)size_of_data > (u64)len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: short-import SizeOfData=%u extends past input "
"(len=%zu)",
size_of_data, len);
if (machine != IMAGE_FILE_MACHINE_AMD64 &&
machine != IMAGE_FILE_MACHINE_ARM64)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: short-import unsupported machine %#x",
(u32)machine);
@@ -205,7 +200,7 @@ static ObjBuilder* read_coff_short_import(Compiler* c, const char* name,
* directory hint/name tables. */
if (name_type == IMPORT_OBJECT_ORDINAL)
compiler_panic(
- c, no_loc(),
+ c, SRCLOC_NONE,
"read_coff: short-import by ordinal not implemented "
"(archive member \"%.*s\", ordinal %u). kit links "
"imports by name only; rebuild the consumer to import "
@@ -220,24 +215,24 @@ static ObjBuilder* read_coff_short_import(Compiler* c, const char* name,
while (sym_name_len < sym_name_max && body[sym_name_len] != '\0')
++sym_name_len;
if (sym_name_len == sym_name_max)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: short-import symbol name not NUL-terminated");
/* DLL name: NUL-terminated starting after the symbol name's NUL. */
u32 dll_name_off = sym_name_len + 1u;
if (dll_name_off >= size_of_data)
- compiler_panic(c, no_loc(), "read_coff: short-import missing DLL name");
+ compiler_panic(c, SRCLOC_NONE, "read_coff: short-import missing DLL name");
const u8* dll_p = body + dll_name_off;
u32 dll_name_max = size_of_data - dll_name_off;
u32 dll_name_len = 0;
while (dll_name_len < dll_name_max && dll_p[dll_name_len] != '\0')
++dll_name_len;
if (dll_name_len == dll_name_max)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: short-import DLL name not NUL-terminated");
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_coff: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_coff: obj_new failed");
/* Pick SymKind by import type: CODE -> function, DATA/CONST -> object.
* Both are defined at section_id=OBJ_SEC_NONE, value=0, size=0 — the
@@ -282,7 +277,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
/* ---- Step 0: header validation ---- */
if (len < COFF_FILE_HEADER_SIZE)
- compiler_panic(c, no_loc(), "read_coff: input shorter than COFF header");
+ compiler_panic(c, SRCLOC_NONE, "read_coff: input shorter than COFF header");
/* Microsoft short-import record? (Sig1=0, Sig2=0xFFFF.) These live
* as members of .lib archives and stand in for a long-form import
@@ -302,7 +297,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
/* data + 18: Characteristics (2 bytes, currently ignored). */
if (size_opt_hdr != 0)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: input has optional header (size=%u); "
"use read_coff_pe for executables",
(u32)size_opt_hdr);
@@ -310,21 +305,21 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
if (machine != IMAGE_FILE_MACHINE_AMD64 &&
machine != IMAGE_FILE_MACHINE_ARM64 &&
machine != IMAGE_FILE_MACHINE_ARM64EC)
- compiler_panic(c, no_loc(), "read_coff: unsupported machine %#x",
+ compiler_panic(c, SRCLOC_NONE, "read_coff: unsupported machine %#x",
(u32)machine);
const ObjFormatImpl* fmt = obj_format_lookup(KIT_OBJ_COFF);
const ObjCoffArchOps* coff =
fmt && fmt->coff_machine ? fmt->coff_machine(machine) : NULL;
if (!coff || !coff->reloc_from)
- compiler_panic(c, no_loc(), "read_coff: no arch impl for machine %#x",
+ compiler_panic(c, SRCLOC_NONE, "read_coff: no arch impl for machine %#x",
(u32)machine);
u32 (*reloc_from)(u32) = coff->reloc_from;
if ((u64)COFF_FILE_HEADER_SIZE +
(u64)nsections * (u64)COFF_SECTION_HEADER_SIZE >
(u64)len)
- compiler_panic(c, no_loc(), "read_coff: section header table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_coff: section header table out of range");
/* ---- Step 1: bootstrap, locate strtab ---- */
/* Strtab is at PointerToSymbolTable + NumberOfSymbols * 18. When the
@@ -334,7 +329,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
if (ptr_to_symtab && nsymbols) {
u64 symtab_end = (u64)ptr_to_symtab + (u64)nsymbols * (u64)COFF_SYMBOL_SIZE;
if (symtab_end + COFF_STRTAB_SIZE_FIELD_BYTES > (u64)len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: symbol table / strtab header out of range");
u32 declared = coff_rd_u32(data + symtab_end);
/* The size field is inclusive of the 4-byte prefix; treat <4 as
@@ -342,7 +337,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
if (declared < COFF_STRTAB_SIZE_FIELD_BYTES) declared = 0;
if (declared) {
if (symtab_end + (u64)declared > (u64)len)
- compiler_panic(c, no_loc(), "read_coff: strtab body out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_coff: strtab body out of range");
strtab = data + symtab_end;
strtab_size = declared;
} else {
@@ -352,7 +347,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
}
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_coff: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_coff: obj_new failed");
/* ---- Step 2: ingest sections ---- */
CSecRec* secs = arena_array(c->scratch, CSecRec, nsections ? nsections : 1);
@@ -376,7 +371,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
ObjSecId id = obj_section_ex(ob, sn, (SecKind)kind, (SecSem)sem, flags,
align, 0u, 0u, 0u);
if (id == OBJ_SEC_NONE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: obj_section_ex failed for section %u", i);
s->obj_sec = id;
@@ -391,7 +386,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
} else if (s->size_of_raw_data) {
u64 end = (u64)s->pointer_to_raw_data + (u64)s->size_of_raw_data;
if (end > (u64)len)
- compiler_panic(c, no_loc(), "read_coff: section %u bytes out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_coff: section %u bytes out of range",
i);
u8* dst = obj_reserve(ob, id, s->size_of_raw_data);
memcpy(dst, data + s->pointer_to_raw_data, s->size_of_raw_data);
@@ -414,7 +409,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
const u8* sym_base = data + ptr_to_symtab;
if (nsymbols) {
if ((u64)ptr_to_symtab + (u64)nsymbols * (u64)COFF_SYMBOL_SIZE > (u64)len)
- compiler_panic(c, no_loc(), "read_coff: symbol table body out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_coff: symbol table body out of range");
}
for (u32 i = 0; i < nsymbols;) {
@@ -441,7 +436,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
* bytes; concatenate then trim trailing NULs. */
u32 total = (u32)naux * COFF_SYMBOL_SIZE;
if ((u64)i + 1u + (u64)naux > (u64)nsymbols)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: FILE aux records extend past symbol "
"table");
const u8* aux = p + COFF_SYMBOL_SIZE;
@@ -555,7 +550,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
kind = SK_OBJ;
}
} else {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: symbol section number %d out of range",
(int)sec_num);
}
@@ -634,7 +629,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
u64 reloc_end = (u64)s->pointer_to_relocations +
(u64)s->number_of_relocations * (u64)COFF_RELOC_SIZE;
if (reloc_end > (u64)len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: relocation table for section %u out of range",
i);
const u8* rbase = data + s->pointer_to_relocations;
@@ -646,7 +641,7 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data,
u32 kind = reloc_from(r_type);
if (kind == (u32)-1)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff: unsupported reloc type %u for machine %#x",
(u32)r_type, (u32)machine);
diff --git a/src/obj/coff/read_dso.c b/src/obj/coff/read_dso.c
@@ -27,11 +27,6 @@
#include "core/slice.h"
#include "obj/coff/coff.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- RVA -> file offset ----
* Walks the section table once per call. Returns 1 on success and
* fills *off_out; returns 0 if the RVA falls outside every section's
@@ -88,20 +83,20 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
/* ---- DOS header + PE signature ---- */
if (len < COFF_DOS_HEADER_SIZE)
- compiler_panic(c, no_loc(), "read_coff_dso: input shorter than DOS header");
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: input shorter than DOS header");
u16 e_magic = coff_rd_u16(data + 0);
if (e_magic != IMAGE_DOS_SIGNATURE)
- compiler_panic(c, no_loc(), "read_coff_dso: bad DOS magic 0x%x", e_magic);
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad DOS magic 0x%x", e_magic);
u32 e_lfanew = coff_rd_u32(data + 60);
u64 nt_end = (u64)e_lfanew + 4u + COFF_FILE_HEADER_SIZE + COFF_OPT_HDR64_SIZE;
if (nt_end > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: PE headers extend past end of file");
u32 pe_sig = coff_rd_u32(data + e_lfanew);
if (pe_sig != IMAGE_NT_SIGNATURE)
- compiler_panic(c, no_loc(), "read_coff_dso: bad PE signature 0x%x", pe_sig);
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad PE signature 0x%x", pe_sig);
/* ---- IMAGE_FILE_HEADER ---- */
const u8* fh = data + e_lfanew + 4u;
@@ -112,13 +107,13 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
if (machine != IMAGE_FILE_MACHINE_AMD64 &&
machine != IMAGE_FILE_MACHINE_ARM64)
- compiler_panic(c, no_loc(), "read_coff_dso: unsupported machine 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: unsupported machine 0x%x",
machine);
if (!(chars & IMAGE_FILE_DLL))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: not a DLL (Characteristics=0x%x)", chars);
if (size_of_opt < COFF_OPT_HDR64_SIZE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: SizeOfOptionalHeader %u too small for PE32+",
size_of_opt);
@@ -126,7 +121,7 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
const u8* oh = fh + COFF_FILE_HEADER_SIZE;
u16 opt_magic = coff_rd_u16(oh + 0);
if (opt_magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: not PE32+ (optional header Magic=0x%x)",
opt_magic);
@@ -143,12 +138,12 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
u64 shdrs_off = (u64)e_lfanew + 4u + COFF_FILE_HEADER_SIZE + size_of_opt;
u64 shdrs_end = shdrs_off + (u64)nsec * COFF_SECTION_HEADER_SIZE;
if (shdrs_end > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: section table extends past end of file");
const u8* shdrs = data + shdrs_off;
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_coff_dso: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_coff_dso: obj_new failed");
/* No export directory => empty DSO (legal for stub DLLs). */
if (export_size == 0 || export_rva == 0) {
@@ -158,11 +153,11 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
u64 exp_off;
if (!rva_to_offset(shdrs, nsec, export_rva, len, &exp_off))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: export directory RVA 0x%x out of range",
export_rva);
if (exp_off + COFF_EXPORT_DIR_SIZE > len)
- compiler_panic(c, no_loc(), "read_coff_dso: export directory truncated");
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: export directory truncated");
const u8* ed = data + exp_off;
u32 name_rva = coff_rd_u32(ed + 12);
@@ -178,7 +173,7 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
if (name_rva) {
u64 name_off;
if (!rva_to_offset(shdrs, nsec, name_rva, len, &name_off))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: DLL name RVA 0x%x out of range", name_rva);
const char* dll_name;
u32 nlen = read_cstr(data, len, name_off, &dll_name);
@@ -191,21 +186,21 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data,
u64 eat_off = 0, ent_off = 0, ord_off = 0;
if (num_names) {
if (!rva_to_offset(shdrs, nsec, eat_rva, len, &eat_off))
- compiler_panic(c, no_loc(), "read_coff_dso: EAT RVA 0x%x out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: EAT RVA 0x%x out of range",
eat_rva);
if (!rva_to_offset(shdrs, nsec, ent_rva, len, &ent_off))
- compiler_panic(c, no_loc(), "read_coff_dso: ENT RVA 0x%x out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: ENT RVA 0x%x out of range",
ent_rva);
if (!rva_to_offset(shdrs, nsec, ord_rva, len, &ord_off))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: ordinal table RVA 0x%x out of range",
ord_rva);
if (ent_off + (u64)num_names * 4u > len ||
ord_off + (u64)num_names * 2u > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_coff_dso: ENT/ordinal table extends past file");
if (eat_off + (u64)num_funcs * 4u > len)
- compiler_panic(c, no_loc(), "read_coff_dso: EAT extends past file");
+ compiler_panic(c, SRCLOC_NONE, "read_coff_dso: EAT extends past file");
}
/* ---- walk the ENT ----
diff --git a/src/obj/elf/emit.c b/src/obj/elf/emit.c
@@ -36,11 +36,6 @@
#include "obj/elf/elf.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- per-ELF-section plan record ---- */
/* Internal section descriptor used during planning. Mirrors Elf64_Shdr
@@ -211,16 +206,16 @@ void emit_elf(Compiler* c, ObjBuilder* ob, Writer* w) {
u32 e_machine;
u32 (*reloc_to)(u32);
if (!elf || !elf->reloc_to) {
- compiler_panic(c, no_loc(), "emit_elf: unsupported target arch %u",
+ compiler_panic(c, SRCLOC_NONE, "emit_elf: unsupported target arch %u",
(u32)c->target.arch);
}
e_machine = elf->e_machine;
reloc_to = elf->reloc_to;
if (c->target.big_endian) {
- compiler_panic(c, no_loc(), "emit_elf: big-endian ELF not supported");
+ compiler_panic(c, SRCLOC_NONE, "emit_elf: big-endian ELF not supported");
}
if (c->target.ptr_size != 8) {
- compiler_panic(c, no_loc(), "emit_elf: ptr_size %u (expected 8)",
+ compiler_panic(c, SRCLOC_NONE, "emit_elf: ptr_size %u (expected 8)",
(u32)c->target.ptr_size);
}
@@ -460,7 +455,7 @@ void emit_elf(Compiler* c, ObjBuilder* ob, Writer* w) {
u32 etype = reloc_to(r->kind);
if (etype == ELF_R_AARCH64_NONE /* == ELF_R_X86_64_NONE == 0 */ &&
r->kind != R_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_elf: unsupported relocation kind %u for arch %u",
(u32)r->kind, (u32)c->target.arch);
}
diff --git a/src/obj/elf/link.c b/src/obj/elf/link.c
@@ -59,11 +59,6 @@
#include "obj/elf/elf.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- ELF64 wire structs (subset) ---- */
#define EI_NIDENT 16
@@ -257,7 +252,7 @@ static void emit_dyn_record(LinkImage* img, u64 site_vaddr, u32 reloc_type,
LinkDynState* dyn = img->dyn;
if (!dyn || !dyn->rela_dyn) return;
if (dyn->nrela_dyn >= dyn->cap_rela_dyn) {
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: too many .rela.dyn records (%u >= %u); raise "
"cap_rela_dyn in layout_dyn",
dyn->nrela_dyn, dyn->cap_rela_dyn);
@@ -273,7 +268,7 @@ static const ObjElfArchOps* elf_arch_or_panic(Compiler* c, const char* where) {
const ObjElfArchOps* arch =
fmt && fmt->elf_arch ? fmt->elf_arch(c->target.arch) : NULL;
if (!arch)
- compiler_panic(c, no_loc(), "%.*s: no ELF arch descriptor",
+ compiler_panic(c, SRCLOC_NONE, "%.*s: no ELF arch descriptor",
SLICE_ARG(slice_from_cstr(where)));
return arch;
}
@@ -309,7 +304,7 @@ static i64 rv_pcrel_lo12_disp(LinkImage* img, u64 auipc_vaddr, u64 img_base) {
hi_P = hi->write_vaddr + img_base;
return (i64)hi_S + hi->addend - (i64)hi_P;
}
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: PCREL_LO12 at 0x%llx has no paired PCREL_HI20",
(unsigned long long)auipc_vaddr);
return 0;
@@ -421,7 +416,7 @@ static void apply_all_relocs(LinkImage* img, u64 img_base) {
? img->dyn->sym_plt_vaddr[canon_id]
: 0u;
if (plt_v == 0)
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: imported sym has no PLT entry (CALL26)");
S = plt_v + img_base;
link_reloc_apply(img->c, r->kind, P_bytes, S, r->addend, P);
@@ -429,7 +424,7 @@ static void apply_all_relocs(LinkImage* img, u64 img_base) {
}
if (reloc_is_abs(r->kind)) {
if (dynidx == 0)
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: imported sym has no .dynsym entry");
emit_globdat_record(img, r->write_vaddr, dynidx, r->addend);
/* Site bytes are irrelevant: the loader's GLOB_DAT writes
@@ -444,7 +439,7 @@ static void apply_all_relocs(LinkImage* img, u64 img_base) {
const char* nm = nm_s.s ? nm_s.s : "";
size_t nl = nm_s.len;
compiler_panic(
- img->c, no_loc(),
+ img->c, SRCLOC_NONE,
"link: unhandled reloc kind %u against imported symbol '%.*s'",
(unsigned)r->kind, (int)nl, nm);
}
@@ -668,7 +663,7 @@ void link_emit_elf(LinkImage* img, Writer* w) {
const ObjElfArchOps* arch = elf_arch_or_panic(c, "link_emit_elf");
u32 e_machine = arch->e_machine;
if (img->entry_sym == LINK_SYM_NONE)
- compiler_panic(c, no_loc(), "link_emit_elf: no resolved entry symbol");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_elf: no resolved entry symbol");
/* IFUNC trampolines: layout_iplt builds the .iplt stubs + .igot.plt
* slots and (when emit_static_exe was set) synthesizes a
* .init_array entry that calls __kit_ifunc_init at startup. The
@@ -787,7 +782,7 @@ void link_emit_elf(LinkImage* img, Writer* w) {
* would overflow the section. Instead, panic with a clear
* message — the soname was supposed to be added during
* layout. */
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link_emit_elf: DT_NEEDED soname missing from "
".dynstr");
}
@@ -899,14 +894,14 @@ void link_emit_elf(LinkImage* img, Writer* w) {
u32 outshdr_cap = img->nsections + 1u;
outshdrs = (OutShdr*)heap->alloc(heap, sizeof(*outshdrs) * outshdr_cap,
_Alignof(OutShdr));
- if (!outshdrs) compiler_panic(c, no_loc(), "link_emit_elf: oom on outshdrs");
+ if (!outshdrs) compiler_panic(c, SRCLOC_NONE, "link_emit_elf: oom on outshdrs");
memset(outshdrs, 0, sizeof(*outshdrs) * outshdr_cap);
{
/* Build a sort index over LinkSection ids by (segment_id, vaddr). */
u32* order = (u32*)heap->alloc(heap, sizeof(u32) * (img->nsections + 1u),
_Alignof(u32));
if (!order && img->nsections)
- compiler_panic(c, no_loc(), "link_emit_elf: oom on shdr sort");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_elf: oom on shdr sort");
u32 i, j;
for (i = 0; i < img->nsections; ++i) order[i] = i;
/* Insertion sort — section count is small. */
@@ -963,7 +958,7 @@ void link_emit_elf(LinkImage* img, Writer* w) {
u32* outshdr_name_off =
(u32*)heap->alloc(heap, sizeof(u32) * (noutshdr + 1u), _Alignof(u32));
if (!outshdr_name_off && noutshdr)
- compiler_panic(c, no_loc(), "link_emit_elf: oom on shdr name table");
+ compiler_panic(c, SRCLOC_NONE, "link_emit_elf: oom on shdr name table");
{
u32 i;
for (i = 0; i < noutshdr; ++i) {
@@ -1000,7 +995,7 @@ void link_emit_elf(LinkImage* img, Writer* w) {
SymRec* recs = (SymRec*)heap->alloc(
heap, sizeof(*recs) * (LinkSyms_count(&img->syms) + 1u),
_Alignof(SymRec));
- if (!recs) compiler_panic(c, no_loc(), "link_emit_elf: oom on symrecs");
+ if (!recs) compiler_panic(c, SRCLOC_NONE, "link_emit_elf: oom on symrecs");
u32 nsyms_emit = 0;
u32 first_global_idx;
memset(&recs[nsyms_emit++], 0, sizeof(*recs)); /* slot 0 */
@@ -1105,7 +1100,7 @@ void link_emit_elf(LinkImage* img, Writer* w) {
/* ---- build phdrs ---- */
Phdr64* phdrs = (Phdr64*)heap->alloc(heap, sizeof(Phdr64) * nphdr_total,
_Alignof(Phdr64));
- if (!phdrs) compiler_panic(c, no_loc(), "link_emit_elf: oom on phdrs");
+ if (!phdrs) compiler_panic(c, SRCLOC_NONE, "link_emit_elf: oom on phdrs");
memset(phdrs, 0, sizeof(Phdr64) * nphdr_total);
{
u32 pi = 0;
diff --git a/src/obj/elf/link_dyn.c b/src/obj/elf/link_dyn.c
@@ -45,11 +45,6 @@
#include "obj/elf/elf.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- small allocators (mirror layout_iplt's helpers) ---- */
static u32 dyn_alloc_segments(LinkImage* img, u32 nseg) {
@@ -67,7 +62,7 @@ static u32 dyn_alloc_segments(LinkImage* img, u32 nseg) {
sizeof(*img->segment_bytes_cap) * img->nsegments,
sizeof(*img->segment_bytes_cap) * new_nseg, _Alignof(size_t));
if (!nsegs || !nsbufs || !nscaps)
- compiler_panic(img->c, no_loc(), "link: oom on dyn segments");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on dyn segments");
img->segments = nsegs;
img->segment_bytes = nsbufs;
img->segment_bytes_cap = nscaps;
@@ -81,7 +76,7 @@ static u32 dyn_alloc_sections(LinkImage* img, u32 nsec) {
LinkSection* nsections = (LinkSection*)h->realloc(
h, img->sections, sizeof(*img->sections) * img->nsections,
sizeof(*img->sections) * new_nsec, _Alignof(LinkSection));
- if (!nsections) compiler_panic(img->c, no_loc(), "link: oom on dyn sections");
+ if (!nsections) compiler_panic(img->c, SRCLOC_NONE, "link: oom on dyn sections");
img->sections = nsections;
return base;
}
@@ -217,11 +212,11 @@ static void collect_imports(Linker* l, LinkImage* img, Heap* h,
int is_func = sym_is_func_import(s) || dso_export_is_func(l, s);
if (is_func) {
if (VEC_GROW(h, il->funcs, cap_f, il->nfuncs + 1u))
- compiler_panic(img->c, no_loc(), "link: oom on import-funcs");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on import-funcs");
il->funcs[il->nfuncs++] = s->id;
} else {
if (VEC_GROW(h, il->datas, cap_d, il->ndatas + 1u))
- compiler_panic(img->c, no_loc(), "link: oom on import-datas");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on import-datas");
il->datas[il->ndatas++] = s->id;
}
}
@@ -242,7 +237,7 @@ static void collect_needed(Linker* l, LinkImage* img, LinkDynState* dyn) {
u32 i, nused = 0;
used = (u8*)h->alloc(h, ninputs ? ninputs : 1u, 1);
- if (!used) compiler_panic(img->c, no_loc(), "link: oom on needed map");
+ if (!used) compiler_panic(img->c, SRCLOC_NONE, "link: oom on needed map");
memset(used, 0, ninputs ? ninputs : 1u);
/* Mark every DSO that ended up satisfying at least one import. */
@@ -267,7 +262,7 @@ static void collect_needed(Linker* l, LinkImage* img, LinkDynState* dyn) {
dyn->needed =
nused ? (Sym*)h->alloc(h, sizeof(Sym) * nused, _Alignof(Sym)) : NULL;
if (nused && !dyn->needed)
- compiler_panic(img->c, no_loc(), "link: oom on needed list");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on needed list");
dyn->nneeded = 0;
for (i = 0; i < ninputs; ++i) {
LinkInput* in = LinkInputs_at(&l->inputs, i);
@@ -303,7 +298,7 @@ static void build_dynsym(LinkImage* img, LinkDynState* dyn,
dyn->ndynsym = ndynsym;
dyn->dynsym = (DynSymRec*)h->alloc(h, sizeof(*dyn->dynsym) * ndynsym,
_Alignof(DynSymRec));
- if (!dyn->dynsym) compiler_panic(img->c, no_loc(), "link: oom on dynsym");
+ if (!dyn->dynsym) compiler_panic(img->c, SRCLOC_NONE, "link: oom on dynsym");
memset(dyn->dynsym, 0, sizeof(*dyn->dynsym) * ndynsym);
/* Slot 0: STN_UNDEF. dynstr leads with a NUL so st_name=0 reads as
@@ -320,14 +315,14 @@ static void build_dynsym(LinkImage* img, LinkDynState* dyn,
dyn->sym_dynidx = (u32*)h->alloc(
h, sizeof(*dyn->sym_dynidx) * dyn->sym_dynidx_size, _Alignof(u32));
if (!dyn->sym_dynidx)
- compiler_panic(img->c, no_loc(), "link: oom on sym_dynidx");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on sym_dynidx");
memset(dyn->sym_dynidx, 0, sizeof(*dyn->sym_dynidx) * dyn->sym_dynidx_size);
/* sym_plt_vaddr is populated alongside the PLT body emit below; here
* we only allocate the parallel array. */
dyn->sym_plt_vaddr = (u64*)h->alloc(
h, sizeof(*dyn->sym_plt_vaddr) * dyn->sym_dynidx_size, _Alignof(u64));
if (!dyn->sym_plt_vaddr)
- compiler_panic(img->c, no_loc(), "link: oom on sym_plt_vaddr");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on sym_plt_vaddr");
memset(dyn->sym_plt_vaddr, 0,
sizeof(*dyn->sym_plt_vaddr) * dyn->sym_dynidx_size);
@@ -406,7 +401,7 @@ static void build_gnu_hash(Heap* h, LinkImage* img, LinkDynState* dyn,
u32 total = hdr_bytes + bloom_bytes + buckets_bytes + chains_bytes;
u8* buf = (u8*)h->alloc(h, total ? total : 1u, 4);
- if (!buf) compiler_panic(img->c, no_loc(), "link: oom on .gnu.hash");
+ if (!buf) compiler_panic(img->c, SRCLOC_NONE, "link: oom on .gnu.hash");
memset(buf, 0, total);
wr_u32_le(buf + 0, nbuckets);
@@ -419,7 +414,7 @@ static void build_gnu_hash(Heap* h, LinkImage* img, LinkDynState* dyn,
u32 i;
u32* hashes = (u32*)h->alloc(h, sizeof(u32) * hashed, _Alignof(u32));
if (!hashes)
- compiler_panic(img->c, no_loc(), "link: oom on .gnu.hash hashes");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on .gnu.hash hashes");
for (i = 0; i < hashed; ++i) {
const DynSymRec* r = &dyn->dynsym[sym_offset + i];
const char* name = (const char*)dynstr->data + r->st_name;
@@ -514,17 +509,17 @@ void layout_dyn(Linker* l, LinkImage* img) {
arch = link_arch_desc_for(l->c);
if (!arch)
- compiler_panic(img->c, no_loc(), "link: layout_dyn: no arch descriptor");
+ compiler_panic(img->c, SRCLOC_NONE, "link: layout_dyn: no arch descriptor");
{
const ObjFormatImpl* fmt = obj_format_lookup(KIT_OBJ_ELF);
elf_arch = fmt && fmt->elf_arch ? fmt->elf_arch(l->c->target.arch) : NULL;
if (!elf_arch)
- compiler_panic(img->c, no_loc(),
+ compiler_panic(img->c, SRCLOC_NONE,
"link: layout_dyn: no ELF arch descriptor");
}
dyn = (LinkDynState*)h->alloc(h, sizeof(*dyn), _Alignof(LinkDynState));
- if (!dyn) compiler_panic(img->c, no_loc(), "link: oom on dyn state");
+ if (!dyn) compiler_panic(img->c, SRCLOC_NONE, "link: oom on dyn state");
memset(dyn, 0, sizeof(*dyn));
img->dyn = dyn;
img->pie = 1;
@@ -586,7 +581,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
_Alignof(DynRela))
: NULL;
if (imports.nfuncs && !dyn->rela_plt)
- compiler_panic(img->c, no_loc(), "link: oom on rela_plt");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on rela_plt");
/* RELA dyn: GLOB_DAT (one per imported abs-relocated symbol) +
* RELATIVE (one per PIE internal abs reloc against a defined sym).
@@ -615,7 +610,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
_Alignof(DynRela))
: NULL;
if (dyn->cap_rela_dyn && !dyn->rela_dyn)
- compiler_panic(img->c, no_loc(), "link: oom on rela_dyn");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on rela_dyn");
dyn->nrela_dyn = 0;
Slice interp_s = pool_slice(l->c->global, dyn->interp_path);
@@ -722,7 +717,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
ro_seg_size ? (u8*)h->alloc(h, (size_t)ro_seg_size, 16) : NULL;
img->segment_bytes_cap[ro_seg_idx] = (size_t)ro_seg_size;
if (ro_seg_size && !img->segment_bytes[ro_seg_idx])
- compiler_panic(img->c, no_loc(), "link: oom on ro dyn segment");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on ro dyn segment");
if (ro_seg_size)
memset(img->segment_bytes[ro_seg_idx], 0, (size_t)ro_seg_size);
@@ -740,7 +735,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
img->segment_bytes[rx_seg_idx] = (u8*)h->alloc(h, (size_t)plt_bytes, 16);
img->segment_bytes_cap[rx_seg_idx] = (size_t)plt_bytes;
if (!img->segment_bytes[rx_seg_idx])
- compiler_panic(img->c, no_loc(), "link: oom on .plt segment");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on .plt segment");
memset(img->segment_bytes[rx_seg_idx], 0, (size_t)plt_bytes);
/* Stash plt / got.plt vaddrs now — the PLT body emit just below
* reads them, and the post-shift fixup in shift_image_addresses
@@ -751,7 +746,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
dyn->got_plt_size = gotplt_bytes;
/* PLT body emit: the descriptor owns the psABI-specific bytes. */
if (!arch->emit_plt0 || !arch->emit_plt_entry)
- compiler_panic(l->c, no_loc(), "link: PLT emit not configured");
+ compiler_panic(l->c, SRCLOC_NONE, "link: PLT emit not configured");
{
u8* plt_b = img->segment_bytes[rx_seg_idx];
u32 ki;
@@ -782,7 +777,7 @@ void layout_dyn(Linker* l, LinkImage* img) {
img->segment_bytes[rw_seg_idx] = (u8*)h->alloc(h, (size_t)rw_seg_size, 16);
img->segment_bytes_cap[rw_seg_idx] = (size_t)rw_seg_size;
if (!img->segment_bytes[rw_seg_idx])
- compiler_panic(img->c, no_loc(), "link: oom on rw dyn segment");
+ compiler_panic(img->c, SRCLOC_NONE, "link: oom on rw dyn segment");
/* Zero-initialize. .got.plt[0] (&.dynamic) is filled later, after
* shift_image_addresses has bumped dyn->dynamic_vaddr. .dynamic
* body is built post-shift in link_emit_elf. Loader
diff --git a/src/obj/elf/read.c b/src/obj/elf/read.c
@@ -23,11 +23,6 @@
#include "obj/elf/elf.h"
#include "obj/format.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- shdr scratch struct ---- */
typedef struct ShdrRec {
@@ -249,7 +244,7 @@ static void read_elf_image(Compiler* c, ObjBuilder* ob, const u8* data,
u32 (*reloc_from)(u32)) {
ObjImage* im =
obj_image_ensure(ob, e_type == ET_DYN ? OBJ_KIND_DYN : OBJ_KIND_EXEC);
- if (!im) compiler_panic(c, no_loc(), "read_elf: obj_image_ensure failed");
+ if (!im) compiler_panic(c, SRCLOC_NONE, "read_elf: obj_image_ensure failed");
obj_image_set_entry(im, rd_u64_le(data + 24));
@@ -262,10 +257,10 @@ static void read_elf_image(Compiler* c, ObjBuilder* ob, const u8* data,
u64 image_base = 0;
if (e_phnum) {
if (e_phentsize != ELF64_PHDR_SIZE)
- compiler_panic(c, no_loc(), "read_elf: unexpected e_phentsize %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: unexpected e_phentsize %u",
(u32)e_phentsize);
if (e_phoff + (u64)e_phnum * ELF64_PHDR_SIZE > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: program header table out of range");
for (u16 i = 0; i < e_phnum; ++i) {
const u8* p = data + e_phoff + (u64)i * ELF64_PHDR_SIZE;
@@ -437,17 +432,17 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
(void)name;
if (len < ELF64_EHDR_SIZE)
- compiler_panic(c, no_loc(), "read_elf: input shorter than ELF header");
+ compiler_panic(c, SRCLOC_NONE, "read_elf: input shorter than ELF header");
if (data[EI_MAG0] != ELFMAG0 || data[EI_MAG1] != ELFMAG1 ||
data[EI_MAG2] != ELFMAG2 || data[EI_MAG3] != ELFMAG3)
- compiler_panic(c, no_loc(), "read_elf: bad ELF magic");
+ compiler_panic(c, SRCLOC_NONE, "read_elf: bad ELF magic");
if (data[EI_CLASS] != ELFCLASS64)
- compiler_panic(c, no_loc(), "read_elf: not ELFCLASS64 (got %u)",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: not ELFCLASS64 (got %u)",
data[EI_CLASS]);
if (data[EI_DATA] != ELFDATA2LSB)
- compiler_panic(c, no_loc(), "read_elf: not ELFDATA2LSB (got %u)",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: not ELFDATA2LSB (got %u)",
data[EI_DATA]);
u16 e_type = rd_u16_le(data + 16);
@@ -456,7 +451,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
* section tables still parse through the same passes. ET_CORE and other
* types are out of scope (see doc/plan/IMAGE_INSPECT.md). */
if (e_type != ET_REL && e_type != ET_EXEC && e_type != ET_DYN)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: unsupported e_type=%u (expected ET_REL, "
"ET_EXEC, or ET_DYN)",
(u32)e_type);
@@ -467,7 +462,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
fmt && fmt->elf_machine ? fmt->elf_machine(e_machine) : NULL;
u32 (*reloc_from)(u32);
if (!arch || !arch->reloc_from) {
- compiler_panic(c, no_loc(), "read_elf: unsupported e_machine 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: unsupported e_machine 0x%x",
(u32)e_machine);
}
reloc_from = arch->reloc_from;
@@ -487,17 +482,17 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
int has_sht = (e_shoff != 0 && e_shnum != 0);
if (has_sht) {
if (e_shentsize != ELF64_SHDR_SIZE)
- compiler_panic(c, no_loc(), "read_elf: unexpected e_shentsize %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: unexpected e_shentsize %u",
(u32)e_shentsize);
if (e_shoff + (u64)e_shnum * ELF64_SHDR_SIZE > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: section header table out of range");
if (e_shstrndx >= e_shnum)
- compiler_panic(c, no_loc(), "read_elf: e_shstrndx %u >= e_shnum %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: e_shstrndx %u >= e_shnum %u",
(u32)e_shstrndx, (u32)e_shnum);
} else {
if (e_type == ET_REL)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: ET_REL with no section header table");
e_shnum = 0; /* normalize so the section/symbol/reloc passes are no-ops */
}
@@ -513,14 +508,14 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
const ShdrRec* shstr_sh = &shdrs[e_shstrndx];
if (shstr_sh->sh_offset + shstr_sh->sh_size > len)
- compiler_panic(c, no_loc(), "read_elf: .shstrtab out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf: .shstrtab out of range");
shstrtab = data + shstr_sh->sh_offset;
shstrtab_sz = shstr_sh->sh_size;
}
/* Build the ObjBuilder. */
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_elf: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_elf: obj_new failed");
obj_set_elf_e_flags(ob, e_flags);
/* elf_to_obj[shndx] -> ObjSecId, OBJ_SEC_NONE for skipped sections. */
@@ -559,7 +554,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
obj_section_ex(ob, sym, (SecKind)sec_kind, (SecSem)sec_sem, flags,
align, (u32)sh->sh_entsize, sh->sh_link, sh->sh_info);
if (id == OBJ_SEC_NONE)
- compiler_panic(c, no_loc(), "read_elf: obj_section_ex failed for '%.*s'",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: obj_section_ex failed for '%.*s'",
SLICE_ARG(((Slice){.s = nm, .len = nlen})));
elf_to_obj[i] = id;
@@ -582,7 +577,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
obj_reserve_bss(ob, id, (u32)sh->sh_size, align);
} else if (sh->sh_size) {
if (sh->sh_offset + sh->sh_size > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: section '%.*s' bytes out of range",
SLICE_ARG(((Slice){.s = nm, .len = nlen})));
/* For SYMTAB/STRTAB/RELA we still copy the raw bytes — the
@@ -611,18 +606,18 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
if (symtab_shndx) {
const ShdrRec* sh = &shdrs[symtab_shndx];
if (sh->sh_entsize != ELF64_SYM_SIZE)
- compiler_panic(c, no_loc(), "read_elf: .symtab entsize %llu != %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: .symtab entsize %llu != %u",
(unsigned long long)sh->sh_entsize, (u32)ELF64_SYM_SIZE);
if (sh->sh_size % ELF64_SYM_SIZE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: .symtab size %llu not a multiple of %u",
(unsigned long long)sh->sh_size, (u32)ELF64_SYM_SIZE);
if (sh->sh_link >= e_shnum)
- compiler_panic(c, no_loc(), "read_elf: .symtab sh_link %u out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: .symtab sh_link %u out of range",
sh->sh_link);
const ShdrRec* str_sh = &shdrs[sh->sh_link];
if (str_sh->sh_offset + str_sh->sh_size > len)
- compiler_panic(c, no_loc(), "read_elf: .strtab out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf: .strtab out of range");
const u8* strtab = data + str_sh->sh_offset;
u64 strtab_sz = str_sh->sh_size;
@@ -665,7 +660,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
sec_id = elf_to_obj[st_shndx];
value = st_value;
} else {
- compiler_panic(c, no_loc(), "read_elf: symbol shndx %u out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: symbol shndx %u out of range",
(u32)st_shndx);
sec_id = OBJ_SEC_NONE;
value = 0; /* unreachable */
@@ -695,10 +690,10 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
u32 entsize = is_rela ? ELF64_RELA_SIZE : 16;
if (sh->sh_entsize != entsize)
- compiler_panic(c, no_loc(), "read_elf: rela entsize %llu != %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: rela entsize %llu != %u",
(unsigned long long)sh->sh_entsize, entsize);
if (sh->sh_info == 0 || sh->sh_info >= e_shnum)
- compiler_panic(c, no_loc(), "read_elf: rela sh_info %u out of range",
+ compiler_panic(c, SRCLOC_NONE, "read_elf: rela sh_info %u out of range",
sh->sh_info);
ObjSecId target = elf_to_obj[sh->sh_info];
if (target == OBJ_SEC_NONE) continue;
@@ -715,7 +710,7 @@ ObjBuilder* read_elf(Compiler* c, const char* name, const u8* data,
u32 kind = reloc_from(etype);
if (kind == (u32)-1)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf: unsupported reloc type %u for e_machine 0x%x",
etype, (u32)e_machine);
@@ -807,18 +802,18 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
if (soname_out) *soname_out = 0;
if (len < ELF64_EHDR_SIZE)
- compiler_panic(c, no_loc(), "read_elf_dso: input shorter than ELF header");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: input shorter than ELF header");
if (data[EI_MAG0] != ELFMAG0 || data[EI_MAG1] != ELFMAG1 ||
data[EI_MAG2] != ELFMAG2 || data[EI_MAG3] != ELFMAG3)
- compiler_panic(c, no_loc(), "read_elf_dso: bad ELF magic");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: bad ELF magic");
if (data[EI_CLASS] != ELFCLASS64)
- compiler_panic(c, no_loc(), "read_elf_dso: not ELFCLASS64");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: not ELFCLASS64");
if (data[EI_DATA] != ELFDATA2LSB)
- compiler_panic(c, no_loc(), "read_elf_dso: not ELFDATA2LSB");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: not ELFDATA2LSB");
u16 e_type = rd_u16_le(data + 16);
if (e_type != ET_DYN)
- compiler_panic(c, no_loc(), "read_elf_dso: expected ET_DYN, got e_type=%u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: expected ET_DYN, got e_type=%u",
(u32)e_type);
u16 e_machine = rd_u16_le(data + 18);
@@ -827,7 +822,7 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
const ObjElfArchOps* arch =
fmt && fmt->elf_machine ? fmt->elf_machine(e_machine) : NULL;
if (!arch)
- compiler_panic(c, no_loc(), "read_elf_dso: unsupported e_machine 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: unsupported e_machine 0x%x",
(u32)e_machine);
}
@@ -840,13 +835,13 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
u16 e_shstrndx = rd_u16_le(data + 62);
if (e_shentsize != ELF64_SHDR_SIZE)
- compiler_panic(c, no_loc(), "read_elf_dso: unexpected e_shentsize %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: unexpected e_shentsize %u",
(u32)e_shentsize);
if (e_shoff + (u64)e_shnum * ELF64_SHDR_SIZE > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf_dso: section header table out of range");
if (e_shstrndx >= e_shnum)
- compiler_panic(c, no_loc(), "read_elf_dso: e_shstrndx out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: e_shstrndx out of range");
ShdrRec* shdrs = arena_array(c->scratch, ShdrRec, e_shnum);
for (u32 i = 0; i < e_shnum; ++i)
@@ -861,7 +856,7 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
}
if (!dynsym_idx)
- compiler_panic(c, no_loc(), "read_elf_dso: no SHT_DYNSYM in shared object");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: no SHT_DYNSYM in shared object");
/* Parse PT_DYNAMIC for DT_SONAME. The .dynamic section gives us the
* dynstr to resolve the SONAME's offset; if there's no .dynamic
@@ -870,17 +865,17 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
if (dynamic_idx) {
const ShdrRec* dsh = &shdrs[dynamic_idx];
if (dsh->sh_link >= e_shnum)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf_dso: .dynamic sh_link %u out of range",
dsh->sh_link);
const ShdrRec* str_sh = &shdrs[dsh->sh_link];
if (str_sh->sh_offset + str_sh->sh_size > len)
- compiler_panic(c, no_loc(), "read_elf_dso: .dynamic strtab out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: .dynamic strtab out of range");
const u8* dynstr = data + str_sh->sh_offset;
u64 dynstr_sz = str_sh->sh_size;
if (dsh->sh_offset + dsh->sh_size > len)
- compiler_panic(c, no_loc(), "read_elf_dso: .dynamic body out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: .dynamic body out of range");
const u8* dynp = data + dsh->sh_offset;
u64 dynsz = dsh->sh_size;
/* DT entries are 16 bytes: (d_tag: u64, d_un: u64). */
@@ -910,21 +905,21 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data,
/* Now parse .dynsym. */
const ShdrRec* sh = &shdrs[dynsym_idx];
if (sh->sh_entsize != ELF64_SYM_SIZE)
- compiler_panic(c, no_loc(), "read_elf_dso: .dynsym entsize %llu != %u",
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: .dynsym entsize %llu != %u",
(unsigned long long)sh->sh_entsize, (u32)ELF64_SYM_SIZE);
if (sh->sh_size % ELF64_SYM_SIZE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_elf_dso: .dynsym size not multiple of entry size");
if (sh->sh_link >= e_shnum)
- compiler_panic(c, no_loc(), "read_elf_dso: .dynsym sh_link out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: .dynsym sh_link out of range");
const ShdrRec* str_sh = &shdrs[sh->sh_link];
if (str_sh->sh_offset + str_sh->sh_size > len)
- compiler_panic(c, no_loc(), "read_elf_dso: .dynstr out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_elf_dso: .dynstr out of range");
const u8* strtab = data + str_sh->sh_offset;
u64 strtab_sz = str_sh->sh_size;
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_elf_dso: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_elf_dso: obj_new failed");
u32 nsyms = (u32)(sh->sh_size / ELF64_SYM_SIZE);
const u8* base = data + sh->sh_offset;
diff --git a/src/obj/macho/emit.c b/src/obj/macho/emit.c
@@ -35,11 +35,6 @@
#include "obj/format.h"
#include "obj/macho/macho.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- LE writer helpers (Writer-based) ----
* Thin aliases onto the shared writer_u*_le helpers (core/bytes.h). */
@@ -241,7 +236,7 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
u32 (*reloc_length)(u32);
if (!macho || !macho->reloc_to || !macho->reloc_pcrel ||
!macho->reloc_length) {
- compiler_panic(c, no_loc(), "emit_macho: unsupported target arch %u",
+ compiler_panic(c, SRCLOC_NONE, "emit_macho: unsupported target arch %u",
(u32)c->target.arch);
}
cputype = macho->cputype;
@@ -250,10 +245,10 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
reloc_pcrel = macho->reloc_pcrel;
reloc_length = macho->reloc_length;
if (c->target.big_endian) {
- compiler_panic(c, no_loc(), "emit_macho: big-endian not supported");
+ compiler_panic(c, SRCLOC_NONE, "emit_macho: big-endian not supported");
}
if (c->target.ptr_size != 8) {
- compiler_panic(c, no_loc(), "emit_macho: ptr_size %u (expected 8)",
+ compiler_panic(c, SRCLOC_NONE, "emit_macho: ptr_size %u (expected 8)",
(u32)c->target.ptr_size);
}
@@ -312,7 +307,7 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
nsecs++;
}
if (nsecs > 255u) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: too many physical sections for Mach-O "
"symbol n_sect ordinals (%u > 255); use atom splitting "
"instead of physical split sections",
@@ -437,7 +432,7 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
type |= N_SECT;
u32 ms_idx = (s->section_id < nobjsec) ? obj_to_msec[s->section_id] : 0;
if (ms_idx > 255u) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: symbol section ordinal %u exceeds "
"Mach-O n_sect range",
ms_idx);
@@ -554,13 +549,13 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
? ARM64_RELOC_UNSIGNED
: X86_64_RELOC_UNSIGNED;
if (r->sym == OBJ_SYM_NONE || sub->sym == OBJ_SYM_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: symdiff reloc without symbol");
}
add_idx = sym_obj_to_macho[r->sym];
sub_idx = sym_obj_to_macho[sub->sym];
if (add_idx == 0 || sub_idx == 0) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: symdiff reloc target not in symtab");
}
{
@@ -585,7 +580,7 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
}
u32 mtype = reloc_to(r->kind);
if (mtype == (u32)-1) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: unsupported reloc kind %u for arch %u",
(u32)r->kind, (u32)c->target.arch);
}
@@ -596,14 +591,14 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) {
* an ObjSymId). Skip relocs without a symbol — they would map to
* a section-relative reloc which the v1 cgtarget never emits. */
if (r->sym == OBJ_SYM_NONE) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: reloc without symbol not supported "
"(sec=%u offset=%u kind=%u)",
(u32)r->section_id, (u32)r->offset, (u32)r->kind);
}
u32 mach_sym_idx = sym_obj_to_macho[r->sym];
if (mach_sym_idx == 0) {
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"emit_macho: reloc target sym %u not in symtab",
(u32)r->sym);
}
diff --git a/src/obj/macho/link.c b/src/obj/macho/link.c
@@ -53,11 +53,6 @@
#include "obj/format.h"
#include "obj/macho/macho.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- constants ---- */
#define MZ_PAGEZERO 0x100000000ULL
#define MZ_PAGE 0x4000ULL
@@ -398,7 +393,7 @@ static void collect_imports(MCtx* x) {
x->sym_to_imp =
(u32*)h->alloc(h, sizeof(u32) * x->sym_to_imp_size, _Alignof(u32));
if (!x->sym_to_imp)
- compiler_panic(x->c, no_loc(), "link_macho: oom on sym_to_imp");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on sym_to_imp");
memset(x->sym_to_imp, 0, sizeof(u32) * x->sym_to_imp_size);
u32 cap = 0, cap_d = 0;
@@ -409,7 +404,7 @@ static void collect_imports(MCtx* x) {
LinkSymId canon = symhash_get(&img->globals, s->name);
if (canon != LINK_SYM_NONE && canon != s->id) continue;
if (VEC_GROW(h, x->imports, cap, x->nimports + 1u))
- compiler_panic(x->c, no_loc(), "link_macho: oom on imports");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on imports");
MachImp* mi = &x->imports[x->nimports++];
memset(mi, 0, sizeof(*mi));
mi->sym = s->id;
@@ -458,7 +453,7 @@ static void collect_imports(MCtx* x) {
u32 ord = dylib_ordinal_of(x, install);
if (!ord) {
if (VEC_GROW(h, x->dylibs, cap_d, x->ndylibs + 1u))
- compiler_panic(x->c, no_loc(), "link_macho: oom on dylibs");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on dylibs");
x->dylibs[x->ndylibs].install = install;
++x->ndylibs;
ord = x->ndylibs;
@@ -474,7 +469,7 @@ static void collect_imports(MCtx* x) {
if (in->soname == 0) continue;
if (dylib_ordinal_of(x, in->soname)) continue;
if (VEC_GROW(h, x->dylibs, cap_d, x->ndylibs + 1u))
- compiler_panic(x->c, no_loc(), "link_macho: oom on dylibs");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on dylibs");
x->dylibs[x->ndylibs].install = in->soname;
++x->ndylibs;
}
@@ -516,7 +511,7 @@ static void collect_imports(MCtx* x) {
}
}
if (VEC_GROW(h, x->imports, cap, x->nimports + 1u))
- compiler_panic(x->c, no_loc(), "link_macho: oom on internal got");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on internal got");
MachImp* mi = &x->imports[x->nimports++];
memset(mi, 0, sizeof(*mi));
mi->sym = canon;
@@ -562,7 +557,7 @@ static void collect_tlv(MCtx* x) {
x->sym_to_tlv =
(u32*)h->alloc(h, sizeof(u32) * x->sym_to_tlv_size, _Alignof(u32));
if (!x->sym_to_tlv)
- compiler_panic(x->c, no_loc(), "link_macho: oom on sym_to_tlv");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on sym_to_tlv");
memset(x->sym_to_tlv, 0, sizeof(u32) * x->sym_to_tlv_size);
u32 cap = 0;
@@ -589,7 +584,7 @@ static void collect_tlv(MCtx* x) {
continue;
}
if (VEC_GROW(h, x->tlv_slots, cap, x->ntlv + 1u))
- compiler_panic(x->c, no_loc(), "link_macho: oom on tlv_slots");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on tlv_slots");
MachTlv* ts = &x->tlv_slots[x->ntlv++];
memset(ts, 0, sizeof(*ts));
ts->sym = canon;
@@ -724,7 +719,7 @@ static void plan_layout(MCtx* x) {
* since pie wasn't set on this Linker. Still, oversize by a few.) */
u32 cap = LinkRelocs_count(&img->relocs) + img->nsections + 4u;
x->secs = (MSec*)h->alloc(h, sizeof(MSec) * cap, _Alignof(MSec));
- if (!x->secs) compiler_panic(x->c, no_loc(), "link_macho: oom on MSec");
+ if (!x->secs) compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on MSec");
memset(x->secs, 0, sizeof(MSec) * cap);
x->nsecs = 0;
@@ -775,7 +770,7 @@ static void plan_layout(MCtx* x) {
x->stubs_size = x->nimport_funcs * x->macho->stub_size;
x->stubs_bytes = (u8*)h->alloc(h, x->stubs_size, 4);
if (!x->stubs_bytes)
- compiler_panic(x->c, no_loc(), "link_macho: oom on stubs");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on stubs");
memset(x->stubs_bytes, 0, x->stubs_size);
MSec* m = &x->secs[x->nsecs++];
memset(m, 0, sizeof(*m));
@@ -798,7 +793,7 @@ static void plan_layout(MCtx* x) {
if (x->nimports) {
x->got_size = x->nimports * MZ_GOT_SIZE;
x->got_bytes = (u8*)h->alloc(h, x->got_size, 8);
- if (!x->got_bytes) compiler_panic(x->c, no_loc(), "link_macho: oom on got");
+ if (!x->got_bytes) compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on got");
memset(x->got_bytes, 0, x->got_size);
MSec* m = &x->secs[x->nsecs++];
memset(m, 0, sizeof(*m));
@@ -885,7 +880,7 @@ static void plan_layout(MCtx* x) {
x->tlv_ptrs_size = x->ntlv * MZ_TLVP_SIZE;
x->tlv_ptrs_bytes = (u8*)h->alloc(h, x->tlv_ptrs_size, 8);
if (!x->tlv_ptrs_bytes)
- compiler_panic(x->c, no_loc(), "link_macho: oom on tlv_ptrs");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on tlv_ptrs");
memset(x->tlv_ptrs_bytes, 0, x->tlv_ptrs_size);
MSec* m = &x->secs[x->nsecs++];
memset(m, 0, sizeof(*m));
@@ -1187,7 +1182,7 @@ static void plan_layout(MCtx* x) {
u32* order =
(u32*)h->alloc(h, sizeof(u32) * (x->nsecs + 1u), _Alignof(u32));
if (!order && x->nsecs)
- compiler_panic(x->c, no_loc(), "link_macho: oom on outsec sort");
+ compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on outsec sort");
for (u32 i = 0; i < x->nsecs; ++i) order[i] = i;
/* Insertion sort — section count is small. */
for (u32 i = 1; i < x->nsecs; ++i) {
@@ -1206,7 +1201,7 @@ static void plan_layout(MCtx* x) {
}
u32 cap = x->nsecs + 1u;
x->outs = (OutSec*)h->alloc(h, sizeof(OutSec) * cap, _Alignof(OutSec));
- if (!x->outs) compiler_panic(x->c, no_loc(), "link_macho: oom on OutSec");
+ if (!x->outs) compiler_panic(x->c, SRCLOC_NONE, "link_macho: oom on OutSec");
memset(x->outs, 0, sizeof(OutSec) * cap);
x->nouts = 0;
for (u32 i = 0; i < x->nsecs; ++i) {
@@ -1218,7 +1213,7 @@ static void plan_layout(MCtx* x) {
if (merge) {
if (tail->flags != m->flags || tail->is_zerofill != m->is_zerofill)
compiler_panic(
- x->c, no_loc(),
+ x->c, SRCLOC_NONE,
"link_macho: coalesce mismatch on %.*s,%.*s (flags/zerofill)",
SLICE_ARG(slice_from_cstr(m->segname)),
SLICE_ARG(slice_from_cstr(m->sectname)));
@@ -1258,7 +1253,7 @@ static void plan_layout(MCtx* x) {
}
for (u32 i = 0; i < x->nsegs; ++i) {
if (prev_nouts[i] != x->segs[i].nouts)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: OutSec count drift seg %u (%u vs %u)",
(u32)i, prev_nouts[i], x->segs[i].nouts);
}
@@ -1489,7 +1484,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
u32 tlv_idx =
(r->target < x->sym_to_tlv_size) ? x->sym_to_tlv[r->target] : 0u;
if (!tlv_idx)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: TLVP reloc has no __thread_ptrs slot");
u64 slot_v = x->tlv_ptrs_vaddr + (tlv_idx - 1u) * MZ_TLVP_SIZE;
link_reloc_apply(x->c, r->kind, P_bytes, slot_v, r->addend, P);
@@ -1501,7 +1496,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
if (x->link_arch->is_branch_reloc &&
x->link_arch->is_branch_reloc(r->kind)) {
if (!mi || !mi->stub_idx)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: import has no stub for branch");
u64 stub_v = x->stubs_vaddr + (mi->stub_idx - 1u) * x->macho->stub_size;
link_reloc_apply(x->c, r->kind, P_bytes, stub_v, r->addend, P);
@@ -1510,7 +1505,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
if (x->link_arch->is_got_load_reloc &&
x->link_arch->is_got_load_reloc(r->kind)) {
if (!mi)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: GOT reloc for unknown import");
u64 got_v = x->got_vaddr + (mi->got_idx - 1u) * MZ_GOT_SIZE;
link_reloc_apply(x->c, r->kind, P_bytes, got_v, r->addend, P);
@@ -1520,7 +1515,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
x->link_arch->is_direct_page_reloc(r->kind)) {
/* Direct page/lo12 against an import: route through __got. */
if (!mi)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: PAGE/LO12 against unknown import");
u64 got_v = x->got_vaddr + (mi->got_idx - 1u) * MZ_GOT_SIZE;
link_reloc_apply(x->c, r->kind, P_bytes, got_v, r->addend, P);
@@ -1533,7 +1528,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
fix_push(fl, &fs);
continue;
}
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: unhandled reloc kind %u against imported "
"symbol",
(u32)r->kind);
@@ -1614,7 +1609,7 @@ static void apply_relocs(MCtx* x, FixList* fl) {
u8* slot = x->tlv_ptrs_bytes + (ts->tlv_idx - 1u) * MZ_TLVP_SIZE;
if (ts->imported) {
if (!ts->import_idx)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: imported TLV without matching import slot");
wr_u64_le(slot, 0);
FixSite fs = {3u, 1, {0}, ts->import_idx, slot_v, 0};
@@ -1827,7 +1822,7 @@ static void build_chained_fixups(MCtx* x, FixList* fl) {
}
}
if (!slot)
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: chained-fixup slot for vaddr 0x%llx not "
"in any segment buffer",
(unsigned long long)s->vaddr);
@@ -1836,7 +1831,7 @@ static void build_chained_fixups(MCtx* x, FixList* fl) {
* uses 0-based. */
if (s->import_idx == 0 || s->import_idx > x->nimports_real) {
compiler_panic(
- x->c, no_loc(),
+ x->c, SRCLOC_NONE,
"link_macho: chained bind for vaddr 0x%llx uses import index "
"%u outside real import table size %u",
(unsigned long long)s->vaddr, (unsigned)s->import_idx,
@@ -1875,7 +1870,7 @@ static void build_chained_fixups(MCtx* x, FixList* fl) {
const char* nm = nm_s.s;
size_t nl = nm_s.len;
if (!nm || !nl || mi->dylib_ord == 0 || mi->dylib_ord > x->ndylibs) {
- compiler_panic(x->c, no_loc(),
+ compiler_panic(x->c, SRCLOC_NONE,
"link_macho: invalid chained import %u "
"(name=%u dylib_ord=%u ndylibs=%u)",
(unsigned)i, (unsigned)mi->name, (unsigned)mi->dylib_ord,
@@ -1974,7 +1969,7 @@ static void build_exports_trie(MCtx* x) {
uleb128(out, leaf_pos);
/* leaf node */
if (out->len != leaf_pos)
- compiler_panic(x->c, no_loc(), "macho: exports trie leaf offset mismatch");
+ compiler_panic(x->c, SRCLOC_NONE, "macho: exports trie leaf offset mismatch");
/* terminal_size byte then payload */
mbuf_u8(out, (u8)leaf_payload_len);
uleb128(out, flags);
@@ -2393,10 +2388,10 @@ void link_emit_macho(LinkImage* img, Writer* w) {
if (!x.link_arch || !x.macho || !x.macho->cputype || !x.macho->emit_stub ||
!x.macho->stub_size)
- compiler_panic(x.c, no_loc(),
+ compiler_panic(x.c, SRCLOC_NONE,
"link_emit_macho: no Mach-O descriptor for target");
if (img->entry_sym == LINK_SYM_NONE)
- compiler_panic(x.c, no_loc(), "link_emit_macho: no resolved entry");
+ compiler_panic(x.c, SRCLOC_NONE, "link_emit_macho: no resolved entry");
collect_imports(&x);
collect_tlv(&x);
@@ -2406,9 +2401,9 @@ void link_emit_macho(LinkImage* img, Writer* w) {
/* entry offset within __TEXT segment. */
LinkSymbol* esym = sym_at(img, img->entry_sym);
if (!esym || !esym->defined)
- compiler_panic(x.c, no_loc(), "link_emit_macho: entry symbol undefined");
+ compiler_panic(x.c, SRCLOC_NONE, "link_emit_macho: entry symbol undefined");
if (esym->vaddr < x.text_vaddr)
- compiler_panic(x.c, no_loc(),
+ compiler_panic(x.c, SRCLOC_NONE,
"link_emit_macho: entry symbol below __TEXT base");
x.entry_offset = (u32)(esym->vaddr - x.text_vaddr);
@@ -2579,7 +2574,7 @@ void link_emit_macho(LinkImage* img, Writer* w) {
/* Sanity: lc.len + MACHO_HDR64_SIZE must equal headers_size we
* predicted in plan_layout. If not, we mis-sized — panic. */
if ((u64)lc.len + MACHO_HDR64_SIZE != x.headers_size) {
- compiler_panic(x.c, no_loc(),
+ compiler_panic(x.c, SRCLOC_NONE,
"link_macho: load-cmd size mismatch: predicted %llu got %u",
(unsigned long long)(x.headers_size - MACHO_HDR64_SIZE),
lc.len);
diff --git a/src/obj/macho/read.c b/src/obj/macho/read.c
@@ -23,11 +23,6 @@
#include "obj/format.h"
#include "obj/macho/macho.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- mach-section scratch struct ---- */
typedef struct MSecRec {
@@ -155,7 +150,7 @@ static void read_macho_image(Compiler* c, ObjBuilder* ob, const u8* data,
const MSecRec* msecs, u32 nmsecs) {
ObjImage* im =
obj_image_ensure(ob, filetype == MH_DYLIB ? OBJ_KIND_DYN : OBJ_KIND_EXEC);
- if (!im) compiler_panic(c, no_loc(), "read_macho: obj_image_ensure failed");
+ if (!im) compiler_panic(c, SRCLOC_NONE, "read_macho: obj_image_ensure failed");
u32 ncmds = rd_u32_le(data + 16);
u32 sizeofcmds = rd_u32_le(data + 20);
@@ -405,11 +400,11 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
size_t len) {
(void)name;
if (len < MACHO_HDR64_SIZE)
- compiler_panic(c, no_loc(), "read_macho: input shorter than header");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: input shorter than header");
u32 magic = rd_u32_le(data + 0);
if (magic != MH_MAGIC_64)
- compiler_panic(c, no_loc(), "read_macho: bad magic 0x%x", magic);
+ compiler_panic(c, SRCLOC_NONE, "read_macho: bad magic 0x%x", magic);
u32 cputype = rd_u32_le(data + 4);
const ObjFormatImpl* fmt = obj_format_lookup(KIT_OBJ_MACHO);
@@ -421,19 +416,19 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
u32 mh_flags = rd_u32_le(data + 24);
if (!macho || !macho->reloc_from)
- compiler_panic(c, no_loc(), "read_macho: unsupported cputype 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "read_macho: unsupported cputype 0x%x",
cputype);
/* MH_OBJECT parses to the section/symbol/reloc view only. MH_EXECUTE /
* MH_DYLIB additionally get the linked-image view (read_macho_image, at
* the end); their sections still parse through the same passes. */
if (filetype != MH_OBJECT && filetype != MH_EXECUTE && filetype != MH_DYLIB)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho: unsupported filetype %u (expected MH_OBJECT, "
"MH_EXECUTE, or MH_DYLIB)",
filetype);
if ((u64)MACHO_HDR64_SIZE + sizeofcmds > len)
- compiler_panic(c, no_loc(), "read_macho: load commands exceed file");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: load commands exceed file");
/* ---- pass 1: walk load commands, collect sections, symtab cmd. */
MSecRec* msecs = NULL;
@@ -446,12 +441,12 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
u32 cmd = rd_u32_le(data + pos);
u32 cmdsize = rd_u32_le(data + pos + 4);
if (cmdsize < 8 || pos + cmdsize > end)
- compiler_panic(c, no_loc(), "read_macho: malformed load command");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: malformed load command");
if (cmd == LC_SEGMENT_64) {
u32 nsects = rd_u32_le(data + pos + 64);
if (MACHO_SEGCMD64_SIZE + (u64)nsects * MACHO_SECT64_SIZE > cmdsize)
- compiler_panic(c, no_loc(), "read_macho: segment cmd truncated");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: segment cmd truncated");
MSecRec* extra = arena_array(c->scratch, MSecRec, nmsecs + nsects);
if (msecs && nmsecs) memcpy(extra, msecs, sizeof(MSecRec) * nmsecs);
msecs = extra;
@@ -482,13 +477,13 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
}
if (stroff + (u64)strsize > len)
- compiler_panic(c, no_loc(), "read_macho: string table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: string table out of range");
if (symoff + (u64)nsyms * MACHO_NLIST64_SIZE > len)
- compiler_panic(c, no_loc(), "read_macho: symbol table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: symbol table out of range");
const u8* strtab = data + stroff;
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_macho: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_macho: obj_new failed");
/* ---- pass 2: create ObjSecs and copy bytes. */
for (u32 i = 0; i < nmsecs; ++i) {
@@ -513,7 +508,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
ObjSecId id = obj_section_ex(ob, sn, (SecKind)kind, (SecSem)sem, flags,
align, m->reserved2, 0, 0);
if (id == OBJ_SEC_NONE)
- compiler_panic(c, no_loc(), "read_macho: obj_section_ex failed");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: obj_section_ex failed");
/* Preserve the raw mach section.flags so emit_macho can write back
* the same S_TYPE / S_ATTR_* bits. */
@@ -523,7 +518,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
obj_reserve_bss(ob, id, (u32)m->size, align);
} else if (m->size) {
if (m->fileoff + m->size > len)
- compiler_panic(c, no_loc(), "read_macho: section bytes out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: section bytes out of range");
obj_write(ob, id, data + m->fileoff, (size_t)m->size);
}
m->obj_sec = id;
@@ -680,7 +675,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
MSecRec* m = &msecs[i];
if (!m->nreloc) continue;
if (m->reloff + (u64)m->nreloc * MACHO_RELOC_SIZE > len)
- compiler_panic(c, no_loc(), "read_macho: relocation table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho: relocation table out of range");
const u8* rp = data + m->reloff;
i64 pending_addend = 0;
int have_pending = 0;
@@ -715,7 +710,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
kind = macho->reloc_from(r_type);
}
if (kind == (u32)-1)
- compiler_panic(c, no_loc(), "read_macho: unsupported reloc type %u",
+ compiler_panic(c, SRCLOC_NONE, "read_macho: unsupported reloc type %u",
r_type);
/* Refine kind by (r_pcrel, r_length) when the type field alone
@@ -743,7 +738,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
* at r_address to pick the right RelocKind so the applier in
* link_reloc.c shifts the lo12 correctly. */
if (m->fileoff + r_address + 4u > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho: PAGEOFF12 r_address %u out of range",
r_address);
u32 ins = rd_u32_le(data + m->fileoff + r_address);
@@ -780,7 +775,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
if (!have_pending && r_type == ARM64_RELOC_UNSIGNED) {
u32 rsz = 1u << r_length;
if ((u64)m->fileoff + r_address + rsz > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho: extern unsigned reloc r_address out "
"of range");
const u8* pv = data + m->fileoff + r_address;
@@ -805,7 +800,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
* per section) and re-express the reloc as
* target = sec_start_sym, addend = inplace - section.addr. */
if (r_symbolnum == 0 || r_symbolnum > nmsecs)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho: section-relative reloc references "
"invalid section index %u",
r_symbolnum);
@@ -836,7 +831,7 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data,
target = sec_start_sym[sec_idx];
u32 rsz = 1u << r_length;
if ((u64)m->fileoff + r_address + rsz > len)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho: non-extern reloc r_address out of range");
u64 inplace;
const u8* pv = data + m->fileoff + r_address;
@@ -896,11 +891,11 @@ ObjBuilder* read_macho_dso(Compiler* c, const char* name, const u8* data,
(void)name;
if (install_name_out) *install_name_out = 0;
if (len < MACHO_HDR64_SIZE)
- compiler_panic(c, no_loc(), "read_macho_dso: input shorter than header");
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: input shorter than header");
u32 magic = rd_u32_le(data + 0);
if (magic != MH_MAGIC_64)
- compiler_panic(c, no_loc(), "read_macho_dso: bad magic 0x%x", magic);
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: bad magic 0x%x", magic);
u32 cputype = rd_u32_le(data + 4);
u32 filetype = rd_u32_le(data + 12);
@@ -912,15 +907,15 @@ ObjBuilder* read_macho_dso(Compiler* c, const char* name, const u8* data,
const ObjMachoArchOps* macho =
fmt && fmt->macho_cputype ? fmt->macho_cputype(cputype) : NULL;
if (!macho)
- compiler_panic(c, no_loc(), "read_macho_dso: unsupported cputype 0x%x",
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: unsupported cputype 0x%x",
cputype);
}
if (filetype != MH_DYLIB && filetype != MH_BUNDLE)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_macho_dso: not MH_DYLIB/MH_BUNDLE (filetype=%u)",
filetype);
if ((u64)MACHO_HDR64_SIZE + sizeofcmds > len)
- compiler_panic(c, no_loc(), "read_macho_dso: load commands exceed file");
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: load commands exceed file");
u32 symoff = 0, nsyms = 0, stroff = 0, strsize = 0;
Sym install_name = 0;
@@ -931,7 +926,7 @@ ObjBuilder* read_macho_dso(Compiler* c, const char* name, const u8* data,
u32 cmd = rd_u32_le(data + pos);
u32 cmdsize = rd_u32_le(data + pos + 4);
if (cmdsize < 8 || pos + cmdsize > end)
- compiler_panic(c, no_loc(), "read_macho_dso: malformed load command");
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: malformed load command");
if (cmd == LC_ID_DYLIB) {
/* dylib_command: cmd, cmdsize, name(lc_str: 4-byte offset within
* the cmd), timestamp, current_version, compat_version. */
@@ -957,12 +952,12 @@ ObjBuilder* read_macho_dso(Compiler* c, const char* name, const u8* data,
if (install_name_out) *install_name_out = install_name;
if (stroff + (u64)strsize > len)
- compiler_panic(c, no_loc(), "read_macho_dso: string table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: string table out of range");
if (symoff + (u64)nsyms * MACHO_NLIST64_SIZE > len)
- compiler_panic(c, no_loc(), "read_macho_dso: symbol table out of range");
+ compiler_panic(c, SRCLOC_NONE, "read_macho_dso: symbol table out of range");
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_macho_dso: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_macho_dso: obj_new failed");
const u8* strtab = data + stroff;
const u8* sbase = data + symoff;
diff --git a/src/obj/macho/tbd_read.c b/src/obj/macho/tbd_read.c
@@ -44,11 +44,6 @@
#include "core/slice.h"
#include "obj/obj.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
static int is_id_start(u8 c) { return c == '_'; }
static int is_id_cont(u8 c) {
return (c == '_') || (c == '$') || (c == '.') || (c >= 'A' && c <= 'Z') ||
@@ -95,11 +90,11 @@ ObjBuilder* read_tbd(Compiler* c, const char* name, const u8* data, size_t len,
Sym* install_name_out) {
(void)name;
if (install_name_out) *install_name_out = 0;
- if (!data || !len) compiler_panic(c, no_loc(), "read_tbd: empty input");
+ if (!data || !len) compiler_panic(c, SRCLOC_NONE, "read_tbd: empty input");
/* Validate magic: a tbd starts with `--- !tapi-tbd` (or any `---`). */
if (len < 4 || data[0] != '-' || data[1] != '-' || data[2] != '-')
- compiler_panic(c, no_loc(), "read_tbd: not a tbd file (missing '---')");
+ compiler_panic(c, SRCLOC_NONE, "read_tbd: not a tbd file (missing '---')");
/* Reject obviously-wrong target arches up front so we don't stream a
* bunch of irrelevant symbols in. */
@@ -108,13 +103,13 @@ ObjBuilder* read_tbd(Compiler* c, const char* name, const u8* data, size_t len,
case KIT_ARCH_X86_64:
break;
default:
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"read_tbd: unsupported target arch %u for tbd lookup",
(u32)c->target.arch);
}
ObjBuilder* ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_tbd: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_tbd: obj_new failed");
if (install_name_out) *install_name_out = extract_install_name(c, data, len);
diff --git a/src/obj/reloc_apply.c b/src/obj/reloc_apply.c
@@ -20,11 +20,6 @@
#include "core/bytes.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* ---- ULEB128 codec for R_RISCV_{SET,SUB}_ULEB128 ----
*
* These RISC-V relocs patch a variable-length ULEB128 field in place
@@ -118,7 +113,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
return;
}
case R_X64_COPY:
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: R_X64_COPY belongs in dynamic loader, "
"not static link");
return;
@@ -143,7 +138,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
case R_X64_PC8: {
i64 v = (i64)S + A - (i64)P;
if (v < -128 || v > 127)
- compiler_panic(c, no_loc(), "link: X64_PC8 out of range");
+ compiler_panic(c, SRCLOC_NONE, "link: X64_PC8 out of range");
P_bytes[0] = (u8)((u64)v & 0xffu);
return;
}
@@ -174,10 +169,10 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 imm19;
if (disp & 3)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: imm19 reloc misaligned displacement");
if (disp < -(i64)(1 << 20) || disp >= (i64)(1 << 20))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: imm19 reloc out of range (need ±1MiB)");
imm19 = (u32)((disp >> 2) & 0x7ffffu);
instr = rd_u32_le(P_bytes);
@@ -192,9 +187,9 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 imm14;
if (disp & 3)
- compiler_panic(c, no_loc(), "link: TSTBR14 misaligned displacement");
+ compiler_panic(c, SRCLOC_NONE, "link: TSTBR14 misaligned displacement");
if (disp < -(i64)(1 << 15) || disp >= (i64)(1 << 15))
- compiler_panic(c, no_loc(), "link: TSTBR14 out of range (need ±32KiB)");
+ compiler_panic(c, SRCLOC_NONE, "link: TSTBR14 out of range (need ±32KiB)");
imm14 = (u32)((disp >> 2) & 0x3fffu);
instr = rd_u32_le(P_bytes);
instr = (instr & ~(0x3fffu << 5)) | (imm14 << 5);
@@ -208,7 +203,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 immlo, immhi;
if (disp < -(i64)(1 << 20) || disp >= (i64)(1 << 20))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: ADR_PREL_LO21 out of range (need ±1MiB)");
immlo = (u32)(disp & 0x3u);
immhi = (u32)((disp >> 2) & 0x7ffffu);
@@ -226,9 +221,9 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 imm26;
if (disp & 3)
- compiler_panic(c, no_loc(), "link: CALL26 misaligned displacement");
+ compiler_panic(c, SRCLOC_NONE, "link: CALL26 misaligned displacement");
if (disp < -(i64)(1 << 27) || disp >= (i64)(1 << 27))
- compiler_panic(c, no_loc(), "link: CALL26 out of range (need ±128MiB)");
+ compiler_panic(c, SRCLOC_NONE, "link: CALL26 out of range (need ±128MiB)");
imm26 = (u32)((disp >> 2) & 0x3ffffffu);
instr = rd_u32_le(P_bytes);
instr = (instr & 0xfc000000u) | imm26;
@@ -252,7 +247,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 immlo, immhi;
if (k != R_AARCH64_ADR_PREL_PG_HI21_NC &&
(imm21 < -(i64)(1 << 20) || imm21 >= (i64)(1 << 20)))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: ADR_PREL_PG_HI21 out of range (need ±4GiB)");
immlo = (u32)(imm21 & 0x3u);
immhi = (u32)((imm21 >> 2) & 0x7ffffu);
@@ -312,7 +307,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u64 imm12 = lo12 >> shift;
u32 instr = rd_u32_le(P_bytes);
if (lo12 & ((1u << shift) - 1u))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: LDST%u_ABS_LO12_NC misaligned address "
"(kind=%u S=0x%llx A=%lld P=0x%llx)",
1u << (3 + shift), (unsigned)k, (unsigned long long)S,
@@ -380,9 +375,9 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 b;
if (disp & 1)
- compiler_panic(c, no_loc(), "link: RV BRANCH misaligned displacement");
+ compiler_panic(c, SRCLOC_NONE, "link: RV BRANCH misaligned displacement");
if (disp < -(i64)(1 << 12) || disp >= (i64)(1 << 12))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: RV BRANCH out of range (need ±4KiB)");
b = (u32)((u64)disp & 0x1ffeu) | ((u32)(((u64)disp >> 11) & 1u) << 11) |
((u32)(((u64)disp >> 12) & 1u) << 12);
@@ -403,9 +398,9 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 instr;
u32 b;
if (disp & 1)
- compiler_panic(c, no_loc(), "link: RV JAL misaligned displacement");
+ compiler_panic(c, SRCLOC_NONE, "link: RV JAL misaligned displacement");
if (disp < -(i64)(1 << 20) || disp >= (i64)(1 << 20))
- compiler_panic(c, no_loc(), "link: RV JAL out of range (need ±1MiB)");
+ compiler_panic(c, SRCLOC_NONE, "link: RV JAL out of range (need ±1MiB)");
b = (u32)((u64)disp & 0x1ffffeu) | ((u32)(((u64)disp >> 11) & 1u) << 11) |
((u32)(((u64)disp >> 20) & 1u) << 20);
instr = rd_u32_le(P_bytes);
@@ -434,7 +429,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u32 auipc = rd_u32_le(P_bytes);
u32 jalr = rd_u32_le(P_bytes + 4);
if (disp < -(i64)(1ll << 31) || disp >= (i64)(1ll << 31))
- compiler_panic(c, no_loc(), "link: RV CALL out of range (need ±2GiB)");
+ compiler_panic(c, SRCLOC_NONE, "link: RV CALL out of range (need ±2GiB)");
auipc = (auipc & 0x00000fffu) | (hi20 << 12);
jalr = (jalr & 0x000fffffu) | (lo12 << 20);
wr_u32_le(P_bytes, auipc);
@@ -454,10 +449,10 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u16 instr = (u16)(P_bytes[0] | ((u16)P_bytes[1] << 8));
u32 b;
if (disp & 1)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: RV RVC_BRANCH misaligned displacement");
if (disp < -(i64)(1 << 8) || disp >= (i64)(1 << 8))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: RV RVC_BRANCH out of range (need ±256B)");
b = (u32)((u64)disp & 0x1feu);
instr = (u16)(instr & 0xe383u);
@@ -479,10 +474,10 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
u16 instr = (u16)(P_bytes[0] | ((u16)P_bytes[1] << 8));
u32 b;
if (disp & 1)
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: RV RVC_JUMP misaligned displacement");
if (disp < -(i64)(1 << 11) || disp >= (i64)(1 << 11))
- compiler_panic(c, no_loc(),
+ compiler_panic(c, SRCLOC_NONE,
"link: RV RVC_JUMP out of range (need ±2KiB)");
b = (u32)((u64)disp & 0xffeu);
instr = (u16)(instr & 0xe003u);
@@ -591,7 +586,7 @@ void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A,
return;
}
default:
- compiler_panic(c, no_loc(), "link: unsupported reloc kind %u",
+ compiler_panic(c, SRCLOC_NONE, "link: unsupported reloc kind %u",
(unsigned)k);
}
}
diff --git a/src/obj/wasm/read.c b/src/obj/wasm/read.c
@@ -21,11 +21,6 @@
#include "obj/wasm/wasm.h"
#include "wasm/wasm.h"
-static SrcLoc no_loc(void) {
- SrcLoc l = {0, 0, 0};
- return l;
-}
-
/* Minimal bounds-checked cursor over the raw module bytes. */
typedef struct WasmCur {
Compiler* c;
@@ -36,7 +31,7 @@ typedef struct WasmCur {
static u8 cur_u8(WasmCur* w) {
if (w->pos >= w->len)
- compiler_panic(w->c, no_loc(), "read_wasm: unexpected end of file");
+ compiler_panic(w->c, SRCLOC_NONE, "read_wasm: unexpected end of file");
return w->data[w->pos++];
}
@@ -45,7 +40,7 @@ static u32 cur_uleb(WasmCur* w) {
for (;;) {
u8 b = cur_u8(w);
if (nbytes++ >= 5u || (shift == 28u && (b & 0xf0u)))
- compiler_panic(w->c, no_loc(), "read_wasm: invalid uleb128");
+ compiler_panic(w->c, SRCLOC_NONE, "read_wasm: invalid uleb128");
result |= (u32)(b & 0x7fu) << shift;
if (!(b & 0x80u)) return result;
shift += 7u;
@@ -129,7 +124,7 @@ static void add_code_symbols(Compiler* c, ObjBuilder* ob, ObjSecId code_sec,
fi++;
/* Advance past the body to the next size LEB. */
if (body_size > w.len || w.pos > w.len - body_size)
- compiler_panic(c, no_loc(), "read_wasm: code body out of bounds");
+ compiler_panic(c, SRCLOC_NONE, "read_wasm: code body out of bounds");
w.pos += body_size;
}
}
@@ -145,10 +140,10 @@ ObjBuilder* read_wasm(Compiler* c, const char* name, const u8* data,
input.data = data;
input.len = len;
if (!wasm_is_binary(&input))
- compiler_panic(c, no_loc(), "read_wasm: not a wasm binary");
+ compiler_panic(c, SRCLOC_NONE, "read_wasm: not a wasm binary");
ob = obj_new(c);
- if (!ob) compiler_panic(c, no_loc(), "read_wasm: obj_new failed");
+ if (!ob) compiler_panic(c, SRCLOC_NONE, "read_wasm: obj_new failed");
/* Decode the module model so we can recover function names. Names are
* interned into c->global before the module is freed, so the module's own
@@ -173,7 +168,7 @@ ObjBuilder* read_wasm(Compiler* c, const char* name, const u8* data,
u16 flags;
ObjSecId sid;
if (size > w.len || w.pos > w.len - size)
- compiler_panic(c, no_loc(), "read_wasm: section out of bounds");
+ compiler_panic(c, SRCLOC_NONE, "read_wasm: section out of bounds");
payload_end = payload + size;
if (id == 0) {
@@ -181,7 +176,7 @@ ObjBuilder* read_wasm(Compiler* c, const char* name, const u8* data,
u32 nlen = cur_uleb(&w);
const char* nm = (const char*)(w.data + w.pos);
if (nlen > w.len || w.pos > w.len - nlen)
- compiler_panic(c, no_loc(), "read_wasm: custom name out of bounds");
+ compiler_panic(c, SRCLOC_NONE, "read_wasm: custom name out of bounds");
sname = pool_intern_slice(c->global, (Slice){.s = nm, .len = nlen});
kind = SEC_OTHER;
sem = SSEM_WASM_CUSTOM;
@@ -203,7 +198,7 @@ ObjBuilder* read_wasm(Compiler* c, const char* name, const u8* data,
sid = obj_section_ex(ob, sname, kind, sem, flags, 1, 0, OBJ_SEC_NONE, 0);
if (sid == OBJ_SEC_NONE)
- compiler_panic(c, no_loc(), "read_wasm: obj_section_ex failed");
+ compiler_panic(c, SRCLOC_NONE, "read_wasm: obj_section_ex failed");
if (size) obj_write(ob, sid, data + payload, size);
if (id == 10) add_code_symbols(c, ob, sid, &mod, data + payload, size);