From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0123.outbound.protection.outlook.com ([104.47.33.123]:63726 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032353AbeCAPdQ (ORCPT ); Thu, 1 Mar 2018 10:33:16 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Alan Modra , Michael Ellerman , Sasha Levin Subject: [added to the 4.1 stable tree] powerpc: Simplify module TOC handling Date: Thu, 1 Mar 2018 15:25:43 +0000 Message-ID: <20180301152116.1486-295-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Alan Modra This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 ] PowerPC64 uses the symbol .TOC. much as other targets use _GLOBAL_OFFSET_TABLE_. It identifies the value of the GOT pointer (or in powerpc parlance, the TOC pointer). Global offset tables are generally local to an executable or shared library, or in the kernel, module. Thus it does not make sense for a module to resolve a relocation against .TOC. to the kernel's .TOC. value. A module has its own .TOC., and indeed the powerpc64 module relocation processing ignores the kernel value of .TOC. and instead calculates a module-local value. This patch removes code involved in exporting the kernel .TOC., tweaks modpost to ignore an undefined .TOC., and the module loader to twiddle the section symbol so that .TOC. isn't seen as undefined. Note that if the kernel was compiled with -msingle-pic-base then ELFv2 would not have function global entry code setting up r2. In that case the module call stubs would need to be modified to set up r2 using the kernel .TOC. value, requiring some of this code to be reinstated. mpe: Furthermore a change in binutils master (not yet released) causes the current way we handle the TOC to no longer work when building with MODVERSIONS=3Dy and RELOCATABLE=3Dn. The symptom is that modules can not be loaded due to there being no version found for TOC. Cc: stable@vger.kernel.org # 3.16+ Signed-off-by: Alan Modra Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/kernel/misc_64.S | 28 ---------------------------- arch/powerpc/kernel/module_64.c | 12 +++++++++--- scripts/mod/modpost.c | 3 ++- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S index 25a6f6ae729f..1f979d5617a2 100644 --- a/arch/powerpc/kernel/misc_64.S +++ b/arch/powerpc/kernel/misc_64.S @@ -634,31 +634,3 @@ _GLOBAL(kexec_sequence) li r5,0 blr /* image->start(physid, image->start, 0); */ #endif /* CONFIG_KEXEC */ - -#ifdef CONFIG_MODULES -#if defined(_CALL_ELF) && _CALL_ELF =3D=3D 2 - -#ifdef CONFIG_MODVERSIONS -.weak __crc_TOC. -.section "___kcrctab+TOC.","a" -.globl __kcrctab_TOC. -__kcrctab_TOC.: - .llong __crc_TOC. -#endif - -/* - * Export a fake .TOC. since both modpost and depmod will complain otherwi= se. - * Both modpost and depmod strip the leading . so we do the same here. - */ -.section "__ksymtab_strings","a" -__kstrtab_TOC.: - .asciz "TOC." - -.section "___ksymtab+TOC.","a" -/* This symbol name is important: it's used by modpost to find exported sy= ms */ -.globl __ksymtab_TOC. -__ksymtab_TOC.: - .llong 0 /* .value */ - .llong __kstrtab_TOC. -#endif /* ELFv2 */ -#endif /* MODULES */ diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_6= 4.c index e4f7d4eed20c..08b7a40de5f8 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -326,7 +326,10 @@ static void dedotify_versions(struct modversion_info *= vers, } } =20 -/* Undefined symbols which refer to .funcname, hack to funcname (or .TOC.)= */ +/* + * Undefined symbols which refer to .funcname, hack to funcname. Make .TOC= . + * seem to be defined (value set later). + */ static void dedotify(Elf64_Sym *syms, unsigned int numsyms, char *strtab) { unsigned int i; @@ -334,8 +337,11 @@ static void dedotify(Elf64_Sym *syms, unsigned int num= syms, char *strtab) for (i =3D 1; i < numsyms; i++) { if (syms[i].st_shndx =3D=3D SHN_UNDEF) { char *name =3D strtab + syms[i].st_name; - if (name[0] =3D=3D '.') + if (name[0] =3D=3D '.') { + if (strcmp(name+1, "TOC.") =3D=3D 0) + syms[i].st_shndx =3D SHN_ABS; syms[i].st_name++; + } } } } @@ -351,7 +357,7 @@ static Elf64_Sym *find_dot_toc(Elf64_Shdr *sechdrs, numsyms =3D sechdrs[symindex].sh_size / sizeof(Elf64_Sym); =20 for (i =3D 1; i < numsyms; i++) { - if (syms[i].st_shndx =3D=3D SHN_UNDEF + if (syms[i].st_shndx =3D=3D SHN_ABS && strcmp(strtab + syms[i].st_name, "TOC.") =3D=3D 0) return &syms[i]; } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 91ee1b2e0f9a..a9f02fe15ce3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -593,7 +593,8 @@ static int ignore_undef_symbol(struct elf_info *info, c= onst char *symname) if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) =3D=3D 0 || strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) =3D=3D 0 || strncmp(symname, "_restvr_", sizeof("_restvr_") - 1) =3D=3D 0 || - strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) =3D=3D 0) + strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) =3D=3D 0 || + strcmp(symname, ".TOC.") =3D=3D 0) return 1; /* Do not ignore this symbol */ return 0; --=20 2.14.1