Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 409269 - sys-devel/clang-3.0-r3 fails to compile Hello World due to linker issues
Summary: sys-devel/clang-3.0-r3 fails to compile Hello World due to linker issues
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: FreeBSD (show other bugs)
Hardware: All FreeBSD
: Normal normal (vote)
Assignee: Richard Yao (RETIRED)
URL:
Whiteboard:
Keywords: Bug
Depends on: 417031
Blocks: systemwide-clang
  Show dependency tree
 
Reported: 2012-03-22 06:26 UTC by Richard Yao (RETIRED)
Modified: 2012-05-26 10:08 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Yao (RETIRED) gentoo-dev 2012-03-22 06:26:03 UTC
Clang seems to be unable to find libgcc_s.so:

# clang -v hello.c
clang version 3.0 (tags/RELEASE_30/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name hello.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.0 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.0/include -internal-externc-isystem /usr/include -internal-externc-isystem /include -ferror-limit 19 -fmessage-length 271 -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-L2UfbV.o -x c hello.c
clang -cc1 version 3.0 based upon llvm 3.0 hosted on x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/clang/3.0/include
 /usr/include
End of search list.
 "/usr/bin/x86_64-pc-linux-gnu-ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o crtbegin.o -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/hello-L2UfbV.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o /usr/lib/../lib64/crtn.o
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find crtbegin.o: No such file or directory
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc
/usr/bin/x86_64-pc-linux-gnu-ld: cannot find -lgcc_s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It is broken on Gentoo Linux and Gentoo/FreeBSD. Doing `ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so` will work around it.

# emerge --info =sys-devel/clang-3.0-r3
Portage 2.1.10.49 (default/linux/amd64/10.0/desktop/kde, gcc-4.5.3, glibc-2.13-r4, 3.2.6 x86_64)
=================================================================
                        System Settings
=================================================================
System uname: Linux-3.2.6-x86_64-Intel-R-_Core-TM-2_Quad_CPU_Q9550_@_2.83GHz-with-gentoo-2.1
Timestamp of tree: Wed, 21 Mar 2012 14:45:01 +0000
ccache version 3.1.7 [enabled]
app-shells/bash:          4.2_p24
dev-java/java-config:     2.1.11-r3
dev-lang/python:          2.7.2-r3, 3.2.2
dev-util/ccache:          3.1.7
dev-util/cmake:           2.8.7-r3
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.1
sys-apps/openrc:          0.9.9.3
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.68
sys-devel/automake:       1.11.3
sys-devel/binutils:       2.22-r1
sys-devel/gcc:            4.4.6-r1, 4.5.3-r2
sys-devel/gcc-config:     1.5.1-r1
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r3
sys-kernel/linux-headers: 3.2-r1 (virtual/os-headers)
sys-libs/glibc:           2.13-r4
Repositories: gentoo local_overlay mythtv sunrise vmware bitcoin science qt sabayon x-gentoofan
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=core2 -mtune=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/openvpn/easy-rsa"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.4/ext-active/ /etc/php/cgi-php5.4/ext-active/ /etc/php/cli-php5.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=core2 -mtune=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests binpkg-logs buildpkg ccache distlocks ebuild-locks fixlafiles multilib-strict news noinfo parallel-fetch parallel-install protect-owned sandbox sfperms split-log strict test test-fail-continue unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-march=core2 -mtune=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -O2 -pipe"
GENTOO_MIRRORS="http://mirror.lug.udel.edu/pub/gentoo/ http://gentoo.osuosl.org/ ftp://mirrors.rit.edu/gentoo/"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--sort-common"
LINGUAS="en"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage /usr/local/mythtv_portage/Gentoo /var/lib/layman/sunrise /var/lib/layman/vmware /var/lib/layman/bitcoin /var/lib/layman/science /var/lib/layman/qt /var/lib/layman/sabayon /var/lib/layman/gentoofan"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="X a52 aac acpi alsa amd64 bash-completion berkdb branding bzip2 cairo cdda cdr cjk cli consolekit cracklib crypt cups cxx dbus declarative dri dts dvd dvdr emboss encode exif fam ffmpeg fftw firefox flac fontconfig fortran gdbm gdu gif gles gnutls gpm iconv ipv6 java jpeg kde kipi lcms libnotify lzma mad mmap mmx mng modules mp3 mp4 mpeg mudflap multilib ncurses nls nptl nptlonly nsplugin ogg opengl openmp pam pango pcre pdf phonon plasma png policykit ppds pppd qt3support qt4 readline sdl session spell sse sse2 sse3 ssl ssse3 startup-notification svg sysfs tcpd theora tiff truetype udev unicode usb vdpau vorbis x264 xcb xcomposite xinerama xml xorg xscreensaver xulrunner xv xvid xvmc zlib zsh-completion" ALSA_CARDS="hda-intel hpet hrtimer" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan stage tables krita karbon braindump" CAMERAS="*" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en" PHP_TARGETS="php5-3" QEMU_SOFTMMU_TARGETS="mips mips64 mips64el mipsel x86_64" QEMU_USER_TARGETS="arm armeb mips mipsel sparc sparc64 x86_64" RUBY_TARGETS="ruby19" USERLAND="GNU" VIDEO_CARDS="nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

sys-devel/clang-3.0-r3 was built with the following:
USE="(consolekit) (multilib) (policykit) static-analyzer system-cxx-headers test -debug -multitarget"
Comment 1 Richard Yao (RETIRED) gentoo-dev 2012-03-22 06:32:47 UTC
Actually, I executed that in the wrong terminal. It only works around one of the linking issues, not all of them.

On Gentoo/FreeBSD, we need to do the following to be free of issues:

ln -s /usr/lib/gcc/i686-gentoo-freebsd9.0/4.6.2/crtend.o /usr/lib/crtend.o
ln -s /usr/lib/gcc/i686-gentoo-freebsd9.0/4.6.2/crtbegin.o /usr/lib/crtbegin.o
ln -s /usr/lib/gcc/i686-gentoo-freebsd9.0/4.6.2/crtbeginS.o /usr/lib/crtbeginS.o
ln -s /usr/lib/gcc/i686-gentoo-freebsd9.0/4.6.2/crtendS.o /usr/lib/crtendS.o
ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so

On Gentoo Linux, `ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so` will help, but it is not enough to workaround it.
Comment 2 Bernard Cafarelli gentoo-dev 2012-03-22 13:54:19 UTC
Yes, for Gentoo/notLinux the hardcoded paths everywhere will probably cause many problems. On standard arches though, clang works well (just remerged it to check)

Two things bother me here:
* ignoring nonexistent directory "/include"
* no additional paths pointing to /usr/lib/gcc/x86_64-pc-linux-gnu/* in the verbose output: these should have been added at configure time (with some calls to gcc-config in stable ebuilds). What was the configure command line when you emerged it?

clang-999 'autodetects' the gcc paths, but it lost the possibility to specify a gcc version (it always pick up the latest), bug #406163
Comment 3 Richard Yao (RETIRED) gentoo-dev 2012-03-22 18:56:30 UTC
(In reply to comment #2)
> * no additional paths pointing to /usr/lib/gcc/x86_64-pc-linux-gnu/* in the
> verbose output: these should have been added at configure time (with some
> calls to gcc-config in stable ebuilds). What was the configure command line
> when you emerged it?

On amd64 Gentoo Linux, the configure line is as follows:

./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --libdir=/usr/lib64 --enable-shared --with-optimize-option= --enable-optimized --disable-assertions --disable-expensive-checks --enable-targets=host-only --enable-pic --with-c-include-dirs=/usr/include:/include --with-cxx-include-root=/include/g++-v4 --with-cxx-include-arch=x86_64-pc-linux-gnu --with-cxx-include-32bit-dir=/32
Comment 4 Bernard Cafarelli gentoo-dev 2012-04-06 12:56:42 UTC
(In reply to comment #3)
> --with-c-include-dirs=/usr/include:/include
> --with-cxx-include-root=/include/g++-v4

Hmm so it does not find gcc prefix path (from the ebuild):
local CXX_PATH=$(gcc-config -L| cut -d: -f1)
CONF_FLAGS="${CONF_FLAGS} --with-c-include-dirs=/usr/include:${CXX_PATH}/include"
CONF_FLAGS="${CONF_FLAGS} --with-cxx-include-root=${CXX_PATH}/include/g++-v4"

Strange that gcc-config does not show anything on your system
Comment 5 Richard Yao (RETIRED) gentoo-dev 2012-05-05 14:07:54 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > --with-c-include-dirs=/usr/include:/include
> > --with-cxx-include-root=/include/g++-v4
> 
> Hmm so it does not find gcc prefix path (from the ebuild):
> local CXX_PATH=$(gcc-config -L| cut -d: -f1)
> CONF_FLAGS="${CONF_FLAGS}
> --with-c-include-dirs=/usr/include:${CXX_PATH}/include"
> CONF_FLAGS="${CONF_FLAGS} --with-cxx-include-root=${CXX_PATH}/include/g++-v4"
> 
> Strange that gcc-config does not show anything on your system

`gcc-config -L| cut -d: -f1` returns /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3 on my Linux system. It seems that I had upgraded GCC and removed the older version. This broke Clang because it had the older version set at build time.
Comment 6 Richard Yao (RETIRED) gentoo-dev 2012-05-22 08:50:56 UTC
After a chat with voyageur, I am reassigning this bug to myself and CCing the BSD team.

FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects this. Consequently, Clang will not work without it. At present, I have Clang working on my local system with some modifications to sys-freebsd/freebsd-lib to install those components as FreeBSD does.

I will attach a modified ebuild in a day or two. What I currently have locally is hackish and I do not feel it is ready for inclusion into the tree.
Comment 7 Alexis Ballier gentoo-dev 2012-05-22 13:21:04 UTC
(In reply to comment #6)
> After a chat with voyageur, I am reassigning this bug to myself and CCing
> the BSD team.
> 
> FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects

crt*.o are correct here, libgcc and libstdc++ are not if you want to be able to install multiple gcc versions
Comment 8 Richard Yao (RETIRED) gentoo-dev 2012-05-22 17:54:07 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > After a chat with voyageur, I am reassigning this bug to myself and CCing
> > the BSD team.
> > 
> > FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects
> 
> crt*.o are correct here, libgcc and libstdc++ are not if you want to be able
> to install multiple gcc versions

I am testing it and so far, GCC does not seem to care. Its build system hard codes the locations of its own libgcc and libstdc++, so it ignores the system ones.

However, I have encountered a few regressions. One is that modern g++ binaries are incapable of building the version of libstdc++ that FreeBSD uses. It produces errors on valid C++ code, so this is a regression in g++. The second is that I somehow broke PAM. I am still looking into the cause. I plan to fix both regressions before I post patches.
Comment 9 Alexis Ballier gentoo-dev 2012-05-22 18:38:26 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > After a chat with voyageur, I am reassigning this bug to myself and CCing
> > > the BSD team.
> > > 
> > > FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects
> > 
> > crt*.o are correct here, libgcc and libstdc++ are not if you want to be able
> > to install multiple gcc versions
> 
> I am testing it and so far, GCC does not seem to care. Its build system hard
> codes the locations of its own libgcc and libstdc++, so it ignores the
> system ones.

define system ones.
if gcc expects the libgcc* it provides, builds programs expecting this abi, and the program is linked with a random one from /usr/lib, with a different abi, you can expect random to break...


> However, I have encountered a few regressions. One is that modern g++
> binaries are incapable of building the version of libstdc++ that FreeBSD
> uses. It produces errors on valid C++ code, so this is a regression in g++.

the libstdc++ in fbsd is from gcc 4.2.1... lets keep it dead...
bringing in libc++ would be a much more valuable effort
Comment 10 Richard Yao (RETIRED) gentoo-dev 2012-05-22 19:01:08 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > (In reply to comment #7)
> > > (In reply to comment #6)
> > > > After a chat with voyageur, I am reassigning this bug to myself and CCing
> > > > the BSD team.
> > > > 
> > > > FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects
> > > 
> > > crt*.o are correct here, libgcc and libstdc++ are not if you want to be able
> > > to install multiple gcc versions
> > 
> > I am testing it and so far, GCC does not seem to care. Its build system hard
> > codes the locations of its own libgcc and libstdc++, so it ignores the
> > system ones.
> 
> define system ones.

GCC bundles these components and installs them in its own directory subtree, but in FreeBSD, they are system components found in /usr/lib.

> if gcc expects the libgcc* it provides, builds programs expecting this abi,
> and the program is linked with a random one from /usr/lib, with a different
> abi, you can expect random to break...

It links against libgcc.a, so there is no problem.

> > However, I have encountered a few regressions. One is that modern g++
> > binaries are incapable of building the version of libstdc++ that FreeBSD
> > uses. It produces errors on valid C++ code, so this is a regression in g++.
> 
> the libstdc++ in fbsd is from gcc 4.2.1... lets keep it dead...
> bringing in libc++ would be a much more valuable effort

Unfortunately, Clang expects these components to be in /usr/lib, which causes it to break. An alternative solution would be to modify gcc-config to install symlinks in /usr/lib. That could also address bug #406163. How does that sound?
Comment 11 Alexis Ballier gentoo-dev 2012-05-22 19:20:09 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > (In reply to comment #7)
> > > > (In reply to comment #6)
> > > > > After a chat with voyageur, I am reassigning this bug to myself and CCing
> > > > > the BSD team.
> > > > > 
> > > > > FreeBSD installs crt*.o, libgcc and libstdc++ in /usr/lib and Clang expects
> > > > 
> > > > crt*.o are correct here, libgcc and libstdc++ are not if you want to be able
> > > > to install multiple gcc versions
> > > 
> > > I am testing it and so far, GCC does not seem to care. Its build system hard
> > > codes the locations of its own libgcc and libstdc++, so it ignores the
> > > system ones.
> > 
> > define system ones.
> 
> GCC bundles these components and installs them in its own directory subtree,

since they are part of gcc, its pretty normal... gcc on gentoo does this to allow multiple gcc versions to be installed, switched, and used sanely.

> but in FreeBSD, they are system components found in /usr/lib.

components found in /usr/lib are from gcc 4.2.1... it is a problem that should be fixed in freebsd, not a route to follow.


> > if gcc expects the libgcc* it provides, builds programs expecting this abi,
> > and the program is linked with a random one from /usr/lib, with a different
> > abi, you can expect random to break...
> 
> It links against libgcc.a, so there is no problem.

not really; dynamically loading or statically linking something with an abi you dont expect is in the end the same thing...

> 
> > > However, I have encountered a few regressions. One is that modern g++
> > > binaries are incapable of building the version of libstdc++ that FreeBSD
> > > uses. It produces errors on valid C++ code, so this is a regression in g++.
> > 
> > the libstdc++ in fbsd is from gcc 4.2.1... lets keep it dead...
> > bringing in libc++ would be a much more valuable effort
> 
> Unfortunately, Clang expects these components to be in /usr/lib, which
> causes it to break. An alternative solution would be to modify gcc-config to
> install symlinks in /usr/lib. That could also address bug #406163. How does
> that sound?

you should ask this to toolchain@ but im pretty sure they have good reasons not to do so


PS: this bug has absolutely nothing to do with bsd...
Comment 12 Richard Yao (RETIRED) gentoo-dev 2012-05-26 01:41:51 UTC
(In reply to comment #11)
> PS: this bug has absolutely nothing to do with bsd...

Good point. I am reassigning it to myself.

Also, a fix for this issue was committed to CVS as part of sys-devel/clang-3.1-r1.