stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
@ 2016-02-24  3:24 gregkh
  2016-02-24  4:51 ` Michael Ellerman
  0 siblings, 1 reply; 10+ messages in thread
From: gregkh @ 2016-02-24  3:24 UTC (permalink / raw)
  To: amodra, gregkh, mpe; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    powerpc: Simplify module TOC handling

to the 4.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     powerpc-simplify-module-toc-handling.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 15 Jan 2016 20:52:22 +1100
Subject: powerpc: Simplify module TOC handling

From: Alan Modra <amodra@gmail.com>

commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.

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=y and RELOCATABLE=n. The symptom is that modules can not be
loaded due to there being no version found for TOC.

Signed-off-by: Alan Modra <amodra@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 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(-)

--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -701,31 +701,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 == 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 otherwise.
- * 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 syms */
-.globl __ksymtab_TOC.
-__ksymtab_TOC.:
-	.llong 0 /* .value */
-	.llong __kstrtab_TOC.
-#endif /* ELFv2 */
-#endif /* MODULES */
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -326,7 +326,10 @@ static void dedotify_versions(struct mod
 		}
 }
 
-/* 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, un
 	for (i = 1; i < numsyms; i++) {
 		if (syms[i].st_shndx == SHN_UNDEF) {
 			char *name = strtab + syms[i].st_name;
-			if (name[0] == '.')
+			if (name[0] == '.') {
+				if (strcmp(name+1, "TOC.") == 0)
+					syms[i].st_shndx = SHN_ABS;
 				memmove(name, name+1, strlen(name));
+			}
 		}
 	}
 }
@@ -351,7 +357,7 @@ static Elf64_Sym *find_dot_toc(Elf64_Shd
 	numsyms = sechdrs[symindex].sh_size / sizeof(Elf64_Sym);
 
 	for (i = 1; i < numsyms; i++) {
-		if (syms[i].st_shndx == SHN_UNDEF
+		if (syms[i].st_shndx == SHN_ABS
 		    && strcmp(strtab + syms[i].st_name, "TOC.") == 0)
 			return &syms[i];
 	}
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -594,7 +594,8 @@ static int ignore_undef_symbol(struct el
 		if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 ||
 		    strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0 ||
 		    strncmp(symname, "_restvr_", sizeof("_restvr_") - 1) == 0 ||
-		    strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0)
+		    strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0 ||
+		    strcmp(symname, ".TOC.") == 0)
 			return 1;
 	/* Do not ignore this symbol */
 	return 0;


Patches currently in stable-queue which might be from amodra@gmail.com are

queue-4.4/powerpc-simplify-module-toc-handling.patch

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-02-24  3:24 gregkh
@ 2016-02-24  4:51 ` Michael Ellerman
  2016-02-24  5:02   ` Greg KH
  2016-03-08 20:53   ` Ben Hutchings
  0 siblings, 2 replies; 10+ messages in thread
From: Michael Ellerman @ 2016-02-24  4:51 UTC (permalink / raw)
  To: gregkh, amodra; +Cc: stable, stable-commits

On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
>
> This is a note to let you know that I've just added the patch titled
>
>     powerpc: Simplify module TOC handling
>
> to the 4.4-stable tree which can be found at:
>     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
>
> The filename of the patch is:
>      powerpc-simplify-module-toc-handling.patch
> and it can be found in the queue-4.4 subdirectory.
>
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable@vger.kernel.org> know about it.
>
>
> From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> From: Alan Modra <amodra@gmail.com>
> Date: Fri, 15 Jan 2016 20:52:22 +1100
> Subject: powerpc: Simplify module TOC handling
>
> From: Alan Modra <amodra@gmail.com>
>
> commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.


Hi Greg,

Please drop this commit, it requires a corresponding change to depmod which we
need to get accepted first.

Sorry for the churn.

cheers


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-02-24  4:51 ` Michael Ellerman
@ 2016-02-24  5:02   ` Greg KH
  2016-02-24  5:55     ` Michael Ellerman
  2016-03-08 20:53   ` Ben Hutchings
  1 sibling, 1 reply; 10+ messages in thread
From: Greg KH @ 2016-02-24  5:02 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: amodra, stable, stable-commits

On Wed, Feb 24, 2016 at 03:51:25PM +1100, Michael Ellerman wrote:
> On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> >
> > This is a note to let you know that I've just added the patch titled
> >
> >     powerpc: Simplify module TOC handling
> >
> > to the 4.4-stable tree which can be found at:
> >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> >
> > The filename of the patch is:
> >      powerpc-simplify-module-toc-handling.patch
> > and it can be found in the queue-4.4 subdirectory.
> >
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@vger.kernel.org> know about it.
> >
> >
> > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > From: Alan Modra <amodra@gmail.com>
> > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > Subject: powerpc: Simplify module TOC handling
> >
> > From: Alan Modra <amodra@gmail.com>
> >
> > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> 
> 
> Hi Greg,
> 
> Please drop this commit, it requires a corresponding change to depmod which we
> need to get accepted first.

