From d8b4e87af669c2b260686a5db67f7f02b4c164d9 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 14 Dec 2025 12:15:59 +0100 Subject: various relocation related optimization With 59ca5a8db, querying if a symbol is defined is cheap. If we're compiling code that calls foo() and we defined foo() in this compilation unit, we already know its offset within the .text section, so use it instead of emitting a relocation for the linker to handle. Also, put small literal data in the .text section instead of .rodata. This seems to improve performance (cache locality?), and as a bonus, it will be good for aarch64's instr encoding with smallish PC-relative offsets. --- c/c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'c/c.c') diff --git a/c/c.c b/c/c.c index 5ff2041..4c4868b 100644 --- a/c/c.c +++ b/c/c.c @@ -4308,8 +4308,8 @@ function(struct comp *cm, struct function *fn, const char **pnames, const struct if (!ifunc) ifunc = intern("__func__"); union type ty = mkarrtype(mktype(TYCHAR), QCONST, strlen(fn->name) + 1); const char *sym = mkhiddensym(fn->name, ifunc, 1); - uint off = objnewdat(sym, Srodata, 0, typesize(ty), typealign(ty)); - uchar *p = objout.rodata.p + off; + uint off = objnewdat(sym, Stext, 0, typesize(ty), typealign(ty)); + uchar *p = objout.textbegin + off; memcpy(p, fn->name, typearrlen(ty)-1); putdecl(cm, &(struct decl) { .ty = ty, .qual = QCONST, @@ -4418,7 +4418,7 @@ docomp(struct comp *cm) pdecl(&st, cm); } else if (decl.ty.t != TYFUNC && decl.scls != SCTYPEDEF && (decl.scls != SCEXTERN || noscls)) { /* tentative definitions */ - if (!objhassym(decl.sym)) { + if (!objhassym(decl.sym, NULL)) { uint size = typesize(d->ty); if (isincomplete(d->ty)) { if (d->ty.t == TYARRAY) { -- cgit v1.2.3