Module Name: src Committed By: skrll Date: Tue Jun 21 06:52:17 UTC 2022
Modified Files: src/lib/csu/common: crt0-common.c src/libexec/ld.elf_so: rtld.h src/libexec/ld.elf_so/arch/aarch64: mdreloc.c src/tests/lib/csu: h_ifunc_static.c t_ifunc_static.sh src/tests/libexec/ld.elf_so: t_ifunc.c Log Message: Support ifunc on aarch64. The tests pass at least. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/csu/common/crt0-common.c cvs rdiff -u -r1.143 -r1.144 src/libexec/ld.elf_so/rtld.h cvs rdiff -u -r1.15 -r1.16 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c cvs rdiff -u -r1.6 -r1.7 src/tests/lib/csu/h_ifunc_static.c cvs rdiff -u -r1.2 -r1.3 src/tests/lib/csu/t_ifunc_static.sh cvs rdiff -u -r1.11 -r1.12 src/tests/libexec/ld.elf_so/t_ifunc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/csu/common/crt0-common.c diff -u src/lib/csu/common/crt0-common.c:1.26 src/lib/csu/common/crt0-common.c:1.27 --- src/lib/csu/common/crt0-common.c:1.26 Tue Jun 21 06:47:37 2022 +++ src/lib/csu/common/crt0-common.c Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: crt0-common.c,v 1.26 2022/06/21 06:47:37 skrll Exp $ */ +/* $NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: crt0-common.c,v 1.26 2022/06/21 06:47:37 skrll Exp $"); +__RCSID("$NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $"); #include <sys/types.h> #include <sys/exec.h> @@ -127,6 +127,7 @@ _finiarray(void) } #if \ + defined(__aarch64__) || \ defined(__powerpc__) || \ defined(__sparc__) || \ defined(__x86_64__) Index: src/libexec/ld.elf_so/rtld.h diff -u src/libexec/ld.elf_so/rtld.h:1.143 src/libexec/ld.elf_so/rtld.h:1.144 --- src/libexec/ld.elf_so/rtld.h:1.143 Tue Jun 21 06:47:37 2022 +++ src/libexec/ld.elf_so/rtld.h Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.h,v 1.143 2022/06/21 06:47:37 skrll Exp $ */ +/* $NetBSD: rtld.h,v 1.144 2022/06/21 06:52:17 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -303,6 +303,7 @@ typedef struct Struct_Obj_Entry { /* IRELATIVE relocations */ size_t ifunc_remaining; #if \ + defined(__aarch64__) || \ defined(__arm__) || \ defined(__i386__) || \ defined(__powerpc__) || \ Index: src/libexec/ld.elf_so/arch/aarch64/mdreloc.c diff -u src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.15 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.16 --- src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.15 Tue May 31 08:43:14 2022 +++ src/libexec/ld.elf_so/arch/aarch64/mdreloc.c Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: mdreloc.c,v 1.15 2022/05/31 08:43:14 andvar Exp $ */ +/* $NetBSD: mdreloc.c,v 1.16 2022/06/21 06:52:17 skrll Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.15 2022/05/31 08:43:14 andvar Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.16 2022/06/21 06:52:17 skrll Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -248,6 +248,14 @@ _rtld_relocate_nonplt_objects(Obj_Entry obj->path, (void *)tmp, where, defobj->path)); break; + case R_TYPE(IRELATIVE): + /* IFUNC relocations are handled in _rtld_call_ifunc */ + if (obj->ifunc_remaining_nonplt == 0) + obj->ifunc_remaining_nonplt = obj->relalim - rela; + rdbg(("IRELATIVE in %s, %zx", obj->path, + obj->ifunc_remaining_nonplt)); + /* FALLTHROUGH */ + case R_TYPE(RELATIVE): /* word B + A */ *where = (Elf_Addr)(obj->relocbase + rela->r_addend); rdbg(("RELATIVE in %s --> %p", obj->path, @@ -330,8 +338,9 @@ _rtld_relocate_plt_lazy(Obj_Entry *obj) for (const Elf_Rela *rela = obj->pltrela; rela < obj->pltrelalim; rela++) { Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset); - assert((ELF_R_TYPE(rela->r_info) == R_TYPE(JUMP_SLOT)) || - (ELF_R_TYPE(rela->r_info) == R_TYPE(TLSDESC))); + assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JUMP_SLOT) || + ELF_R_TYPE(rela->r_info) == R_TYPE(TLSDESC) || + ELF_R_TYPE(rela->r_info) == R_TYPE(IRELATIVE)); switch (ELF_R_TYPE(rela->r_info)) { case R_TYPE(JUMP_SLOT): @@ -342,6 +351,9 @@ _rtld_relocate_plt_lazy(Obj_Entry *obj) case R_TYPE(TLSDESC): _rtld_tlsdesc_fill(obj, rela, where, SYMLOOK_IN_PLT); break; + case R_TYPE(IRELATIVE): + obj->ifunc_remaining = obj->pltrelalim - rela; + break; } } Index: src/tests/lib/csu/h_ifunc_static.c diff -u src/tests/lib/csu/h_ifunc_static.c:1.6 src/tests/lib/csu/h_ifunc_static.c:1.7 --- src/tests/lib/csu/h_ifunc_static.c:1.6 Tue Jun 21 06:47:38 2022 +++ src/tests/lib/csu/h_ifunc_static.c Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: h_ifunc_static.c,v 1.6 2022/06/21 06:47:38 skrll Exp $ */ +/* $NetBSD: h_ifunc_static.c,v 1.7 2022/06/21 06:52:17 skrll Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,6 +30,7 @@ */ #if \ + defined(__aarch64__) || \ defined(__arm__) || \ defined(__i386__) || \ defined(__powerpc__) || \ Index: src/tests/lib/csu/t_ifunc_static.sh diff -u src/tests/lib/csu/t_ifunc_static.sh:1.2 src/tests/lib/csu/t_ifunc_static.sh:1.3 --- src/tests/lib/csu/t_ifunc_static.sh:1.2 Wed Jan 30 12:42:53 2019 +++ src/tests/lib/csu/t_ifunc_static.sh Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -# $NetBSD: t_ifunc_static.sh,v 1.2 2019/01/30 12:42:53 martin Exp $ +# $NetBSD: t_ifunc_static.sh,v 1.3 2022/06/21 06:52:17 skrll Exp $ # # Copyright (c) 2018 The NetBSD Foundation, Inc. # All rights reserved. @@ -33,10 +33,10 @@ ifunc_static_head() ifunc_static_body() { case `uname -p` in - i386|x86_64|powerpc|*sparc*|*arm*) + i386|x86_64|powerpc|*sparc*|*arm*|*aarch64*) ;; *) - atf_skip "ifunc is supposed only on ARM, i386, PowerPC, SPARC and x86-64" + atf_skip "ifunc is supposed only on AARCH64, ARM, i386, PowerPC, SPARC and x86-64" ;; esac Index: src/tests/libexec/ld.elf_so/t_ifunc.c diff -u src/tests/libexec/ld.elf_so/t_ifunc.c:1.11 src/tests/libexec/ld.elf_so/t_ifunc.c:1.12 --- src/tests/libexec/ld.elf_so/t_ifunc.c:1.11 Tue Jun 21 06:47:38 2022 +++ src/tests/libexec/ld.elf_so/t_ifunc.c Tue Jun 21 06:52:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ifunc.c,v 1.11 2022/06/21 06:47:38 skrll Exp $ */ +/* $NetBSD: t_ifunc.c,v 1.12 2022/06/21 06:52:17 skrll Exp $ */ /* * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -36,6 +36,7 @@ #include "h_macros.h" #if \ + defined(__aarch64__) || \ defined(__arm__) || \ defined(__i386__) || \ defined(__sparc__) || \