If I drop this one, then the next patch in the series, "powerpc: Fix
dedotify for binutils >= 2.26" does not apply, so I'll have to drop that
as well.  Is that acceptable?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-02-24  5:02   ` Greg KH
@ 2016-02-24  5:55     ` Michael Ellerman
  2016-02-24 22:55       ` Greg KH
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Ellerman @ 2016-02-24  5:55 UTC (permalink / raw)
  To: Greg KH; +Cc: amodra, stable, stable-commits

On Tue, 2016-02-23 at 21:02 -0800, Greg KH wrote:
> On Wed, Feb 24, 2016 at 03:51:25PM +1100, Michael Ellerman wrote:
> > On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> > >
> > > This is a note to let you know that I've just added the patch titled
> > >
> > >     powerpc: Simplify module TOC handling
> > >
> > > to the 4.4-stable tree which can be found at:
> > >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > >
> > > The filename of the patch is:
> > >      powerpc-simplify-module-toc-handling.patch
> > > and it can be found in the queue-4.4 subdirectory.
> > >
> > > If you, or anyone else, feels it should not be added to the stable tree,
> > > please let <stable@vger.kernel.org> know about it.
> > >
> > >
> > > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > > From: Alan Modra <amodra@gmail.com>
> > > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > > Subject: powerpc: Simplify module TOC handling
> > >
> > > From: Alan Modra <amodra@gmail.com>
> > >
> > > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> >
> > Hi Greg,
> >
> > Please drop this commit, it requires a corresponding change to depmod which we
> > need to get accepted first.
>
> If I drop this one, then the next patch in the series, "powerpc: Fix
> dedotify for binutils >= 2.26" does not apply, so I'll have to drop that
> as well.  Is that acceptable?

Yeah that's OK.

I'll send a backport for that one.

cheers


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-02-24  5:55     ` Michael Ellerman
@ 2016-02-24 22:55       ` Greg KH
  0 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2016-02-24 22:55 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: amodra, stable, stable-commits

On Wed, Feb 24, 2016 at 04:55:00PM +1100, Michael Ellerman wrote:
> On Tue, 2016-02-23 at 21:02 -0800, Greg KH wrote:
> > On Wed, Feb 24, 2016 at 03:51:25PM +1100, Michael Ellerman wrote:
> > > On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> > > >
> > > > This is a note to let you know that I've just added the patch titled
> > > >
> > > >     powerpc: Simplify module TOC handling
> > > >
> > > > to the 4.4-stable tree which can be found at:
> > > >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > > >
> > > > The filename of the patch is:
> > > >      powerpc-simplify-module-toc-handling.patch
> > > > and it can be found in the queue-4.4 subdirectory.
> > > >
> > > > If you, or anyone else, feels it should not be added to the stable tree,
> > > > please let <stable@vger.kernel.org> know about it.
> > > >
> > > >
> > > > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > > > From: Alan Modra <amodra@gmail.com>
> > > > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > > > Subject: powerpc: Simplify module TOC handling
> > > >
> > > > From: Alan Modra <amodra@gmail.com>
> > > >
> > > > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> > >
> > > Hi Greg,
> > >
> > > Please drop this commit, it requires a corresponding change to depmod which we
> > > need to get accepted first.
> >
> > If I drop this one, then the next patch in the series, "powerpc: Fix
> > dedotify for binutils >= 2.26" does not apply, so I'll have to drop that
> > as well.  Is that acceptable?
> 
> Yeah that's OK.
> 
> I'll send a backport for that one.

Ok, please do so, as I've now dropped both of those patches from the
tree.

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-02-24  4:51 ` Michael Ellerman
  2016-02-24  5:02   ` Greg KH
@ 2016-03-08 20:53   ` Ben Hutchings
  2016-03-08 23:47     ` Michael Ellerman
  1 sibling, 1 reply; 10+ messages in thread
From: Ben Hutchings @ 2016-03-08 20:53 UTC (permalink / raw)
  To: Michael Ellerman, gregkh, amodra; +Cc: stable, stable-commits

[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]

On Wed, 2016-02-24 at 15:51 +1100, Michael Ellerman wrote:
> On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> > 
> > 
> > This is a note to let you know that I've just added the patch titled
> > 
> >     powerpc: Simplify module TOC handling
> > 
> > to the 4.4-stable tree which can be found at:
> >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > 
> > The filename of the patch is:
> >      powerpc-simplify-module-toc-handling.patch
> > and it can be found in the queue-4.4 subdirectory.
> > 
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@vger.kernel.org> know about it.
> > 
> > 
> > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > From: Alan Modra <amodra@gmail.com>
> > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > Subject: powerpc: Simplify module TOC handling
> > 
> > From: Alan Modra <amodra@gmail.com>
> > 
> > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> 
> Hi Greg,
> 
> Please drop this commit, it requires a corresponding change to depmod which we
> need to get accepted first.
> 
> Sorry for the churn.

Is that specifically for ppc64el?  Module loading has been completely
broken in powerpc 64-bit kernels in Debian unstable since we got
binutils 2.26 and these two patches certainly fixed the big-endian case
without any need for a new kmod.

Ben.

-- 
Ben Hutchings
Sturgeon's Law: Ninety percent of everything is crap.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-03-08 20:53   ` Ben Hutchings
@ 2016-03-08 23:47     ` Michael Ellerman
  2016-03-09  0:49       ` Ben Hutchings
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Ellerman @ 2016-03-08 23:47 UTC (permalink / raw)
  To: Ben Hutchings, gregkh, amodra; +Cc: stable, stable-commits

