Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 747976 - dev-lang/rust[system-llvm] link against libstdc++ while cc is sys-devel/clang[default-libcxx] and sys-devel/llvm link against libc++
Summary: dev-lang/rust[system-llvm] link against libstdc++ while cc is sys-devel/clang...
Status: RESOLVED DUPLICATE of bug 732632
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Georgy Yakovlev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-12 11:16 UTC by 12101111
Modified: 2020-10-14 03:45 UTC (History)
2 users (show)

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


Attachments
build.log (build.log.gz,45.23 KB, application/gzip)
2020-10-12 11:25 UTC, 12101111
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 12101111 2020-10-12 11:16:21 UTC
This is a glibc system with clang as default c/c++ toolchain.

make.conf
```
CC="clang"
CXX="clang++"
CPP="clang-cpp"
AR="llvm-ar"
NM="llvm-nm"
OBJCOPY="llvm-objcopy"
OBJDUMP="llvm-objdump"
RANLIB="llvm-ranlib"
SIZE="llvm-size"
STRIP="llvm-strip"
COMMON_FLAGS="-march=skylake -mtune=skylake -O3 -pipe -falign-functions=32 \
-fomit-frame-pointer -ffunction-sections -fdata-sections -flto=thin"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"# -stdlib=libc++"
FCFLAGS="-march=skylake -mtune=skylake -O3"
FFLAGS="-march=skylake -mtune=skylake -O3"
RUSTFLAGS="-Ctarget-cpu=skylake -Copt-level=3 -Ccodegen-units=4 \
-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld -Clink-arg=-flto=thin"
LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind \
-flto=thin -Wl,-O3 -Wl,--gc-sections -march=skylake -mtune=skylake"
```

I install sys-devel/clang-11 with USE="default-compiler-rt default-libcxx default-lld static-analyzer xml", sys-devel/llvm and other llvm staff.
The rebuilding of rust failed with this linking error:

```
sysroot: "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot"
libdir: "/usr/lib/rust/1.47.0/lib"
error: linking with `clang` failed: exit code: 1
  |
  = note: "clang" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219.rustc_binary.53812iwz-cgu.0.rcgu.o" "-o" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/psm-be028d5b57a4efec/out" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/rustc_llvm-8406bf9006ffd1b9/out" "-L" "/usr/lib/llvm/11/lib64" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps" "-lrustc_driver-497d262276e3cbe4" "-Wl,--start-group" "-L" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-c61a15ffdfb83381" "-Wl,--end-group" "-Wl,-Bstatic" "/tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d8fe22de1dd5bc9c.rlib" "-Wl,-Bdynamic" "-lLLVM-11libcxx" "-lstdc++" "-lutil" "-ldl" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::error_code::message() const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__vector_base_common<true>::__throw_length_error() const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__basic_string_common<true>::__throw_length_error() const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__next_prime(unsigned long) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::system_category() [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__shared_weak_count::__release_weak() [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::locale::use_facet(std::__1::locale::id&) const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::ios_base::getloc() const [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::push_back(char) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush() [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry() [--no-allow-shlib-undefined]
          x86_64-pc-linux-gnu-ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
          clang-11: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error
```

So the build script try to link libstdc++ and failed.

In /compiler/rustc_llvm/build.rs:
```
    let llvm_use_libcxx = tracked_env_var_os("LLVM_USE_LIBCXX");

    let stdcppname = if target.contains("openbsd") {
        if target.contains("sparc64") { "estdc++" } else { "c++" }
    } else if target.contains("freebsd") {
        "c++"
    } else if target.contains("darwin") {
        "c++"
    } else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
        // NetBSD uses a separate library when relocation is required
        "stdc++_pic"
    } else if llvm_use_libcxx.is_some() {
        "c++"
    } else {
        "stdc++"
    };

    // RISC-V requires libatomic for sub-word atomic operations
    if target.starts_with("riscv") {
        println!("cargo:rustc-link-lib=atomic");
    }

    // C++ runtime library
    if !target.contains("msvc") {
        if let Some(s) = llvm_static_stdcpp {
            assert!(!cxxflags.contains("stdlib=libc++"));
            let path = PathBuf::from(s);
            println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
            if target.contains("windows") {
                println!("cargo:rustc-link-lib=static-nobundle={}", stdcppname);
            } else {
                println!("cargo:rustc-link-lib=static={}", stdcppname);
            }
        } else if cxxflags.contains("stdlib=libc++") {
            println!("cargo:rustc-link-lib=c++");
        } else {
            println!("cargo:rustc-link-lib={}", stdcppname);
        }
    }
```

