Bug 43810

Summary: [4.5 Regression] linking results in undefined references to _savegpr_* _restgpr_*_x
Product: gcc Reporter: Patrick Oppenlander <patrick>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: froydnj, gcc-bugs, ilya.yanok, nitin.a.kamble, raj.khem, wd
Priority: P4    
Version: 4.5.0   
Target Milestone: 4.5.3   
Host: x86_64-unknown-linux-gnu Target: powerpc-eabispe
Build: x86_64-unknown-linux-gnu Known to work:
Known to fail: Last reconfirmed:

Description Patrick Oppenlander 2010-04-19 23:57:26 UTC
After migrating to gcc 4.5.0 my build is reporting these kinds of errors at link time:

undefined reference to `_savegpr_31'
undefined reference to `_restgpr_31_x'

gcc 4.4.3 didn't emit _savegpr_* _restgpr_* etc. symbols when configured this way.

powerpc-eabispe-gcc -v
Using built-in specs.
COLLECT_GCC=powerpc-eabispe-gcc
COLLECT_LTO_WRAPPER=/home/patrick/src/e7/toolchain/stage2/libexec/gcc/powerpc-eabispe/4.5.0/lto-wrapper
Target: powerpc-eabispe
Configured with: /home/patrick/src/e7/toolchain/src/gcc-4.5.0/configure --prefix=/home/patrick/src/e7/toolchain/stage2 --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=powerpc-eabispe --enable-languages=c,c++ --with-sysroot=/home/patrick/src/e7/prex_sysroot --disable-nls --disable-werror --with-newlib --disable-shared --disable-debug --disable-libssp --with-cpu=8540
Thread model: single
gcc version 4.5.0 (GCC) 


Unfortunately I'm not familiar enough with the internals of gcc to take this any further. Is there any more debugging I can provide?
Comment 1 Andrew Pinski 2010-04-20 00:00:07 UTC
Those functions are part of the ABI and should be provided by your libc.
Does this error happen while you are linking your program or while building GCC?
Comment 2 Patrick Oppenlander 2010-04-20 00:02:39 UTC
Happens while linking my program.

Where in libc are they intended to live? Looking through the source it looks like they may be part of libgcc.a but for powerpc-eabispe they aren't built.
Comment 3 Patrick Oppenlander 2010-04-20 01:28:05 UTC
I've just done a fresh gcc build and crtsavgpr.asm crtresgpr.asm and friends definitely aren't being assembled.

Am I expected to provide these functions in the library layer of my operating system?
Comment 4 Richard Biener 2010-04-20 08:52:31 UTC
libgcc.a should provide these and libgcc.so should be a linker script.
Comment 5 Patrick Oppenlander 2010-04-20 23:01:54 UTC
Running

powerpc-eabispe-objdump -t `powerpc-eabispe-gcc --print-libgcc-file-name` |grep _save

shows no symbols so I assume something in the build process has gone wrong.

Do you need me to attach my libgcc.a or any object dump output?
Comment 6 Khem Raj 2010-04-30 04:13:59 UTC
I have similar problem when building glibc for 603e. When I dump libgcc.a
then it shows these symbols but they are hidden

