aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-05 19:22:08 +0100
committerlemon <lsof@mailbox.org>2026-03-05 19:22:08 +0100
commit25a143d75df857c6b76c67a71a3683d0191c711b (patch)
tree99b13013cb9c7f1988cd0aab58c0eebf87e078a0
parent4362ce9e9d7defddb2d7965ef1cbf481599f5c81 (diff)
c: recognize another static initializer edge case
I think globsym & expr2reloc should be rewritten to be more robust to this kind of thing. Accumulate offsets whilst recursing into the child node that might contain a direct global symbol reference kind of thing.
-rw-r--r--c/c.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/c/c.c b/c/c.c
index cd21e02..87087e7 100644
--- a/c/c.c
+++ b/c/c.c
@@ -1410,7 +1410,6 @@ globsym(union ref *psym, const struct expr *ex)
return 1;
}
return 0;
-
}
static vlong /* -> returns addend */
@@ -1432,8 +1431,8 @@ expr2reloc(union ref *psym, const struct expr *ex)
} else if (ex->t == EADD) {
int swp = ex->sub[0].t == ENUMLIT;
struct expr *a = &ex->sub[swp], *b = &ex->sub[swp ^ 1];
- if (globsym(psym, a) && isint(b->ty) && b->t == ENUMLIT) {
- return b->i * typesize(typechild(a->ty));
+ if (isint(b->ty) && b->t == ENUMLIT) {
+ return expr2reloc(psym, a) + b->i * typesize(typechild(a->ty));
}
}
fatal(&ex->span, "internal bug: non static reloc?");