On Tue, 2016-03-08 at 20:53 +0000, Ben Hutchings wrote:
> On Wed, 2016-02-24 at 15:51 +1100, Michael Ellerman wrote:
> > On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> > > 
> > > This is a note to let you know that I've just added the patch titled
> > > 
> > >     powerpc: Simplify module TOC handling
> > > 
> > > to the 4.4-stable tree which can be found at:
> > >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > > 
> > > The filename of the patch is:
> > >      powerpc-simplify-module-toc-handling.patch
> > > and it can be found in the queue-4.4 subdirectory.
> > > 
> > > If you, or anyone else, feels it should not be added to the stable tree,
> > > please let <stable@vger.kernel.org> know about it.
> > > 
> > > 
> > > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > > From: Alan Modra <amodra@gmail.com>
> > > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > > Subject: powerpc: Simplify module TOC handling
> > > 
> > > From: Alan Modra <amodra@gmail.com>
> > > 
> > > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> > 
> > Hi Greg,
> > 
> > Please drop this commit, it requires a corresponding change to depmod which we
> > need to get accepted first.
> > 
> > Sorry for the churn.
> 
> Is that specifically for ppc64el?  Module loading has been completely
> broken in powerpc 64-bit kernels in Debian unstable since we got
> binutils 2.26 and these two patches certainly fixed the big-endian case
> without any need for a new kmod.

Yes, it's only required on LE.

I'll have to defer to Alan on the details, but on BE we don't see those
relocations against .TOC. and so none of this matters.

cheers


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-03-08 23:47     ` Michael Ellerman
@ 2016-03-09  0:49       ` Ben Hutchings
  2016-03-09  2:07         ` Michael Ellerman
  0 siblings, 1 reply; 10+ messages in thread
From: Ben Hutchings @ 2016-03-09  0:49 UTC (permalink / raw)
  To: Michael Ellerman, gregkh, amodra; +Cc: stable, stable-commits

[-- Attachment #1: Type: text/plain, Size: 2263 bytes --]

On Wed, 2016-03-09 at 10:47 +1100, Michael Ellerman wrote:
> On Tue, 2016-03-08 at 20:53 +0000, Ben Hutchings wrote:
> > 
> > On Wed, 2016-02-24 at 15:51 +1100, Michael Ellerman wrote:
> > > 
> > > On Tue, 2016-02-23 at 19:24 -0800, gregkh@linuxfoundation.org wrote:
> > > > 
> > > > 
> > > > This is a note to let you know that I've just added the patch titled
> > > > 
> > > >     powerpc: Simplify module TOC handling
> > > > 
> > > > to the 4.4-stable tree which can be found at:
> > > >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > > > 
> > > > The filename of the patch is:
> > > >      powerpc-simplify-module-toc-handling.patch
> > > > and it can be found in the queue-4.4 subdirectory.
> > > > 
> > > > If you, or anyone else, feels it should not be added to the stable tree,
> > > > please let <stable@vger.kernel.org> know about it.
> > > > 
> > > > 
> > > > From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
> > > > From: Alan Modra <amodra@gmail.com>
> > > > Date: Fri, 15 Jan 2016 20:52:22 +1100
> > > > Subject: powerpc: Simplify module TOC handling
> > > > 
> > > > From: Alan Modra <amodra@gmail.com>
> > > > 
> > > > commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.
> > > Hi Greg,
> > > 
> > > Please drop this commit, it requires a corresponding change to depmod which we
> > > need to get accepted first.
> > > 
> > > Sorry for the churn.
> > Is that specifically for ppc64el?  Module loading has been completely
> > broken in powerpc 64-bit kernels in Debian unstable since we got
> > binutils 2.26 and these two patches certainly fixed the big-endian case
> > without any need for a new kmod.
> Yes, it's only required on LE.
> 
> I'll have to defer to Alan on the details, but on BE we don't see those
> relocations against .TOC. and so none of this matters.

The following patch "powerpc: Fix dedotify for binutils >= 2.26"
certainly is needed for BE, so someone should send Greg a version that
applies on top of 4.4 without the TOC change.  (It could even be me,
but my patch/compile/test cycle on powerpc is rather slow.)

Ben.

-- 
Ben Hutchings
When in doubt, use brute force. - Ken Thompson

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
  2016-03-09  0:49       ` Ben Hutchings
