Issue |
152763
|
Summary |
undefined symbol: std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int) when using libcxx with newlib
|
Labels |
libc++
|
Assignees |
|
Reporter |
inglorion
|
On #131921, it was [noted](https://github.com/llvm/llvm-project/pull/131921#issuecomment-2737539434) that the change caused an undefined symbol in some situations. What happens is that `libcxx_static.a` ends up containing a definition of `std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long long, std::__1::ios_base::seekdir, unsigned int)` and a reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int)`. The difference is the type of the first parameter: `long long` vs. `long`.
At link time, this will result in an error such as
```
error: undefined symbol: std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int)
```
with references from `vtable for std::__1::__stdinbuf<char>` and similar.
The difference is caused by these lines in `libcxx/include/__fwd/ios.h`:
```
#if defined(_NEWLIB_VERSION)
// On newlib, off_t is 'long int'
using streamoff = long int; // for char_traits in <string>
#elseusing streamoff = long long; // for char_traits in <string>
#endif
```
On systems with newlib, it is possible to get to this code with or without `_NEWLIB_VERSION` being defined. The inclusion of newlib header files causes `_NEWLIB_VERSION` to be defined, so including libc headers before libcxx headers will cause `_NEWLIB_VERSION` to be defined, resulting in streamoff being `long int`. However, if libcxx headers are included without first including newlib headers, `_NEWLIB_VERSION` will be undefined and streamoff will be `long long`. The inconsistency results in the link error.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs