[llvm-bugs] [Bug 38029] New: Unused code triggers linker failure

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 3 03:56:29 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38029

            Bug ID: 38029
           Summary: Unused code triggers linker failure
           Product: clang
           Version: 6.0
          Hardware: Other
                OS: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: adridg at FreeBSD.org
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

This program fails to link (clang6 on FreeBSD):

```
#include <string> 
static std::string f() { return std::string(); } 
int main() { (void) f; }
```

The error message is

```
/tmp/t-a76eba.o: In function `f()':
t.cpp:(.text+0x20): undefined reference to `std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()'
/usr/bin/ld: a.out: hidden symbol
`_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2Ev' isn't
defined
/usr/bin/ld: final link failed: Nonrepresentable section on output
```

It also fails with clang5 on FreeBSD, on FreeBSDs 11- and 12-, and reportedly
on Linux with clang6 and -stdlib=libc++.

It doesn't fail with -O1 or above. It doesn't fail if you remove the `(void)f;`
statement, although then you will get an unused function warning.

Also reported downstream as
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229479

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180703/c7db46dc/attachment.html>


More information about the llvm-bugs mailing list