crtsavfpr.o:     file format elf32-powerpc
00000000 g     F .text  0000004c .hidden _savefpr_14
00000004 g     F .text  00000048 .hidden _savefpr_15
00000008 g     F .text  00000044 .hidden _savefpr_16
0000000c g     F .text  00000040 .hidden _savefpr_17
00000010 g     F .text  0000003c .hidden _savefpr_18
00000014 g     F .text  00000038 .hidden _savefpr_19
00000018 g     F .text  00000034 .hidden _savefpr_20
0000001c g     F .text  00000030 .hidden _savefpr_21
00000020 g     F .text  0000002c .hidden _savefpr_22
00000024 g     F .text  00000028 .hidden _savefpr_23
00000028 g     F .text  00000024 .hidden _savefpr_24
0000002c g     F .text  00000020 .hidden _savefpr_25
00000030 g     F .text  0000001c .hidden _savefpr_26
00000034 g     F .text  00000018 .hidden _savefpr_27
00000038 g     F .text  00000014 .hidden _savefpr_28
0000003c g     F .text  00000010 .hidden _savefpr_29
00000040 g     F .text  0000000c .hidden _savefpr_30
00000044 g     F .text  00000008 .hidden _savefpr_31
crtsavgpr.o:     file format elf32-powerpc
00000000 g     F .text  0000004c .hidden _savegpr_14
00000004 g     F .text  00000048 .hidden _savegpr_15
00000008 g     F .text  00000044 .hidden _savegpr_16
0000000c g     F .text  00000040 .hidden _savegpr_17
00000010 g     F .text  0000003c .hidden _savegpr_18
00000014 g     F .text  00000038 .hidden _savegpr_19
00000018 g     F .text  00000034 .hidden _savegpr_20
0000001c g     F .text  00000030 .hidden _savegpr_21
00000020 g     F .text  0000002c .hidden _savegpr_22
00000024 g     F .text  00000028 .hidden _savegpr_23
00000028 g     F .text  00000024 .hidden _savegpr_24
0000002c g     F .text  00000020 .hidden _savegpr_25
00000030 g     F .text  0000001c .hidden _savegpr_26
00000034 g     F .text  00000018 .hidden _savegpr_27
00000038 g     F .text  00000014 .hidden _savegpr_28
0000003c g     F .text  00000010 .hidden _savegpr_29
00000040 g     F .text  0000000c .hidden _savegpr_30
00000044 g     F .text  00000008 .hidden _savegpr_31
Comment 7 Khem Raj 2010-04-30 04:34:26 UTC
calls to _savegpr_31 and _restgpr_31_x are only generated when compiling libgcc with -Os same compiled with -O2 it does not emit the calls

here is a reduced testcase from crtstuff.c compile it will -Os and then with -O2 

typedef void (*func_ptr) (void);
static func_ptr __CTOR_END__[1]
  __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
  = { (func_ptr) 0 };
static void __attribute__((used))
__do_global_ctors_aux (void)
{
  func_ptr *p;
  for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
    (*p) ();
}
Comment 8 Khem Raj 2010-04-30 04:55:32 UTC
below is the linker command that reports liking error.

/scratch/oe/efika/cross/ppc603e/lib/gcc/powerpc-oe-linux/4.5.0/crtend.o: In function `__do_global_ctors_aux':
crtstuff.c:(.text+0xc): undefined reference to `_savegpr_31'
collect2: ld returned 1 exit status

as we can see the failure is seen in crtend.o and in the linking order libgcc is specified before crtend.o therefore it does not pick the required object from
libgcc.a if I add -lgcc after crtend.o then it links successfully.

/scratch/oe/efika/cross/ppc603e/bin/powerpc-oe-linux-gcc -nostdlib -nostartfiles -o /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/posix/getconf  -Wl,-dynamic-linker=/lib/ld.so.1   -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/csu/crt1.o /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/csu/crti.o `/scratch/oe/efika/cross/ppc603e/bin/powerpc-oe-linux-gcc -mcpu=603e -mhard-float --print-file-name=crtbegin.o` /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/posix/getconf.o  -Wl,-rpath-link=/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/math:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/elf:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/dlfcn:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/nss:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/nis:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/rt:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/resolv:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/crypt:/scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/nptl /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/libc.so.6 /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/libc_nonshared.a -lgcc `/scratch/oe/efika/cross/ppc603e/bin/powerpc-oe-linux-gcc -mcpu=603e -mhard-float --print-file-name=crtend.o` /scratch/oe/efika/work/ppc603e-oe-linux/eglibc-2.11-r10.4/build-powerpc-oe-linux/csu/crtn.o
Comment 9 Patrick Oppenlander 2010-04-30 06:57:23 UTC
Khem,

Your libgcc.a looks fine. As far as I know, libgcc.a is supposed to be the last library listed when linking so the behaviour you are seeing is normal.

