Bug 41818

Summary: Error building cross compiler caused by changing LD_LIBRARY_PATH environment variable in Makefile
Product: gcc Reporter: Denis Onischenko <denis.onischenko>
Component: bootstrapAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: denis.onischenko, gcc-bugs, jocke, lacombar, rwild, sjames, viriketo
Priority: P3    
Version: 4.5.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105688
Host: x86_64-unknown-linux-gnu Target: powerpc64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu Known to work:
Known to fail: Last reconfirmed:
Attachments: patch to add TARGET_LIB_PATH only when bootstrapping

Description Denis Onischenko 2009-10-24 20:08:19 UTC
The following error occurs when compiling "x86_64 to powerpc64"
cross compiler, as soon as the libgcc_s.so.1 has appeared in obj/gcc
directory:

...
# Now that we have built all the objects, we need to copy
# them back to the GCC directory.  Too many things (other
# in-tree libraries, and DejaGNU) know about the layout
# of the build tree, for now.
make install-leaf DESTDIR=../.././gcc \
 slibdir= libsubdir= MULTIOSDIR=.
make[5]: Entering directory
`/a/linux/.powerpc/gcc/obj/powerpc64-unknown-linux-gnu/libgcc'
/bin/bash ../../../src/libgcc/../mkinstalldirs ../.././gcc
/usr/bin/install -c -m 644 libgcc_eh.a ../.././gcc/
chmod 644 ../.././gcc/libgcc_eh.a
/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/ranlib
../.././gcc/libgcc_eh.a
/bin/bash ../../../src/libgcc/../mkinstalldirs ../.././gcc;
/usr/bin/install -c -m 644 ./libgcc_s.so.1 ../.././gcc/libgcc_s.so.1;
rm -f ../.././gcc/libgcc_s.so; ln -s libgcc_s.so.1
../.././gcc/libgcc_s.so
/bin/bash ../../../src/libgcc/../mkinstalldirs ../.././gcc
/usr/bin/install -c -m 644 libgcc.a ../.././gcc/
chmod 644 ../.././gcc/libgcc.a
/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/ranlib
../.././gcc/libgcc.a
/usr/bin/install -c -m 644 libgcov.a ../.././gcc/
chmod 644 ../.././gcc/libgcov.a
/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/ranlib
../.././gcc/libgcov.a
parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o ecrti.o
ecrtn.o ncrti.o ncrtn.o"; \
for file in $parts; do \
 rm -f ../.././gcc/$file; \
 /usr/bin/install -c -m 644 $file ../.././gcc/; \
done
make[5]: Leaving directory
`/a/linux/.powerpc/gcc/obj/powerpc64-unknown-linux-gnu/libgcc'
make[4]: Leaving directory
`/a/linux/.powerpc/gcc/obj/powerpc64-unknown-linux-gnu/libgcc'
Checking multilib configuration for libgomp...
mkdir -p -- powerpc64-unknown-linux-gnu/libgomp
Configuring in powerpc64-unknown-linux-gnu/libgomp
configure: creating cache ./config.cache
checking for --enable-version-specific-runtime-libs... no
checking for --enable-generated-files-in-srcdir... no
checking build system type... x86_64-unknown-linux-gnu
checking host system type... powerpc64-unknown-linux-gnu
checking target system type... powerpc64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for powerpc64-unknown-linux-gnu-strip...
/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/strip
checking for powerpc64-unknown-linux-gnu-gcc...
/a/linux/.powerpc/gcc/obj/./gcc/xgcc
-B/a/linux/.powerpc/gcc/obj/./gcc/
-B/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/
-B/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/lib/
-isystem /a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/include
-isystem /a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/sys-include
checking for C compiler default output file name... configure: error:
in `/a/linux/.powerpc/gcc/obj/powerpc64-unknown-linux-gnu/libgomp':
configure: error: C compiler cannot create executables
See `config.log' for more details.
make[3]: *** [configure-target-libgomp] Error 1
make[3]: Leaving directory `/a/linux/.powerpc/gcc/obj'

The obj/powerpc64-unknown-linux-gnu/libgomp/config.log content is:

...
configure:2569: checking for C compiler default output file name
configure:2572: /a/linux/.powerpc/gcc/obj/./gcc/xgcc
-B/a/linux/.powerpc/gcc/obj/./gcc/
-B/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/bin/
-B/a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/lib/
-isystem /a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/include
-isystem /a/linux/.powerpc/cross-tools/powerpc64-unknown-linux-gnu/sys-include
-g -O2     conftest.c  >&5
/a/linux/.powerpc/gcc/obj/./gcc/cc1: error while loading shared
libraries: /a/linux/.powerpc/gcc/obj/./gcc/libgcc_s.so.1: ELF file
data encoding not little-endian
configure:2575: $? = 1
configure: failed program was:
| /* confdefs.h.  */
|
| #define PACKAGE_NAME "GNU OpenMP Runtime Library"
| #define PACKAGE_TARNAME "libgomp"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU OpenMP Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE "libgomp"
| #define VERSION "1.0"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:2613: error: in
`/a/linux/.powerpc/gcc/obj/powerpc64-unknown-linux-gnu/libgomp':
configure:2616: error: C compiler cannot create executables
See `config.log' for more details.
...