The build script will link to libc++ when 1. LLVM_USE_LIBCXX is set or 2. CXXFLAGS contains -stdlib=libc++

In most time the CXXFLAGS=-stdlib=libc++ is redundant as USE=default-libcxx is set, and may cause problems 
when some package set -Wall and clang will warn option -stdlib=libc++ is unused.

So rust ebuild should set LLVM_USE_LIBCXX=1 when sys-devel/llvm is link against libcxx.



Reproducible: Always

Steps to Reproduce:
1.install sys-devel/clang[default-libcxx]
2.build llvm against libcxx
3.build dev-lang/rust[system-llvm] without set CXXFLAGS=-stdlib=libc++
Comment 1 12101111 2020-10-12 11:17:50 UTC
Portage 3.0.8 (python 3.9.0-final-0, default/linux/amd64/17.1, gcc-10.2.0, glibc-2.32-r2, 5.8.14-zen+ x86_64)
=================================================================
System uname: Linux-5.8.14-zen+-x86_64-Intel-R-_Core-TM-_i7-10810U_CPU_@_1.10GHz-with-glibc2.32
KiB Mem:    24190632 total,  10341416 free
KiB Swap:   25223160 total,  23855608 free
Timestamp of repository gentoo: Mon, 12 Oct 2020 02:35:11 +0000
Head commit of repository gentoo: ecb5362e420d65344ae6806d7db9afa46b663cdc

Timestamp of repository FireBurn: Mon, 12 Oct 2020 00:35:02 +0000
Head commit of repository FireBurn: 39e2e0a80e63e406c3afc085fceb32de3361154c

Timestamp of repository gentoo-zh: Sat, 10 Oct 2020 18:05:12 +0000
Head commit of repository gentoo-zh: 6fc850c0af70b9b18cab5de47730b53841e29f83

Timestamp of repository guru: Sun, 11 Oct 2020 15:05:05 +0000
Head commit of repository guru: 459475c193509691b078af25f72d2ca25b736af8

Timestamp of repository jorgicio: Sun, 11 Oct 2020 23:05:14 +0000
Head commit of repository jorgicio: c38916352b4048a6a08b84826e1ddb50fe20bf14

Head commit of repository kwin-lowlatency-overlay: f737f5793d4333171f289e58dbed75c3babad6b1

Timestamp of repository lanodanOverlay: Fri, 09 Oct 2020 19:35:07 +0000
Head commit of repository lanodanOverlay: 6c2860efdf427ae6730140678cbca491e00bbc90

Timestamp of repository lto-overlay: Tue, 06 Oct 2020 13:35:21 +0000
Head commit of repository lto-overlay: 3e7a867b0a18b943dd7a84995aa3b5c96513305d

Timestamp of repository mv: Sat, 10 Oct 2020 09:05:05 +0000
Head commit of repository mv: 54a4cde6b159b52efb8fd6abdafa7958a9806afc

Timestamp of repository pg_overlay: Sun, 11 Oct 2020 19:35:03 +0000
Head commit of repository pg_overlay: 2789ebf8ba0913fe94e1fcd01dc667cbafe1dfd5

Timestamp of repository sorrow: Mon, 21 Sep 2020 17:35:18 +0000
Head commit of repository sorrow: c13110c3d2785f7d10cfd6ea871312f48dc5d70c

