From 707624e99281241dfc2250c5a2ae4f025d19be5c Mon Sep 17 00:00:00 2001 From: lemon Date: Wed, 10 Dec 2025 21:17:02 +0100 Subject: c: fix static relocation for &sym[offset] --- c/c.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'c') diff --git a/c/c.c b/c/c.c index c206ec8..ea24b1a 100644 --- a/c/c.c +++ b/c/c.c @@ -1270,14 +1270,13 @@ expr2reloc(union ref *psym, vlong *paddend, const struct expr *ex) } else if (globsym(psym, ex) && in_range(ex->ty.t, TYARRAY, TYFUNC)) { *paddend = 0; } else if (ex->t == ESUB && globsym(psym, &ex->sub[0]) && isint(ex->sub[1].ty) && ex->sub[1].t == ENUMLIT) { - *paddend = ex->sub[1].i * typesize(ex->sub[0].ty); + *paddend = -ex->sub[1].i * typesize(typechild(ex->sub[0].ty)); } else if (ex->t == EADD) { - for (int swp = 0; swp < 2; ++swp) { - struct expr *a = &ex->sub[swp], *b = &ex->sub[swp ^ 1]; - if (globsym(psym, a) && isint(b->ty) && b->t == ENUMLIT) { - *paddend = b->i * typesize(a->ty); - return; - } + 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) { + *paddend = b->i * typesize(typechild(a->ty)); + return; } goto Fail; } else Fail: fatal(&ex->span, "internal bug: non static reloc?"); -- cgit v1.2.3