My problem is that libgcc.a does not contain _savegpr_* and _restgpr_* functions at all. It looks like they are only built for linux and gnu targets, not eabispe.
Comment 10 Richard Biener 2010-05-19 12:34:47 UTC
See comment #4.  I believe this is a pilot error.
Comment 11 Khem Raj 2010-05-19 16:25:56 UTC
(In reply to comment #10)
> See comment #4.  I believe this is a pilot error.
> 

yeah on 4.5.0 libgcc.so is a linker script but 4.4 is still broken with this issues

I guess http://gcc.gnu.org/ml/gcc-cvs/2009-09/msg00315.html needs backported to 4.4 branch as well.
Comment 12 Patrick Oppenlander 2010-05-19 22:58:25 UTC
(In reply to comment #10)
> See comment #4.  I believe this is a pilot error.
> 

Richard,

Are you referring to my original bug report or to Khem's link problem.

I don't think (unless I've messed up my gcc build) that my original report is misuse.
Comment 13 Richard Biener 2010-07-31 09:29:47 UTC
GCC 4.5.1 is being released, adjusting target milestone.
Comment 14 Richard Biener 2010-12-16 13:03:23 UTC
GCC 4.5.2 is being released, adjusting target milestone.
Comment 15 Wolfgang Denk 2010-12-20 12:22:22 UTC
For the record: the problem appears to be still present in 4.5.1 (at least I run into the same symptoms when trying to build poky with "--enable-target-optspace" enabled.
Comment 16 Nitin Kamble 2011-02-15 00:43:47 UTC
4.5.2 also carries the issue.
Comment 17 Nathan Froyd 2011-02-23 18:06:38 UTC
Author: froydnj
Date: Wed Feb 23 18:06:29 2011
New Revision: 170443

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170443
Log:
	PR target/43810

	Backport from mainline:
	2010-07-23  Nathan Froyd  <froydnj@codesourcery.com>

	* config.host (powerpc*-eabispe*): Set tmake_file.
	(powerpc*-eabi*): Likewise.
	* config/rs6000/t-ppccomm (EXTRA_PARTS): Add crtbegin, crtend,
	crtbeginS, crtendS, crtbeginT.

Modified:
    branches/gcc-4_5-branch/libgcc/ChangeLog
    branches/gcc-4_5-branch/libgcc/config.host
    branches/gcc-4_5-branch/libgcc/config/rs6000/t-ppccomm
Comment 18 Nathan Froyd 2011-02-23 18:10:02 UTC
Fixed on the 4.5 branch.

If there are still problems with --enable-target-optspace, please open a separate bug for those.
Comment 19 Ilya Yanok 2011-03-22 23:40:01 UTC
I still get the error similar to Khem's one with gcc 4.5.1 and proposed patch applied:

ccache powerpc-poky-linux-gcc -mcpu=603e  -msoft-float --sysroot=/opt/work/yanok/poky/build/tmp/sysroots/ppc603e-poky-linux -nostdlib -nostartfiles -o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/iconv_prog -msoft-float -Wl,-dynamic-linker=/lib/ld.so.1   -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/csu/crt1.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/csu/crti.o `ccache powerpc-poky-linux-gcc -mcpu=603e  -msoft-float --sysroot=/opt/work/yanok/poky/build/tmp/sysroots/ppc603e-poky-linux -msoft-float --print-file-name=crtbegin.o` /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/iconv_prog.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/iconv_charmap.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/charmap.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/charmap-dir.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/linereader.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/dummy-repertoire.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/simple-hash.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/xstrdup.o /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/iconv/xmalloc.o  -Wl,-rpath-link=/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/math:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/elf:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/dlfcn:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/nss:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/nis:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/rt:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/resolv:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/crypt:/opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/nptl /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/libc.so.6 /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/libc_nonshared.a -Wl,--as-needed /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/elf/ld.so -Wl,--no-as-needed -lgcc -Wl,--as-needed -lgcc_s  -Wl,--no-as-needed `ccache powerpc-poky-linux-gcc -mcpu=603e  -msoft-float --sysroot=/opt/work/yanok/poky/build/tmp/sysroots/ppc603e-poky-linux -msoft-float --print-file-name=crtend.o` /opt/work/yanok/poky/build/tmp/work/ppc603e-poky-linux/eglibc-2.12-r13/build-powerpc-poky-linux/csu/crtn.o                                                               
/opt/work/yanok/poky/build/tmp/sysroots/x86_64-linux/usr/lib/ppc603e-poky-linux/gcc/powerpc-poky-linux/4.5.1/crtend.o: In function `__do_global_ctors_aux':              
crtstuff.c:(.text+0xc): undefined reference to `_savegpr_31'                                                                                                             
collect2: ld returned 1 exit status

Though libgcc.a does contain _savegpr_31.