From 25a143d75df857c6b76c67a71a3683d0191c711b Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 5 Mar 2026 19:22:08 +0100 Subject: 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. --- c/c.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'c/c.c') 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?"); -- cgit v1.2.3