Bug 11143

Summary: [PATCH]unconditional linker option arch/powerpc/lib/crtsavres.o causes external module buildfailure
Product: Platform Specific/Hardware Reporter: Olaf Hering (olh)
Component: PPC-32Assignee: platform_ppc-32
Status: REOPENED ---    
Severity: high CC: agruen, ahshah, alan, arekm, christophe.leroy, dbutton, mathieu.malaterre, mchehab, mmarek, ncopa, nyushchenko, rep.dot.nop, vmiklos
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.17 Subsystem:
Regression: Yes Bisected commit-id:
Attachments: Fix linking modules against crtsavres.o
Fix linking modules against crtsavres.o

Description Olaf Hering 2008-07-22 00:28:12 UTC
Latest working kernel version:2.6.25
Earliest failing kernel version:2.6.26
Distribution:openSuSE11.1
Hardware Environment:
Software Environment:
Problem Description:
arch/powerpc/Makefile
...
     77 ifeq ($(CONFIG_PPC64),y)
...
     93 else
     94 LDFLAGS_MODULE  += arch/powerpc/lib/crtsavres.o
     95 endif
...

if external modules are build against the source tree, then linking will fail because there is no arch/powerpc/lib/crtsavres.o binary.

I see a make scripts and make prepare target, which copies /usr/src/linux/scripts sources to /usr/src/linux-obj/<arch>/<flavor>/
Maybe the ctrsavres.S has to be copied as well?

Now, if I knew how kbuild works, I could provide a patch. But I do not know, so I opened this bug in the hope that it gets fixed for 2.6.26.1

Steps to reproduce:
Comment 1 Bernhard Reutner-Fischer 2008-10-06 15:22:47 UTC
Also happens on 2.6.26.5
Comment 2 Bernhard Reutner-Fischer 2008-10-07 05:48:39 UTC
Created attachment 18191 [details]
Fix linking modules against crtsavres.o

Fix linking modules against crtsavres.o

Previously we got
  CC      drivers/char/hw_random/rng-core.mod.o
  LD [M]  drivers/char/hw_random/rng-core.ko
/there/src/buildroot.git.ppc/build_powerpc_nofpu/staging_dir/usr/bin/powerpc-linux-uclibc-ld: arch/powerpc/lib/crtsavres.o: No such file: No such file or directory

        * Makefile (LDFLAGS_MODULE_PREREQ): New variable to hold prerequisite
        files for modules.
        * arch/powerpc/Makefile: add crtsavres.o to LDFLAGS_MODULE_PREREQ.
        * scripts/Makefile.modpost (cmd_as_o_S): Copy from Makefile.build.
        (cmd_ld_ko_o): Also link LDFLAGS_MODULE_PREREQ.
        Provide rule to build objects from assembler.

Signed-off-by:  Bernhard Reutner-Fischer  <see head of patch>

Works For Me (tm). Please apply (or adjust if you dislike some aspect).
HTH && cheers,
Bernhard
Comment 3 Bernhard Reutner-Fischer 2008-10-07 06:00:17 UTC
CC'ing Sam since it touches kbuild.
Please install.
Comment 4 Olaf Hering 2008-10-13 23:44:13 UTC
This patch is incomplete, the target .o (or .c) file is not exported.
The SuSE, and likely any other kernel-source, tree need also arch/powerpc/lib/crtsavres.c exported.


...
<built-in>:0: fatal error: opening dependency file arch/powerpc/lib/.crtsavres.o.d: No such file or directory
...

Andreas, can you have a look as well,  about what we do in kernel-source for kmp packages?
Comment 5 Bernhard Reutner-Fischer 2008-10-16 09:05:09 UTC
I suspect that generally
objhdr-$(CONFIG_MODULES) += $(LDFLAGS_MODULE_PREREQ)
should be ok since these are all generated. Not sure where to stick the sources of LDFLAGS_MODULE_PREREQ for installation though.
Just a thought..
Comment 6 Arkadiusz Miskiewicz 2008-11-04 00:04:13 UTC
Broken on 2.6.27.4, too.
Comment 7 Miklos Vajna 2009-02-17 08:15:30 UTC
Still broken on 2.6.28.3.

