bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

g++/GNU ld/position independent libraries


From: Wheeler, Fred (CRD)
Subject: g++/GNU ld/position independent libraries
Date: Wed, 16 Jan 2002 18:21:54 -0500

To get right to the point -- If it is truly the case that one should not use 
GNU ld in Solaris when
making relocatable libraries then I hope somebody active in the GCC/binutils 
projects can add
warnings to the documentation or configure processes so that others can avoid 
this problem.

Over the past several days I have gone through a great deal of trouble to 
figure out why suddenly all
programs in a big project (VXL) build crashed with a bus error on Solaris 2.7 
and 2.8 immediately
upon execution.  My build system (CMake) recently switched me from -Wl,-G to 
-shared -nostdlib for
shared libs, which started to the problem.  After many long and painful 
experiments and guesses and
much help I was finally able to solve the problem by not configuring g++ to use 
GNU ld/as (stopped
using --with-gnu-as and --with-gnu-ld to configure).  After the fact I have 
found a few e-mails on
lists via google that indicate that GNU ld should not be used on Solaris for 
position independent
libs.

For anyone interested a specific demo of the problem I had is below.  Below 
that are the commands
that I USED to use to build gcc with GNU ld/as.  I had the problem with gcc 
3.0.2 and 3.0.2, Solaris
2.7 and 2.8, and binutils 2.11.2.

Thanks to everyone on these lists for what are (for the most part) fantastic 
build tools.

-Fred Wheeler

############################################################################

cd /tmp

# MAIN

cat<<EOF >| foo.cxx
int main() { return 0; }
EOF

c++ -c foo.cxx -o foo.o

# LIBRARY FILE 1

cat<<EOF >| file1.cxx
// dropping this include fixes the problem
#include <iostream>
EOF

c++ -fPIC -c file1.cxx -o file1.o

# LIBRARY FILE 2

cat<<EOF >| file2.cxx
#include <vector.h>
// dropping this expression fixes the problem
namespace {
  void tic(int nargs) {
    vector<bool> done_once(nargs, false);
  }
}
EOF

# dropping -O2 here fixes problem
c++ -O2 -fPIC -c file2.cxx -o file2.o

# BUILD LIBRARY

# with this option there is no bus error
OPT="-Wl,-G"
# with this option there is no bus error
OPT="-shared"
# with this option the exec will produce a bus error
OPT="-shared -nostdlib"

# build library with only two objects
# dropping either object fixes the problem
c++ $OPT -O2 -fPIC -o /tmp/libbar.so file1.o file2.o

# LINK

c++ foo.o -L/tmp -lbar -Wl,-R,/tmp: -o foo

# RUN

# bus error will occur here if "-shared -nostdlib" was used
./foo


# 
LD_LIBRARY_PATH=/home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/lib:/usr/lib

# ldd ./foo

# nm /tmp/libbar.so | c++filt >| nm_shared.out
# nm /tmp/libbar.so | c++filt >| nm_shared_nostdlib.out

############################################################################


#! /bin/sh -ev
if test ! -f /no_backup/wheeler/usr/download/gcc-3.0.3.tar.gz; then
  # \rm -f /no_backup/wheeler/usr/download/gcc-3.0.3.tar.gz
  wget -O /no_backup/wheeler/usr/download/gcc-3.0.3.tar.gz
ftp://ftp.cs.columbia.edu/archives/gnu/prep/gcc/gcc-3.0.3.tar.gz
fi
chmod 444 /no_backup/wheeler/usr/download/gcc-3.0.3.tar.gz
mkdir -p /tmp/source-sparc-sun-solaris2.7-gcc-3.0.3
cd /tmp/source-sparc-sun-solaris2.7-gcc-3.0.3
gzip -cd /no_backup/wheeler/usr/download/gcc-3.0.3.tar.gz | tar xvf -
mkdir -p /tmp/build-sparc-sun-solaris2.7-gcc-3.0.3
cd /tmp/build-sparc-sun-solaris2.7-gcc-3.0.3
/tmp/source-sparc-sun-solaris2.7-gcc-3.0.3/gcc-3.0.3/configure \
   \
  --with-gnu-as \
  --with-as=/home/wheeler/usr/stow/binutils-2.11.2/sparc-sun-solaris2.7/bin/as \
  --with-gnu-ld \
  --with-ld=/home/wheeler/usr/stow/binutils-2.11.2/sparc-sun-solaris2.7/bin/ld \
  --with-stabs \
  --prefix=/home/wheeler/usr/stow/gcc-3.0.3 \
  --exec-prefix=/home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7 \
  --with-local-prefix=/home/wheeler/usr/local
make \
  CFLAGS='-O' \
  LIBCFLAGS='-g -O2' \
  LIBCXXFLAGS='-g -O2 -fno-implicit-templates' \
  bootstrap-lean
make info
chmod -R u+w /home/wheeler/usr/stow/gcc-3.0.3 || true
make install
make -k install-info || true
\rm -f /home/wheeler/usr/stow/gcc-3.0.3/info/dir
mv /home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/lib/libiberty.a
/home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/lib/libiberty_gcc.a
cd 
/home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/lib/gcc-lib/sparc-sun-solaris2.7/3.0.3
 || cd
/home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/lib/gcc-lib/sparc-sun-solaris2.7/*
strip cc1 cc1obj cc1plus collect2 cpp0 f771 jc1 jvgenmain tradcpp0 || true
strip /home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/bin/* || true
strip /home/wheeler/usr/stow/gcc-3.0.3/sparc-sun-solaris2.7/sbin/* || true
chmod -R uog+rX /home/wheeler/usr/stow/gcc-3.0.3
chmod -R uog-wts /home/wheeler/usr/stow/gcc-3.0.3
# stow -v -D -d /home/wheeler/usr/stow -t /home/wheeler/usr/local gcc-3.0.3
stow -v -d /home/wheeler/usr/stow -t /home/wheeler/usr/local gcc-3.0.3
cd /tmp
\rm -rf /tmp/build-sparc-sun-solaris2.7-gcc-3.0.3
\rm -rf /tmp/source-sparc-sun-solaris2.7-gcc-3.0.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]