Timestamp of repository tgbugs-overlay: Fri, 09 Oct 2020 19:35:07 +0000
Head commit of repository tgbugs-overlay: 6371f62b77e06f561fbf607b1e3e3848ca02247a

sh bash 5.0_p18
ld LLD 11.0.0 (compatible with GNU linkers)
distcc[19058] (dcc_mkdir) ERROR: mkdir '/tmp/portage/.distcc/state' failed: No such file or directory [disabled]
ccache version 3.7.12 [enabled]
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::gentoo
dev-lang/perl:            5.30.3-r1::gentoo
dev-lang/python:          2.7.18-r100::lto-overlay, 3.8.6-r1::lto-overlay, 3.9.0-r1::lto-overlay
dev-util/ccache:          3.7.12::gentoo
dev-util/cmake:           3.18.4::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/openrc:          0.42.1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.2::gentoo
sys-devel/binutils:       2.35.1::gentoo
sys-devel/gcc:            10.2.0-r2::gentoo
sys-devel/gcc-config:     2.3.2::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.8::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r2::gentoo
Repositories:

gentoo
    location: /usr/portage/gentoo
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/gentoo
    priority: -1000

12101111-overlay
    location: /usr/portage/local
    masters: gentoo

FireBurn
    location: /usr/portage/FireBurn
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/FireBurn.git
    masters: gentoo

gentoo-zh
    location: /usr/portage/gentoo-zh
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/gentoo-zh.git
    masters: gentoo

guru
    location: /usr/portage/guru
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/guru.git
    masters: gentoo

jorgicio
    location: /usr/portage/jorgicio
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/jorgicio.git
    masters: gentoo

kwin-lowlatency-overlay
    location: /usr/portage/kwin-lowlatency-overlay
    sync-type: git
    sync-uri: https://github.com/agates/kwin-lowlatency-overlay.git
    masters: gentoo

lanodanOverlay
    location: /usr/portage/lanodanOverlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/lanodanOverlay.git
    masters: gentoo

lto-overlay
    location: /usr/portage/lto-overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/lto-overlay.git
    masters: gentoo mv

mv
    location: /usr/portage/mv
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/mv.git
    masters: gentoo

pg_overlay
    location: /usr/portage/pg_overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/pg_overlay.git
    masters: gentoo

sorrow
    location: /usr/portage/sorrow
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/sorrow.git
    masters: gentoo

tgbugs-overlay
    location: /usr/portage/tgbugs-overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/tgbugs-overlay.git
    masters: gentoo

Installed sets: @fcitx5, @qv2ray
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE @BINARY-REDISTRIBUTABLE"
CBUILD="x86_64-pc-linux-gnu"
CC="clang"
CFLAGS="-march=skylake -mtune=skylake -O3 -pipe -falign-functions=32 -fomit-frame-pointer -ffunction-sections -fdata-sections -flto=thin"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXX="clang++"
CXXFLAGS="-march=skylake -mtune=skylake -O3 -pipe -falign-functions=32 -fomit-frame-pointer -ffunction-sections -fdata-sections -flto=thin -stdlib=libc++"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-march=skylake -mtune=skylake -O3"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg ccache config-protect-if-modified distlocks downgrade-backup ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=skylake -mtune=skylake -O3"
GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo"
LANG="zh_CN.UTF-8"
LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -flto=thin -Wl,-O3 -Wl,--gc-sections -march=skylake -mtune=skylake"
MAKEOPTS="-j12"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X acl alsa amd64 bluetooth bzip2 clang cli compiler-rt crypt cups dbus default-compiler-rt default-libcxx default-lld dri elogind eselect-ldso fortran gdbm gif iconv ipv6 jpeg libcxx libcxxabi libglvnd libtirpc libunwind lto luajit lz4 multilib ncurses networkmanager nls nptl opengl openmp pam pcre pgo png policykit polkit pulseaudio readline seccomp split-usr ssl svg tcpd unicode vaapi vulkan wayland xattr zlib zsh-completion" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel usb-audio" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd 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="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="zh-CN" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="X86 ARM AArch64 RISCV WebAssembly AMDGPU BPF" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_9" PYTHON_TARGETS="python3_9" QEMU_SOFTMMU_TARGETS="arm aarch64 i386 x86_64 riscv32 riscv64" QEMU_USER_TARGETS="arm aarch64" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="intel i965 iris amdgpu radeonsi radeon" 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, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 12101111 2020-10-12 11:25:54 UTC
Created attachment 664858 [details]
build.log
Comment 3 12101111 2020-10-12 11:28:27 UTC
It seems CXXFLAGS=-libc++ don't work as the build.log shows.
Comment 4 12101111 2020-10-12 11:39:39 UTC
I manually execute the link command