The patch above fixes the build in case I have write access to the source tree, but this is a new requirement, in the past only read access was enough. (For example when building as a user and the source tree is installed from a distro package.)
Comment 8 Bernhard Reutner-Fischer 2009-08-25 09:06:50 UTC
Still broken in 2.6.30.5.
Comment 9 Yuri Frolov 2009-09-23 18:24:15 UTC
Created attachment 23154 [details]
Fix linking modules against crtsavres.o

Should export the target .o file, as suggested in comment# 4 by Olaf Hering.
Comment 10 Ali Shah 2011-05-19 19:09:53 UTC
It seems that LDFLAGS_MODULE_PREREQ as provided by these patches should be built from some sort of prepare target (potentially modules_prepare?). 

This is because, as it stands currently it is not possible to build a kernel's external modules using the provided patches in parallel (i.e using DistCC or make -j) 
Since each module is now forced to rebuild the LDFALGS_MODULE_PREREQ target, each thread has the potential to trample over another's compilation.
Comment 11 Alan 2012-10-30 14:56:51 UTC
If this is still seen on modern kernels then please re-open/update
Comment 12 Nikita Yushchenko 2014-05-07 07:36:09 UTC
This issue is still there in 3.14 and 3.15-rc4.

arch/powerpc/lib/crtsavres.o is needed to build external modules, but is not created by 'make modules_prepare'
Comment 13 Mauro Carvalho Chehab 2014-10-09 14:43:47 UTC
That still happens on 3.17. The module doesn't even need to be external.
Compiling with M=<some module> also causes the compilation breakage:

$ LANG=C PATH=/opt/gcc-4.9.1-nolibc/powerpc64-linux/bin:$PATH CROSS_COMPILE=powerpc64-linux- make ARCH=powerpc M=drivers/media/

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

  Building modules, stage 2.
  MODPOST 562 modules
  LD [M]  drivers/media//common/b2c2/b2c2-flexcop.ko
powerpc64-linux-ld: cannot find arch/powerpc/lib/crtsavres.o: No such file or directory
  LD [M]  drivers/media//common/btcx-risc.ko
make[1]: *** [drivers/media//common/b2c2/b2c2-flexcop.ko] Error 1
make[1]: *** Waiting for unfinished jobs....
powerpc64-linux-ld: cannot find arch/powerpc/lib/crtsavres.o: No such file or directory
make[1]: *** [drivers/media//common/btcx-risc.ko] Error 1
Comment 14 Mathieu Malaterre 2016-05-04 12:27:46 UTC
Still present in 4.5.0
Comment 15 Mathieu Malaterre 2016-05-04 12:28:55 UTC
Reference from Debian BTS: https://bugs.debian.org/823224
Comment 16 ncopa 2017-05-08 21:49:33 UTC
Still present in 4.9.y
Comment 17 ncopa 2017-05-08 21:59:45 UTC
Just removing the

  KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o

make it work on ppc64le. The crtsavres.o seems to be a part of gcc nowdays?
Comment 18 ncopa 2017-05-08 22:27:58 UTC
Correction, removing it makes it build. I haven't tested if it actually runs.

The commit that introduced it is da3de6df33f5f42ff9dc40093fbc884f524c9a49 ([POWERPC] Fix -Os kernel builds with newer gcc versions)
Comment 19 Christophe Leroy 2021-06-19 06:49:25 UTC
Seems like commit efe0160cfd40a99c052a00e174787c1f4158a9cd removes it for binutils >= 2.25

Can you check it works for you now ?

I so, maybe the simplest solution is to wait until binutils minimum version is at least 2.25. For the time being the minimum is 2.23