<div dir="ltr">This is a by-product of libc++'s use of __attribute__((always_inline, visibility("hidden"))) on string::size (and many other functions).<div><br></div><div>std::string is externally instantiated in the dylib, this causes functions like `string::size` to have a dylib definition.</div><div>Unfortunately this definition has hidden visibility which causes linker failures when an out-of-line reference to `string::size` is generated.</div><div><br></div><div>This behavior should eventually be fixed for QoI reasons, even though the standard forbids taking the address of a member function.</div><div><br></div><div>/Eric</div><div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 21, 2017 at 9:54 AM, David Blaikie via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">FWIW the C++ standard doesn't allow taking the address of standard library member functions (I don't know the wording - but I can go hunt for it), so far as I understand.<br><br>That said, interesting failure - not what I'd have expected.</div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 20, 2017 at 10:45 PM Adam C. Emerson via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello. I'm not sure if this is a bug or if I'm using undefined<br>
behavior or otherwise doing something screwy.<br>
<br>
My Minimal Working Reproducer is:<br>
<br>
---------->8-----------<br>
<br>
#include <functional><br>
#include <iostream><br>
#include <string><br>
<br>
int main(void) {<br>
    auto s = ::std::string("Meow.");<br>
    auto l = ::std::mem_fn(&::std::string::<wbr>size);<br>
<br>
    ::std::cout << l(s) << ::std::endl;<br>
<br>
    return 0;<br>
}<br>
<br>
---------->8-----------<br>
<br>
If I compile this under g++ or with clang++ using libstdc++, this<br>
compiles and works as expected. However, if I use clang++ (v4.0.0 on<br>
Arch Linux x86_64) with libc++ (4.0.0), I get a link error:<br>
<br>
---------->8-----------<br>
<br>
% clang++ -v -std=c++14 -stdlib=libc++ foo.cc<br>
clang version 4.0.0 (tags/RELEASE_400/final)<br>
Target: x86_64-unknown-linux-gnu<br>
Thread model: posix<br>
InstalledDir: /usr/bin<br>
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-<wbr>linux-gnu/6.3.1<br>
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1<br>
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-<wbr>gnu/6.3.1<br>
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-<wbr>linux-gnu/6.3.1<br>
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1<br>
Candidate multilib: .;@m64<br>
Candidate multilib: 32;@m32<br>
Selected multilib: .;@m64<br>
 "/usr/bin/clang-4.0" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name foo.cc -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/4.0.0 -internal-isystem /usr/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/4.0.0/<wbr>include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/azure -ferror-limit 19 -fmessage-length 119 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/foo-1fe78b.o -x c++ foo.cc<br>
clang -cc1 version 4.0.0 based upon LLVM 4.0.0 default target x86_64-unknown-linux-gnu<br>
ignoring nonexistent directory "/include"<br>
#include "..." search starts here:<br>
#include <...> search starts here:<br>
 /usr/bin/../include/c++/v1<br>
 /usr/local/include<br>
 /usr/bin/../lib/clang/4.0.0/<wbr>include<br>
 /usr/include<br>
End of search list.<br>
 "/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1/../../../..<wbr>/lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1/../../../..<wbr>/lib64/crti.o /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1/crtbegin.o -L/usr/bin/../lib64/gcc/x86_<wbr>64-pc-linux-gnu/6.3.1 -L/usr/bin/../lib64/gcc/x86_<wbr>64-pc-linux-gnu/6.3.1/../../..<wbr>/../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_<wbr>64-pc-linux-gnu/6.3.1/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/foo-1fe78b.o -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1/crtend.o /usr/bin/../lib64/gcc/x86_64-<wbr>pc-linux-gnu/6.3.1/../../../..<wbr>/lib64/crtn.o<br>
/tmp/foo-1fe78b.o: In function `main':<br>
foo.cc:(.text+0x44d): undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::size() const'<br>
/usr/bin/ld: a.out: hidden symbol `_ZNKSt3__112basic_stringIcNS_<wbr>11char_traitsIcEENS_<wbr>9allocatorIcEEE4sizeEv' isn't defined<br>
/usr/bin/ld: final link failed: Bad value<br>
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)<br>
<br>
---------->8-----------<br>
<br>
Thank you very much.<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>