aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-10 21:17:02 +0100
committerlemon <lsof@mailbox.org>2025-12-10 21:17:02 +0100
commit707624e99281241dfc2250c5a2ae4f025d19be5c (patch)
tree5b315a8ec5353bc670518899059279d1691830aa /c
parent97882e8d32fd99e1edaf5361bfd3b6852dbb1a3d (diff)
c: fix static relocation for &sym[offset]
Diffstat (limited to 'c')
-rw-r--r--c/c.c13
1 files changed, 6 insertions, 7 deletions
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?");