RFC: Proposal for a patch that changes multilib linker scripts.

Steve Ellcey sellcey at mips.com
Tue Mar 11 15:59:03 UTC 2014


I am building a GCC cross compiler tool chain with uclibc and noticed a
difference between libc.so from glibc and from uclibc when building a
multilib toolchain.  As an example, on glibc, compiling for mips64r2,
N64 ABI, little endian; I put libraries like libc.so in
<root>/mips64r2/64/el/usr/lib/libc.so and the contents of libc.so are:


/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-tradlittlemips)
GROUP ( /usr/lib/libc.so.6 /usr/lib/libc_nonshared.a  AS_NEEDED ( /usr/lib/ld.so
.1 ) )


But when I build with uclibc and put libc.so in the same location by setting
the MULTILIB_DIR, its libc.so contents are:


/* GNU ld script
 * Use the shared library, but some functions are only in
 * the static library, so try that secondarily. */
OUTPUT_FORMAT("elf64-tradlittlemips", "elf64-tradbigmips",
	      "elf64-tradlittlemips")
GROUP ( /mips64r2/64/el/usr/lib/libc.so.0 /mips64r2/64/el/usr/lib/uclibc_nonshar
ed.a AS_NEEDED ( /mips64r2/64/el/usr/lib/ld64-uClibc.so.0 ) )


Then when I try to compile things with this multilib GCC I get errors like:

/local/home/sellcey/gcc/uclibc_err/install-mips-mti-linux-uclibc/mips-mti-linux-uclibc/bin/ld: cannot find /mips64r2/64/el/usr/lib/uclibc_nonshared.a inside /local/home/sellcey/gcc/uclibc_err/install-mips-mti-linux-uclibc/sysroot/mips64r2/64/el
/local/home/sellcey/gcc/uclibc_err/install-mips-mti-linux-uclibc/mips-mti-linux-uclibc/bin/ld: cannot find /mips64r2/64/el/usr/lib/ld-uClibc.so.0 inside /local/home/sellcey/gcc/uclibc_err/install-mips-mti-linux-uclibc/sysroot/mips64r2/64/el

I believe this is because I am running GCC with sysroot option and that is
adding the '/mips64r2/64/el' prefix on to paths, but then that path is also
in the libc.so ld script.  I would like to modify uclibc so I can make the
ld script for uclibc look more like the glibc one and have come up with
attached changes.

If it looks OK, I will submit a proper patch but I thought I would get some
feedback on this approach first and make sure it is considered a reasonable
change to propose.  My idea is to add a new variable (GROUP_DIR) that can
be set to change the contents of libc.so.  By default it would be set to
MULTILIB_DIR so that anyone who does not set this variable is not affected.
But if it is set then it is used to set the contents of libc.so while
MULTILIB_DIR is still used when determining where to install the actual
libraries.

Steve Ellcey
sellcey at mips.com


Here is a diff of my current idea for a patch:


diff --git a/Makefile.in b/Makefile.in
index 5419704..ccd7729 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -361,6 +361,11 @@ install_startfiles: startfiles | $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)
 	-$(INSTALL) -m 644 $(startfiles) $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/
 
 # Installs development library links.
+
+ifeq ($(GROUP_DIR),)
+GROUP_DIR=$(MULTILIB_DIR)
+endif
+
 install_dev: install_headers install_runtime install_startfiles | $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)
 	-$(INSTALL) -m 644 $(top_builddir)lib/*.a $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/
 ifeq ($(HAVE_SHARED),y)
@@ -372,9 +377,9 @@ ifeq ($(HAVE_SHARED),y)
 ifeq ($(HARDWIRED_ABSPATH),y)
 	if [ -f $(top_builddir)lib/libc.so -a -f $(PREFIX)$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME) ] ; then \
 		$(RM) $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
-		$(SED) -e 's:$(NONSHARED_LIBNAME):$(DEVEL_PREFIX)$(MULTILIB_DIR)/$(NONSHARED_LIBNAME):' \
-		    -e 's:$(SHARED_LIBNAME):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME):' \
-		    -e 's:$(UCLIBC_LDSO):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UCLIBC_LDSO):' \
+		$(SED) -e 's:$(NONSHARED_LIBNAME):$(DEVEL_PREFIX)$(GROUP_DIR)/$(NONSHARED_LIBNAME):' \
+		    -e 's:$(SHARED_LIBNAME):$(RUNTIME_PREFIX)$(GROUP_DIR)/$(SHARED_LIBNAME):' \
+		    -e 's:$(UCLIBC_LDSO):$(RUNTIME_PREFIX)$(GROUP_DIR)/$(UCLIBC_LDSO):' \
 		    $(top_builddir)lib/libc.so > $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
 		$(SED) -i -e 's://:/:g' $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
 	fi
@@ -388,7 +393,7 @@ ifeq ($(HARDWIRED_ABSPATH),y)
 	if [ -f $(top_builddir)lib/libpthread.so -a -f $(PREFIX)$(RUNTIME_PREFIX)$(MULTILIB_DIR)/libpthread.so.$(ABI_VERSION) ] ; then \
 		$(RM) $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libpthread.so; \
 		cp $(top_srcdir)extra/scripts/format.lds $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libpthread.so; \
-		echo "GROUP ( $(RUNTIME_PREFIX)$(MULTILIB_DIR)/libpthread.so.$(ABI_VERSION) $(DEVEL_PREFIX)$(MULTILIB_DIR)/libpthread_nonshared.a )" \
+		echo "GROUP ( $(RUNTIME_PREFIX)$(GROUP_DIR)/libpthread.so.$(ABI_VERSION) $(DEVEL_PREFIX)$(GROUP_DIR)/libpthread_nonshared.a )" \
 			>> $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libpthread.so; \
 		$(SED) -i -e 's://:/:g' $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libpthread.so; \
 	fi


More information about the uClibc mailing list