Adding keywords for =sys-devel/llvm-3.0 and =sys-devel/clang-3.0 to Gentoo Prefix on x64-macos, installing clang and then compiling a standard Hello World program fails on Mac OS X 10.6: $ clang hello.c clang: error: invalid version number in '-mlinker-version=127.2 (Gentoo binutils-apple-4.2)' Here is my system information: $ emerge --info =sys-devel/clang-3.0 Portage 2.2.01.19941-prefix (prefix/darwin/macos/10.6/x64, gcc-4.2.1, unavailable, 10.6.0 i386) ================================================================= System Settings ================================================================= System uname: Darwin-10.6.0-i386-64bit Timestamp of tree: Fri, 16 Dec 2011 16:10:23 +0000 distcc 3.1 x86_64-apple-darwin10 [disabled] app-shells/bash: 4.2_p10 dev-lang/python: 2.7.2-r3 dev-util/pkgconfig: 0.26 sys-devel/autoconf: 2.68 sys-devel/automake: 1.11.1 sys-devel/gcc-config: 1.5-r2 sys-devel/libtool: 2.4-r4 sys-devel/make: 3.82 Repositories: gentoo_prefix local_overlay Installed sets: ACCEPT_KEYWORDS="~x64-macos" ACCEPT_LICENSE="* -@EULA" CBUILD="x86_64-apple-darwin10" CFLAGS="-march=core2 -mtune=core2 -O2 -pipe" CHOST="x86_64-apple-darwin10" CONFIG_PROTECT="/etc" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/portage /etc/revdep-rebuild /etc/terminfo" CXXFLAGS="-march=core2 -mtune=core2 -O2 -pipe" DISTDIR="/home/stufs1/ryao/Gentoo/usr/portage/distfiles" FEATURES="assume-digests binpkg-logs collision-protect distlocks ebuild-locks fixlafiles force-prefix news nostrip parallel-fetch preserve-libs protect-owned sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch" FFLAGS="" GENTOO_MIRRORS="http://distfiles.gentoo.org" LDFLAGS="-Wl,-dead_strip_dylibs" MAKEOPTS="-j3" PKGDIR="/home/stufs1/ryao/Gentoo/usr/portage/packages" PORTAGE_CONFIGROOT="/home/stufs1/ryao/Gentoo/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/home/stufs1/ryao/Gentoo/usr/portage" PORTDIR_OVERLAY="/home/stufs1/ryao/Gentoo/usr/local/portage" SYNC="rsync://rsync.prefix.freens.org/gentoo-portage-prefix" USE="aqua coreaudio cracklib cxx mmx mmxext modules ncurses nls objc objc++ prefix readline sse sse2 ssl unicode x64-macos zlib" 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="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="Darwin" 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="keyboard mouse" KERNEL="Darwin" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" 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, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS ================================================================= Package Settings ================================================================= sys-devel/clang-3.0 was built with the following: USE="(prefix) static-analyzer system-cxx-headers -debug -multitarget -test"
Invoking the linker directly works: $ clang -c hello.c $ ld hello.o /usr/lib/libSystem.B.dylib /usr/lib/crt1.10.6.o $ ./a.out Hello World Clang will output "clang: error: invalid version number in '-mlinker-version=127.2 (Gentoo binutils-apple-4.2)'" when "err_drv_invalid_version_number" occurs internally. That significantly narrows the code that needs to be examined in order to fix this: $ grep -rn "err_drv_invalid_version_number" /private/var/tmp/portage/sys-devel/clang-3.0/work /private/var/tmp/portage/sys-devel/clang-3.0/work/clang-3.0.src/include/clang/Basic/DiagnosticDriverKinds.td:50:def err_drv_invalid_version_number : Error< /private/var/tmp/portage/sys-devel/clang-3.0/work/clang-3.0.src/lib/Driver/ToolChains.cpp:657: getDriver().Diag(diag::err_drv_invalid_version_number) /private/var/tmp/portage/sys-devel/clang-3.0/work/clang-3.0.src/lib/Driver/ToolChains.cpp:665: getDriver().Diag(diag::err_drv_invalid_version_number) /private/var/tmp/portage/sys-devel/clang-3.0/work/clang-3.0.src/lib/Driver/Tools.cpp:3181: D.Diag(diag::err_drv_invalid_version_number) I probably can patch this myself, but I can't commit to doing it. I hope this information will be useful to anyone with more spare time to work on this.
we need to patch their version lookup code to drop the Gentoo identification string, indeed
Charles, adding you to this bug. I don't have an account for llvm.org bugs. As I believe, the version comes from HOST_LINK_VERSION only (as you suggested in the llvm bug). That one is set using: version_string="$(ld -v 2>&1 | head -1)" # Check for ld64. if (echo "$version_string" | grep -q "ld64"); then llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]* \)#\1#") else llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]* \).*#\1#") fi Which IMO can be then fixed like this: llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\?#\1#") (e.g. removing the trailing " (xxxx)" if present) I'm going to check-in this patch for clang-3.0, perhaps upstream would be interested in the "fix", although it's a problem only on Gentoo setups, of course.
I confirmed the fix myself, got a functioning clang-3.0 now
(In reply to comment #3) > Charles, adding you to this bug. I don't have an account for llvm.org bugs. [...] > I'm going to check-in this patch for clang-3.0, perhaps upstream would be > interested in the "fix", although it's a problem only on Gentoo setups, of > course. OK. I've emailed your patch to the LLVM devs to see if they're interested. If they are, I will commit the patch and resolve LLVM PR8339.
Chris, please let us know if it is committed. :)
There's one slight problem with this patch. It doesn't work quite right with BSD sed (which just so happens to be the sed that comes with Mac OS X): $ version_string=$(/usr/bin/ld -v 2>&1 | head -1) $ echo "$version_string" | /usr/bin/sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\?#\1#" @(#)PROGRAM:ld PROJECT:ld64-127.2 $ echo "$version_string" | $EPREFIX/bin/sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\?#\1#" 127.2 Same for the Gentoo linker: $ version_string=$($EPREFIX/usr/bin/ld -v 2>&1 | head -1) $ echo "$version_string" | /usr/bin/sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\?#\1#" @(#)PROGRAM:ld PROJECT:ld64-127.2 (Gentoo binutils-apple-4.2) $ echo "$version_string" | $EPREFIX/bin/sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\?#\1#" 127.2 The man page for BSD sed(1) says that its REs are, by default, POSIX BREs--or as the re_format(7) page likes to call them, "obsolete" REs. The man page has this to say: "Obsolete ("basic") regular expressions differ in several respects. [...] '+' and '?' are ordinary characters, and their functionality can be expressed using bounds ('{1,}' or '{0,1}' respectively). [...] The delimiters for bounds are '\{' and '\}', with '{' and '}' by themselves ordinary characters." Based on that, I wrote this slightly changed substitution, which works with GNU and BSD sed: "s#.*ld64-\([^ ]*\)\( (.*)\)\{0,1\}#\1#" I've committed the patch as r151612 with this tweak.
ooooh, sorry for my ignorance! Thank you very much for fixing and committing it!