It seems that host cc1 executable tries to load target libgcc_s.so.1
from obj/gcc directory, rather than host libgcc_s.so.1 from /lib.

I have successfully build the cross-compiler with overriden RPATH_ENVVAR variable, as following:

make RPATH_ENVVAR=MY_LD_LIBRARY_PATH

 So error was indeed caused by changing LD_LIBRARY_PATH environment variable during the build

HOST gcc version is:

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu4) 


gcc versions I was tried to build are 4.4.1 and 4.5.0 (rev 153504)
Comment 1 Denis Onischenko 2009-10-24 20:23:15 UTC
I run the configure script as follows:

../src/configure --build=x86_64-unknown-linux-gnu
--host=x86_64-unknown-linux-gnu --target=powerpc64-unknown-linux-gnu
--prefix=$(BUILDDIR)/cross-tools --disable-werror --with-sysroot=$(SYSROOT) --enable-languages=c,c++ --disable-multilib
--disable-nls
Comment 2 Andrew Pinski 2009-10-25 21:00:32 UTC
@if gcc-bootstrap
        $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
@endif gcc-bootstrap


That is only happens when doing a native bootstrap and never when doing a cross build.  
Comment 3 Andrew Pinski 2009-10-25 21:01:26 UTC
Actually, wait:
        $(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);

For BASE_TARGET_EXPORTS.
Comment 4 Joachim Nilsson 2010-01-06 13:53:08 UTC
I can confirm this issue while building an armeb-unknown-uclibcgnueabi (big-endian) cross toolchain on i686 (Ubuntu 9.10 32-bit) using crosstool-NG.  However, I cannot replicate it on any host running x86_64 (Ubuntu 9.04 or 9.10, 64-bit).  Also, when building a arm-unknown-uclibcgnueabi (little-endian) this bug is not triggered.  Maybe that helps.

Some of the messages in the official mailing list archive related to this issue have somehow been lost (?), http://gcc.gnu.org/ml/gcc-bugs/2009-10/msg02122.html (see the thread view).  I found http://old.nabble.com/Re:-Error-when-building-cross-compiler-td25755999.html where Kai Ruottu gave some interesting insight.

The bug can be worked around by adding the --disable-shared configure option to the last (final) stage in the compiler build.
Comment 5 Ralf Wildenhues 2010-01-06 17:33:07 UTC
Created attachment 19486 [details]
patch to add TARGET_LIB_PATH only when bootstrapping

Please try this patch.  Thanks.
Comment 6 Denis Onischenko 2010-01-06 20:19:04 UTC
(In reply to comment #5)
> Created an attachment (id=19486) [edit]
> patch to add TARGET_LIB_PATH only when bootstrapping
> 
> Please try this patch.  Thanks.
> 

I have successfuly compiled cross compiler with this patch. gcc revision is 155559. host is x86_64-unknown-linux-gnu, target is powerpc64-unknown-linux-gnu.
Comment 7 Joachim Nilsson 2010-01-06 20:31:57 UTC
Yep, works for me too, using crosstool-NG to build an armeb-unknown-linux-uclibcgnueabi for i686 host. Thanks Ralf!
Comment 8 Ralf Wildenhues 2010-01-07 19:54:06 UTC
Subject: Bug 41818

Author: rwild
Date: Thu Jan  7 19:53:50 2010
New Revision: 155706

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155706
Log:
Fix PR bootstrap/41818.

/:
	PR bootstrap/41818
	* Makefile.tpl (BASE_TARGET_EXPORTS): Only add TARGET_LIB_PATH
	to $(RPATH_ENVVAR) if bootstrapping.  Fix typo in comment.
	* Makefile.in: Regenerate.


Modified:
    trunk/ChangeLog
    trunk/Makefile.in
    trunk/Makefile.tpl

Comment 9 Ralf Wildenhues 2010-01-07 19:57:25 UTC
Fixed.
Comment 10 Andrew Pinski 2010-02-27 01:20:48 UTC
*** Bug 43194 has been marked as a duplicate of this bug. ***
Comment 11 Arnaud Lacombe 2010-08-05 23:29:15 UTC
I encountered that issue with gcc 4.3.4 on the following target: mips-unknown-linux-uclibc. I'm currently confirming with gcc 4.3.5. If it still happen, would it be worth pulling to the 4.3 branch ?
Comment 12 Arnaud Lacombe 2010-08-06 00:01:07 UTC
ok, 3.4.5, same target is bad too:

./mips-unknown-linux-uclibc/libstdc++-v3/config.log:
error while loading shared libraries: /targets/mips-unknown-linux-uclibc/build/build-cc/./gcc/libgcc_s.so.1: ELF file data encoding not little-endian
Comment 13 Ralf Wildenhues 2010-08-07 14:18:15 UTC
(In reply to comment #11)
> I encountered that issue with gcc 4.3.4 on the following target:
> mips-unknown-linux-uclibc. I'm currently confirming with gcc 4.3.5. If it still
> happen, would it be worth pulling to the 4.3 branch ?

Can you please confirm that the patch from comment #8 fixes the issue for you on the 4.3 (and maybe also 4.4) branch?  I'd propose the backport on gcc-patches then.  Thanks.