Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 406163 - sys-devel/clang-9999 detects wrong libstdc++ include / library path
Summary: sys-devel/clang-9999 detects wrong libstdc++ include / library path
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal with 2 votes (vote)
Assignee: Gentoo Clang Team (OBSOLETE)
URL:
Whiteboard:
Keywords:
: 405233 (view as bug list)
Depends on:
Blocks: systemwide-clang
  Show dependency tree
 
Reported: 2012-02-28 15:04 UTC by Matthias Dahl
Modified: 2015-10-16 11:16 UTC (History)
3 users (show)

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


Attachments
Patch proposal that adds runtime detection of correct GCC version (clang-3.0-gentoo.patch,1.78 KB, patch)
2012-05-23 18:51 UTC, Richard Yao (RETIRED)
Details | Diff
Patch proposal that adds runtime detection of correct GCC version (clang-3.0-gentoo.patch,1.69 KB, patch)
2012-05-23 19:46 UTC, Richard Yao (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Dahl 2012-02-28 15:04:20 UTC
I have several gcc versions installed (4.5.3-r2, 4.6.2, 4.6.3_pre9999, 4.7.0_alpha20120114) and clang always detects the highest gcc version available for its include and library path. This is bound to cause trouble when the actual active version is for example 4.6.x and clang uses the libstdc++ related stuff from 4.7.0_alpha during compile and link time. (like in my case)

Compiling a simple helloworld.cpp:

clang version 3.1 (trunk)
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 helloworld.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4/x86_64-pc-linux-gnu -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /root -ferror-limit 19 -fmessage-length 188 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/helloworld-fyDgWY.o -x c++ helloworld.cpp
clang -cc1 version 3.1 based upon LLVM 3.1svn default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4/x86_64-pc-linux-gnu
 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/include/g++-v4/backward
 /usr/local/include
 /usr/bin/../lib/clang/3.1/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 helloworld /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../.. -L/lib -L/usr/lib /tmp/helloworld-fyDgWY.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20120114/../../../../lib64/crtn.o

This was tested with today's trunk and ebuild on a ~AMD64 system.

Reproducible: Always
Comment 1 Matthias Dahl 2012-02-28 17:53:20 UTC
I might be wrong but shouldn't
 /usr/lib64/gcc/x86_64-pc-linux-gnu/<gcc-version>/include/ also
be in the path as well? Otherwise packages might fail because clang can't find cxxabi.h which is located there as well. One example for this is chromium which fails to due to not finding cxxabi.h.
Comment 2 Matthias Dahl 2012-02-28 19:33:40 UTC
Ok... Clang++ not finding "cxxabi.h" is actually a problem on our side, so I have opened bug 406209 about it.

Regarding the priority of the different include paths itself. That is intended behavior. Clang++ always uses the highest version installed which imho can cause trouble (see above). There is a new configure option (also exposed as runtime option) according to one of the llvm guys "-gcc-toolchain" or similar which we could use to fix this to our needs. (haven't checked it yet, since I am in hurry and short on time, sorry)
Comment 3 Bernard Cafarelli gentoo-dev 2012-02-29 09:55:25 UTC
*** Bug 405233 has been marked as a duplicate of this bug. ***
Comment 4 Bernard Cafarelli gentoo-dev 2012-02-29 09:57:14 UTC
Thanks for your work on this :)

I thought the gcc-toolchain option was something like our PREFIX variable, I'll update my 9999 checkout and look at it again
Comment 5 Matthias Dahl 2012-02-29 18:57:12 UTC
Sure thing. I'm glad to help. I'm sorry I cannot be of more use currently as I am writing my degree dissertation and have only a few weeks left. But if there is anything else, just let me know. I really would like to see the clang support in Gentoo flourish.
Comment 6 Bernard Cafarelli gentoo-dev 2012-04-06 12:18:03 UTC
I finally had some time to look at this, for now I think the cleanest way would be to have a "-gcc-version" option in llvm/clang close to the existing "-gcc-toolchain"

When looping over /usr/lib/gcc/x86_64-pc-linux-gnu/ (or wherever the detector goes), instead of looping over folders and stopping at the highest version, a first test would be run on /usr/lib/gcc/x86_64-pc-linux-gnu/"gcc-version" if it is set

I'll open a bugreport upstream to see what they think of this (or if they have a better solution)
Comment 7 Bernard Cafarelli gentoo-dev 2012-05-09 11:29:00 UTC
The relevant upstream bug is in the "See Also" part:
http://llvm.org/bugs/show_bug.cgi?id=12479

(commenting here to make it more visible :) )
Comment 8 Richard Yao (RETIRED) gentoo-dev 2012-05-22 19:02:08 UTC
It might be possible to resolve this by modifying gcc-config to install a symlink to libstdc++ in /usr/lib.
Comment 9 Richard Yao (RETIRED) gentoo-dev 2012-05-23 18:51:41 UTC
Created attachment 312865 [details, diff]
Patch proposal that adds runtime detection of correct GCC version

(In reply to comment #8)
> It might be possible to resolve this by modifying gcc-config to install a
> symlink to libstdc++ in /usr/lib.

On second thought, that is pointless because gcc-config modifies /etc/env.d, which tells the dynamic linker where to find libstdc++.

I have written a patch that adds runtime detection of the correct GCC version. The patch also adds hooks to Clang's distribution detection so that it can explicitly detect Gentoo. That is pointless right now, but I wrote that with the intention of sending it upstream.

voyageur, let me know if it is okay to commit this to portage.
Comment 10 Richard Yao (RETIRED) gentoo-dev 2012-05-23 18:59:39 UTC
(In reply to comment #9)
> voyageur, let me know if it is okay to commit this to portage.

Disregard that comment. I missed a regression. This needs a bit more work before it can be committed to the tree.
Comment 11 Richard Yao (RETIRED) gentoo-dev 2012-05-23 19:46:05 UTC
Created attachment 312871 [details, diff]
Patch proposal that adds runtime detection of correct GCC version

I have attached a proper patch to address this. This one applies against clang 3.0 and works well in my testing. With a GCC 4.5-built LLVM and Clang, I can do `gcc-config gcc-config x86_64-pc-linux-gnu-4.5.3` and `gcc-config x86_64-pc-linux-gnu-4.6.3` to switch back and forth and `clang -v hello.c` indicates that it is linking to the correct libstdc++ each time.

voyageur, let me know if it is okay to commit this.
Comment 12 Richard Yao (RETIRED) gentoo-dev 2012-05-26 01:40:23 UTC
I have updated my patch for Clang 3.1 and committed it to CVS as part of sys-devel/clang-3.1-r1. My position on 9999 ebuilds is that patches against them should be sent upstream rather than put into the tree, although the decision belongs to the sys-devel/clang maintainers.

Matthias, do you have any particular need for sys-devel/clang-9999? Try sys-devel/clang-3.1-r1 and see if it resolves your problems. If it does, you could always create  the /etc/portage/patches/sys-devel/clang-9999 directory and put copies of my 3.1 patches into it.
Comment 13 PaX Team 2012-05-27 19:11:32 UTC
just FYI, if you want to get patches accepted into llvm/clang then you should post them to llvm-commits/cfe-commits for review (instead of their bugzilla).
Comment 14 Bernard Cafarelli gentoo-dev 2015-10-16 11:16:37 UTC
Cleaning old bugs, this has probably been fixed for some time but I just retested it (switching between my system 4.9.3 and 5.2.0), it got the correct libstdc++ and headers