Bug 19421 - [2.26 Regression] Missing weak symbols in kernel modules on powerpc64le-linux-gnu
Summary: [2.26 Regression] Missing weak symbols in kernel modules on powerpc64le-linux...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-30 18:23 UTC by Timothy Pearson
Modified: 2016-01-14 12:24 UTC (History)
5 users (show)

See Also:
Host:
Target: powerpc64le-linux-gnu
Build:
Last reconfirmed:


Attachments
kernel fix (304 bytes, patch)
2016-01-13 00:23 UTC, Alan Modra
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Pearson 2015-12-30 18:23:39 UTC
Quite a few symbols in kernel modules on ppc64el are dropped after upgrading to binutils 2.25.  This in turn completely breaks module loading on ppc64el systems, per this Debian bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808246

Analysis with symbol dumps here:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808246#47
Comment 1 Matthias Klose 2016-01-05 16:38:37 UTC
> after upgrading to binutils 2.25.

this should be 2.25.90 ...
Comment 2 Nick Clifton 2016-01-08 09:25:42 UTC
Hi Alan,

   Have you seen this bug report:

> https://sourceware.org/bugzilla/show_bug.cgi?id=19421

>             Summary: Missing weak symbols in kernel modules on ppc64el

> Quite a few symbols in kernel modules on ppc64el are dropped after upgrading to
> binutils 2.25.  This in turn completely breaks module loading on ppc64el
> systems, per this Debian bug report:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808246

It seems that the cause of this was the patch for PR 4317:

   https://sourceware.org/bugzilla/show_bug.cgi?id=4317

Perhaps we need to allow some targets to require that undefined locals 
are preserved ?

Cheers
   Nick
Comment 3 Alan Modra 2016-01-12 04:15:32 UTC
So far, I haven't been able to reproduce this problem using torvalds linux git kernel and current binutils.

There are lots of claims in the debian bug report:

1)
fat: no symbol version for TOC.
fat: Unknown symbol TOC. (err -22)
ext4: no symbol version for TOC.
ext4: Unknown symbol TOC. (err -22)
and others like this.

This can happen if there is no entry for "TOC." in the __versions section of a module, but I see for example
objdump -sj__versions fs/binfmt_misc.ko
...
 0e00 00000000 00000000 2e544f43 2e000000  .........TOC....
 0e10 00000000 00000000 00000000 00000000  ................
 0e20 00000000 00000000 00000000 00000000  ................
 0e30 00000000 00000000 00000000 00000000  ................
...
I picked on binfmt_misc.ko rather than the fat or ext4 modules since binfmt_misc.ko is built for "make defconfig", but I see the same with ext4.ko after flipping the appropriate .config lines.

2)
Changed section ordering for -z relro.  This shouldn't be a problem, but may be one of the triggers for (4) below.

3)
Normally a ppc64el kernel has the following undefined symbols:
| 44809: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND mach_powermac
| 52870: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND mach_chrp
| 62021: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND mach_cell
| 62383: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __crc_TOC.

Also not a problem if these symbols disappear when undefined, I think.  The mach_* symbols are used in the following macro
#define machine_is(name) \
        ({ \
                extern struct machdep_calls mach_##name \
                        __attribute__((weak));           \
                machine_id == &mach_##name; \
        })
A missing kernel symbol will be silently resolved to 0 if the reference is STB_WEAK as far as I can see from my reading kernel/module.c.  This of course is the same value if the symbol is found.  __crc_TOC. is similar (but I'm still investigating this one).

4)
the mcount symbol error

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68759
If you're building with gcc-6, you will need a kernel patch.
Comment 4 Alan Modra 2016-01-12 12:12:01 UTC
I've reproduced lack of "TOC." in __versions.  (Lots of WARNING: ".TOC."  [*.ko] has no CRC! too.)

"make defconfig" followed by turning off CONFIG_CRASH_DUMP and CONFIG_RELOCATABLE in .config does the trick, at least with current gcc-6 and binutils.  I'll look into why tomorrow if someone else doesn't beat me to it.
Comment 5 Alan Modra 2016-01-13 00:23:26 UTC
Created attachment 8897 [details]
kernel fix

So the reason that CONFIG_RELOCATABLE (which is forced on by CONFIG_CRASH_DUMP) avoids the problem is that with relocatable output there is a relocation on "__crc_TOC." which results in the symbol being kept with newer binutils.  genksyms ought to be providing a value for "__crc_TOC." but it doesn't, which I think makes this a kernel bug.  Attached patch cures the problem.
Comment 6 cvs-commit@gcc.gnu.org 2016-01-14 10:14:27 UTC
The binutils-2_26-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a82e3ef7ad90d9335c8f3801f06916ffed43327b

commit a82e3ef7ad90d9335c8f3801f06916ffed43327b
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jan 14 19:02:18 2016 +1030

    Revert "Strip undefined symbols from .symtab"
    
    This reverts commit d983c8c5503d680c6d4955ceb610a9beebc64460 and
    db95bb7c5946a109e1584ab2c43c052ff39e63bd
    
    The PR4317 patch introduced a ppc64le linux kernel build problem.
    
    	PR ld/19421
    	PR ld/4317
    bfd/
    	* elflink.c (elf_link_input_bfd): Revert 2015-02-19 changes.
    	(elf_link_output_extsym): Likewise.
    ld/
    	* ld-aarch64/gc-tls-relocs.d: Revert 2015-02-19 changes.
    	* ld-cris/locref2.d: Likewise.
    	* ld-elf/ehdr_start-weak.d: Likewise.
    	* ld-elf/group1.d: Likewise.
    	* ld-i386/compressed1.d: Likewise.
    	* ld-ia64/error1.d: Likewise.
    	* ld-ia64/error2.d: Likewise.
    	* ld-ia64/error3.d: Likewise.
    	* ld-mips-elf/pic-and-nonpic-1.nd: Likewise.
    	* ld-mmix/undef-3.d: Likewise.
    	* ld-powerpc/tlsexe.r: Likewise.
    	* ld-powerpc/tlsexetoc.r: Likewise.
    	* ld-powerpc/tlsso.r: Likewise.
    	* ld-powerpc/tlstocso.r: Likewise.
    	* ld-x86-64/compressed1.d: Likewise.
    	* ld-x86-64/pie1.d: Likewise.
Comment 7 Alan Modra 2016-01-14 10:36:33 UTC
Fixed for 2.26 by reverting the pr4317 patch.  Expect kernel patches too.