```
clang -Wl,--as-needed -Wl,-z,noexecstack -m64 -Wl,--eh-frame-hdr -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219.rustc_binary.53812iwz-cgu.0.rcgu.o -o /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219 -Wl,--gc-sections -pie -Wl,-zrelro -Wl,-znow -Wl,-O1 -nodefaultlibs -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/psm-be028d5b57a4efec/out -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/rustc_llvm-8406bf9006ffd1b9/out -L /usr/lib/llvm/11/lib64 -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -lrustc_driver-497d262276e3cbe4 -Wl,--start-group -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib -lstd-c61a15ffdfb83381 -Wl,--end-group -Wl,-Bstatic /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d8fe22de1dd5bc9c.rlib -Wl,-Bdynamic -lLLVM-11libcxx -lstdc++ -lutil -ldl -lutil -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -ldl -lutil
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::error_code::message() const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__vector_base_common<true>::__throw_length_error() const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__basic_string_common<true>::__throw_length_error() const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__next_prime(unsigned long) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::system_category() [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::__shared_weak_count::__release_weak() [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::locale::use_facet(std::__1::locale::id&) const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::ios_base::getloc() const [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::push_back(char) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush() [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-497d262276e3cbe4.so: undefined reference to std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry() [--no-allow-shlib-undefined]
x86_64-pc-linux-gnu-ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
```

And without the `-lstdc++`: 
```
# clang -Wl,--as-needed -Wl,-z,noexecstack -m64 -Wl,--eh-frame-hdr -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219.rustc_binary.53812iwz-cgu.0.rcgu.o -o /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219 -Wl,--gc-sections -pie -Wl,-zrelro -Wl,-znow -Wl,-O1 -nodefaultlibs -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/psm-be028d5b57a4efec/out -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/rustc_llvm-8406bf9006ffd1b9/out -L /usr/lib/llvm/11/lib64 -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -lrustc_driver-497d262276e3cbe4 -Wl,--start-group -L /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib -lstd-c61a15ffdfb83381 -Wl,--end-group -Wl,-Bstatic /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d8fe22de1dd5bc9c.rlib -Wl,-Bdynamic -lLLVM-11libcxx -lutil -ldl -lutil -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -ldl -lutil
# ldd /tmp/portage/dev-lang/rust-1.47.0/work/rustc-1.47.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_binary-d4fd69a791712219
	linux-vdso.so.1 (0x00007ffe9a5d7000)
	librustc_driver-497d262276e3cbe4.so => not found
	libstd-c61a15ffdfb83381.so => not found
	libc.so.6 => /lib64/libc.so.6 (0x00007f8488dc5000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f8488fac000)
```
It works without `-lstdc++`.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-10-13 00:46:59 UTC
I feel like we've seen this before, but I can't find the bug.
Comment 6 Georgy Yakovlev archtester gentoo-dev 2020-10-13 03:33:34 UTC
yeah I also remember someone digging it but can't remember the name.

rust has a knob to use libcxx, unsurprisingly it's called

use-libcxx = true

and can be set in config.toml (src_configure phase)


if you figure out how to use it - patches welcome.
however I will be unable to test it as I don't have such system and unlikely to setup/maintain one for testing.
Comment 7 12101111 2020-10-14 03:45:09 UTC
It seems there is already an open bug for this. Close this.

*** This bug has been marked as a duplicate of bug 732632 ***