Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Feb 2016 00:26:26 +0000
From:      Ben Morrow <ben@morrow.me.uk>
To:        freebsd-mips@freebsd.org
Subject:   mips/qemu jails with native-xtools
Message-ID:  <20160205002626.GA93874@anubis.morrow.me.uk>

next in thread | raw e-mail | index | archive | help
I've finally got a mips/qemu poudriere jail working properly with a
native toolchain, but it took a bit of fiddling to make it work, so I
thought I'd report on what I did.

First I tried installing things the way poudriere -x does, with an
/nxb-bin directory in the jail and redirections in make.conf. That
doesn't work because /nxb-bin/usr/bin/cc just invokes /usr/libexec/cc1,
which is still a mips executable.

Then I tried copying the nxb-bin tree directly into the root of the
jail. This caused a problem immediately: the nxb-bin tree includes the
static flex libraries (/usr/lib/lib{l,fl,ln}.a) built for amd64.
Obviously this isn't going to work; it's the cause of the bison build
failures I found mentioned in the archives.

Having put the proper libraries back, the next problem was that ld was
failing to find shared libraries that were implicitly linked (DT_NEEDED)
by other shared libraries. The specific port I was building was
net/tshark, which links glib, which implicitly pulls in libpcre and
libiconv. The configure step was failing because ld couldn't find
libpcre.so.3.

It turns out that ld finds the path to search for DT_NEEDED libraries by
reading ld-elf.so.hints. That file (in the jail) is BE, because this is
a mips world with a mips ldconfig, but the ld binary is LE, so it can't
read the file. With the patch below, it can; since endianness is the
only difference between architectures, I think it should be safe for
general use, but I don't really know.

Ben

diff --git a/contrib/binutils/ld/emultempl/elf32.em b/contrib/binutils/ld/emultempl/elf32.em
index 4f707ff..5219820 100644
--- a/contrib/binutils/ld/emultempl/elf32.em
+++ b/contrib/binutils/ld/emultempl/elf32.em
@@ -539,6 +539,7 @@ EOF
 #else
 #include "elf-hints-local.h"
 #endif
+#include <sys/endian.h>
 
 static bfd_boolean
 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
@@ -560,17 +561,28 @@ gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
 	{
 	  struct elfhints_hdr hdr;
 
-	  if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
-	      && hdr.magic == ELFHINTS_MAGIC
-	      && hdr.version == 1)
-	    {
-	      if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
+	  if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr))
+            {
+              u_int32_t start = 0, len;
+
+              if (hdr.magic == ELFHINTS_MAGIC
+	          && hdr.version == 1)
+                {
+                  start = hdr.strtab + hdr.dirlist;
+                  len = hdr.dirlistlen;
+                }
+              if (bswap32(hdr.magic) == ELFHINTS_MAGIC
+                  && bswap32(hdr.version) == 1)
+                {
+                  start = bswap32(hdr.strtab) + bswap32(hdr.dirlist);
+                  len = bswap32(hdr.dirlistlen);
+                }
+              if (start && fseek (f, start, SEEK_SET) != -1)
 		{
 		  char *b;
 
-		  b = xmalloc (hdr.dirlistlen + 1);
-		  if (fread (b, 1, hdr.dirlistlen + 1, f) ==
-		      hdr.dirlistlen + 1)
+		  b = xmalloc (len + 1);
+		  if (fread (b, 1, len + 1, f) == len + 1)
 		    ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
 
 		  free (b);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160205002626.GA93874>