[LLVMdev] ld crashes with invalid pointer on Ubuntu 11.04 x86 when linking libgcc_s.so

Don Quixote de la Mancha quixote at dulcineatech.com
Mon Oct 3 09:35:28 PDT 2011

I don't get the crash at all with the ld I built myself from the
Ubuntu 11.04 source deb.  Instead I get a complaint that ld cannot
find -lc; I believe I had the --prefix path wrong when I built the
release llvm at the start, so that later "make bootstrap" in
llvm-gcc-4.2 looks in the wrong place.

I didn't start my build with a binary distro of llvm-gcc.  I expect it
would have been easier if I had but I wanted to try bootstrapping the
source from scratch.

I'm not sure, but a possibility is that either ld or a library it
depends on has badly generated code.  I built with debugging on, which
may have altered the generated i386 code.

I also built on a 32-bit Core Duo; I expect that whoever built the
optimized binaries for Ubuntu did so on an x86_64 box with a compiler
that produces i386 binaries, a sort of cross-compiler.  We all know
that cross-compilers are cans of worms!

/usr/bin/ld is a symbolic link to /usr/bin/ld.bfd.  Here is how I
rebuilt it myself:

First we need to know what Ubuntu package ld.bfd is part of:

$ sudo apt-get install apt-file

Apt-file needs to download some databases:

$ sudo apt-file update
$ apt-file search ld.bfd

Apt-file now says that ld.bfd is in binutils.

$ mkdir ~/DebSrc
$ cd ~/DebSrc
$ sudo apt-get source binutils

On Debian one would now use dpkg-source to unroll the source archive,
but "apt-get source" does this on its own on Ubuntu.

$ cd binutils-

We might need some special tools, header files or development
libraries to do the build:

$ sudo apt-get build-dep binutils
$ sudo apt-get install build-essentials fakeroot dpkg-dev

Examination of the configure script seems to indicate we want to set
$CFLAGS_FOR_BUILD to "-g" rather than just $CFLAGS:

$ export CFLAGS_FOR_BUILD=-g

On Debian, $DEB_BUILD_OPTIONS will be passed on to configure, but it
didn't work for me on Ubuntu.  That is, I tried:

$ export DEB_BUILD_OPTIONS=--prefix=/home/mike/binutils-

... because I didn't want to clobber the official binutils, lest I
break everything real bad.  But when I installed the binary debs, all
the executables and such went into /usr, just as if I made an official
build.  I don't know what I might have done wrong.

Now build the binaries:

$ fakeroot debian/rules binary

The binary deb archives are placed in the parent directory to where
you are now (~/DebSrc):

$ cd ..
$ ls -l *.deb

(The listing shows several debs that were just created.)

Now install them.  As I said I didn't want to install these over the
official packages, but somehow screwed up.  Even so, I think I got a
good build so it's OK

$ sudo dpkg -i *.deb

I made a one-line - one VERY LONG line - script with the xgcc command
line that links libgcc_s.so.1.  With the release /usr/bin/ld.bfd, it
dumps core, but with mine it says:

/usr/bin/ld: cannot find -lc

This seems to be because I didn't put my initial build of llvm where
the bootstrap llvm-gcc wants to find that.  Once I make sure I've got
my configure command lines set up right and can build, I'll post a
followup to this threa.

Don Quixote de la Mancha
Dulcinea Technologies Corporation
Software of Elegance and Beauty
quixote at dulcineatech.com

More information about the llvm-dev mailing list