git: 1cd90a2c16dd - main - rtld: Move powerpc specific code to powerpc files

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Fri, 17 May 2024 10:21:53 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=1cd90a2c16dd2e22dd6f6c8e1ebd3eff0fe4993a

commit 1cd90a2c16dd2e22dd6f6c8e1ebd3eff0fe4993a
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-05-13 18:13:07 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-05-17 09:37:23 +0000

    rtld: Move powerpc specific code to powerpc files
    
    There are two variables set by dynamic tags in the powerpc runtime
    linker. Now we have a way to split out architecture-specific dynamic
    tags use it to handle these.
    
    Reviewed by:    kib, jhibbits
    Obtained from:  jhibbits (earlier version)
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D45182
---
 libexec/rtld-elf/powerpc/reloc.c          | 11 +++++++++++
 libexec/rtld-elf/powerpc/rtld_machdep.h   |  6 +++---
 libexec/rtld-elf/powerpc64/reloc.c        | 11 +++++++++++
 libexec/rtld-elf/powerpc64/rtld_machdep.h |  6 +++---
 libexec/rtld-elf/rtld.c                   | 12 ------------
 libexec/rtld-elf/rtld.h                   |  7 -------
 6 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index 73a1c89991e2..5618efb7f716 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -57,6 +57,17 @@
 
 void _rtld_bind_secureplt_start(void);
 
+bool
+arch_digest_dynamic(struct Struct_Obj_Entry *obj, const Elf_Dyn *dynp)
+{
+	if (dynp->d_tag == DT_PPC_GOT) {
+		obj->gotptr = (Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr);
+		return (true);
+	}
+
+	return (false);
+}
+
 /*
  * Process the R_PPC_COPY relocations
  */
diff --git a/libexec/rtld-elf/powerpc/rtld_machdep.h b/libexec/rtld-elf/powerpc/rtld_machdep.h
index 69fc52369201..ec470f238991 100644
--- a/libexec/rtld-elf/powerpc/rtld_machdep.h
+++ b/libexec/rtld-elf/powerpc/rtld_machdep.h
@@ -35,13 +35,13 @@
 
 struct Struct_Obj_Entry;
 
-#define	MD_OBJ_ENTRY
+#define	MD_OBJ_ENTRY	\
+    Elf_Addr *gotptr;		/* GOT pointer (secure-plt only) */
 
 /* Return the address of the .dynamic section in the dynamic linker. */
 #define rtld_dynamic(obj)    (&_DYNAMIC)
 
-/* No arch-specific dynamic tags */
-#define	arch_digest_dynamic(obj, dynp)	false
+bool arch_digest_dynamic(struct Struct_Obj_Entry *, const Elf_Dyn *);
 
 /* No architecture specific notes */
 #define	arch_digest_note(obj, note)	false
diff --git a/libexec/rtld-elf/powerpc64/reloc.c b/libexec/rtld-elf/powerpc64/reloc.c
index 70928829aeda..2d06d5821d1b 100644
--- a/libexec/rtld-elf/powerpc64/reloc.c
+++ b/libexec/rtld-elf/powerpc64/reloc.c
@@ -52,6 +52,17 @@ struct funcdesc {
 };
 #endif
 
+bool
+arch_digest_dynamic(struct Struct_Obj_Entry *obj, const Elf_Dyn *dynp)
+{
+	if (dynp->d_tag == DT_PPC64_GLINK) {
+		obj->glink = (Elf_Addr)(obj->relocbase + dynp->d_un.d_ptr);
+		return (true);
+	}
+
+	return (false);
+}
+
 /*
  * Process the R_PPC_COPY relocations
  */
diff --git a/libexec/rtld-elf/powerpc64/rtld_machdep.h b/libexec/rtld-elf/powerpc64/rtld_machdep.h
index d1dab63d3779..d628e776bae9 100644
--- a/libexec/rtld-elf/powerpc64/rtld_machdep.h
+++ b/libexec/rtld-elf/powerpc64/rtld_machdep.h
@@ -35,13 +35,13 @@
 
 struct Struct_Obj_Entry;
 
-#define	MD_OBJ_ENTRY
+#define	MD_OBJ_ENTRY	\
+    Elf_Addr glink;		/* GLINK PLT call stub section */
 
 /* Return the address of the .dynamic section in the dynamic linker. */
 #define rtld_dynamic(obj)    (&_DYNAMIC)
 
-/* No arch-specific dynamic tags */
-#define	arch_digest_dynamic(obj, dynp)	false
+bool arch_digest_dynamic(struct Struct_Obj_Entry *, const Elf_Dyn *);
 
 /* No architecture specific notes */
 #define	arch_digest_note(obj, note)	false
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 20c340ed15a3..ef34a9d36bc3 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1520,18 +1520,6 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath,
 		    obj->static_tls = true;
 	    break;
 
-#ifdef __powerpc__
-#ifdef __powerpc64__
-	case DT_PPC64_GLINK:
-		obj->glink = (Elf_Addr)(obj->relocbase + dynp->d_un.d_ptr);
-		break;
-#else
-	case DT_PPC_GOT:
-		obj->gotptr = (Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr);
-		break;
-#endif
-#endif
-
 	case DT_FLAGS_1:
 		if (dynp->d_un.d_val & DF_1_NOOPEN)
 		    obj->z_noopen = true;
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index a4f2c35cc03f..9df5b4ec8f59 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -183,13 +183,6 @@ typedef struct Struct_Obj_Entry {
     const Elf_Sym *symtab;	/* Symbol table */
     const char *strtab;		/* String table */
     unsigned long strsize;	/* Size in bytes of string table */
-#ifdef __powerpc__
-#ifdef __powerpc64__
-    Elf_Addr glink;		/* GLINK PLT call stub section */
-#else
-    Elf_Addr *gotptr;		/* GOT pointer (secure-plt only) */
-#endif
-#endif
 
     const Elf_Verneed *verneed; /* Required versions. */
     Elf_Word verneednum;	/* Number of entries in verneed table */