Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261102165837.24591-9-kaloz@kernel.org>
Date: Mon,  2 Nov 2026 17:58:35 +0100
From: Imre Kaloz <kaloz@...nel.org>
To: musl@...ts.openwall.com
Subject: [PATCH 08/10] add ARCH_PLT_WRITE hook for archs whose PLT entries hold code

sparc64's PLT entries are instructions, so the dynamic linker resolves a
JMP_SLOT relocation by writing code, through the new arch_plt_write
hook. The hook also gets the addend and the object's base: on sparc64
the entries from the 32768th on are reached through a data word, which
their JMP_SLOT marks with a nonzero addend. With ARCH_LOCAL_SYM_IS_BASE
defined, a local symbol resolves to the load base, since the sparc
relocations binutils' bfd/elfxx-sparc.c emits against section symbols
carry the full address in the addend.
---
 ldso/dynlink.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 10471b23..0c717aa4 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -456,6 +456,10 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 
 		sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0;
 		tls_val = def.sym ? def.sym->st_value : 0;
+#ifdef ARCH_LOCAL_SYM_IS_BASE
+		if (def.sym && (def.sym->st_info>>4) == STB_LOCAL)
+			sym_val = (size_t)def.dso->base;
+#endif
 
 		if ((type == REL_TPOFF || type == REL_TPOFF_NEG)
 		    && def.dso->tls_id > static_tls_cnt) {
@@ -470,9 +474,16 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 			addend -= (size_t)reloc_addr;
 		case REL_SYMBOLIC:
 		case REL_GOT:
+#ifndef ARCH_PLT_WRITE
 		case REL_PLT:
+#endif
 			*reloc_addr = sym_val + addend;
 			break;
+#ifdef ARCH_PLT_WRITE
+		case REL_PLT:
+			arch_plt_write(reloc_addr, sym_val + addend, addend, base);
+			break;
+#endif
 		case REL_USYMBOLIC:
 			memcpy(reloc_addr, &(size_t){sym_val + addend}, sizeof(size_t));
 			break;
-- 
2.47.3

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.