@ 2016-03-09  2:07         ` Michael Ellerman
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Ellerman @ 2016-03-09  2:07 UTC (permalink / raw)
  To: Ben Hutchings, gregkh, amodra; +Cc: stable, stable-commits

On Wed, 2016-03-09 at 00:49 +0000, Ben Hutchings wrote:
> 
> The following patch "powerpc: Fix dedotify for binutils >= 2.26"
> certainly is needed for BE, so someone should send Greg a version that
> applies on top of 4.4 without the TOC change.  (It could even be me,
> but my patch/compile/test cycle on powerpc is rather slow.)

Yep, it's on my very long TODO list.

I'll try and send it out today.

cheers


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree
@ 2018-02-04 11:08 gregkh
  0 siblings, 0 replies; 10+ messages in thread
From: gregkh @ 2018-02-04 11:08 UTC (permalink / raw)
  To: amodra, gregkh, mpe; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    powerpc: Simplify module TOC handling

to the 4.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     powerpc-simplify-module-toc-handling.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 15 Jan 2016 20:52:22 +1100
Subject: powerpc: Simplify module TOC handling

From: Alan Modra <amodra@gmail.com>

commit c153693d7eb9eeb28478aa2deaaf0b4e7b5ff5e9 upstream.

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=y and RELOCATABLE=n. The symptom is that modules can not be
loaded due to there being no version found for TOC.

Signed-off-by: Alan Modra <amodra@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 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(-)

--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -701,31 +701,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 == 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 otherwise.
- * 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 syms */
-.globl __ksymtab_TOC.
-__ksymtab_TOC.:
-	.llong 0 /* .value */
-	.llong __kstrtab_TOC.
-#endif /* ELFv2 */
-#endif /* MODULES */
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -326,7 +326,10 @@ static void dedotify_versions(struct mod
 		}
 }
 
-/* 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, un
 	for (i = 1; i < numsyms; i++) {
 		if (syms[i].st_shndx == SHN_UNDEF) {
 			char *name = strtab + syms[i].st_name;
-			if (name[0] == '.')
+			if (name[0] == '.') {
+				if (strcmp(name+1, "TOC.") == 0)
+					syms[i].st_shndx = SHN_ABS;
 				syms[i].st_name++;
+			}
 		}
 	}
 }
@@ -351,7 +357,7 @@ static Elf64_Sym *find_dot_toc(Elf64_Shd
 	numsyms = sechdrs[symindex].sh_size / sizeof(Elf64_Sym);
 
 	for (i = 1; i < numsyms; i++) {
-		if (syms[i].st_shndx == SHN_UNDEF
+		if (syms[i].st_shndx == SHN_ABS
 		    && strcmp(strtab + syms[i].st_name, "TOC.") == 0)
 			return &syms[i];
 	}
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -594,7 +594,8 @@ static int ignore_undef_symbol(struct el
 		if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 ||
 		    strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0 ||
 		    strncmp(symname, "_restvr_", sizeof("_restvr_") - 1) == 0 ||
-		    strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0)
+		    strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0 ||
+		    strcmp(symname, ".TOC.") == 0)
 			return 1;
 	/* Do not ignore this symbol */
 	return 0;


Patches currently in stable-queue which might be from amodra@gmail.com are

queue-4.4/powerpc-simplify-module-toc-handling.patch

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-02-04 11:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-04 11:08 Patch "powerpc: Simplify module TOC handling" has been added to the 4.4-stable tree gregkh
  -- strict thread matches above, loose matches on Subject: below --
2016-02-24  3:24 gregkh
2016-02-24  4:51 ` Michael Ellerman
2016-02-24  5:02   ` Greg KH
2016-02-24  5:55     ` Michael Ellerman
2016-02-24 22:55       ` Greg KH
2016-03-08 20:53   ` Ben Hutchings
2016-03-08 23:47     ` Michael Ellerman
2016-03-09  0:49       ` Ben Hutchings
2016-03-09  2:07         ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).