[libcxx-dev] ifstream destructor crash with unstable ABI

Raul Tambre via libcxx-dev libcxx-dev at lists.llvm.org
Mon Dec 7 02:00:39 PST 2020


I've attached a simple example that can be compiled using `clang++ 
crash.cpp` and will segfault when ran on my x86-64 Linux machine.
The issue does not occur if compiled using optimizations. Presumably the 
destructor call gets optimized away.

I vendor libc++ using the unstable ABI, so commit 
997d41cdec536a0b632505d9b0c4ab5dec5d7d12 
<https://github.com/llvm/llvm-project/commit/997d41cdec536a0b632505d9b0c4ab5dec5d7d12> 
seems suspect.

Has anyone seen this? Any ideas what's wrong?
-------------- next part --------------
#include <fstream>

int main()
{
	std::ifstream in{"/etc/hostname"};
}

-------------- next part --------------
# lldb out
(lldb) target create "out"
Current executable set to '/root/abi/out' (x86_64).
(lldb) r
Process 258435 launched: '/root/abi/out' (x86_64)
Process 258435 stopped
* thread #1, name = 'out', stop reason = signal SIGSEGV: invalid address (fault address: 0x157c)
    frame #0: 0x0000000000202038 out`std::__1::basic_ifstream<char, std::__1::char_traits<char> >::~basic_ifstream() + 8
out`std::__1::basic_ifstream<char, std::__1::char_traits<char> >::~basic_ifstream:
->  0x202038 <+8>:  movq   0x157c, %rsi
    0x202040 <+16>: movq   %rdi, -0x8(%rbp)
    0x202044 <+20>: movq   -0x8(%rbp), %rdi
    0x202048 <+24>: movq   %rdi, -0x10(%rbp)
(lldb) bt
* thread #1, name = 'out', stop reason = signal SIGSEGV: invalid address (fault address: 0x157c)
  * frame #0: 0x0000000000202038 out`std::__1::basic_ifstream<char, std::__1::char_traits<char> >::~basic_ifstream() + 8
    frame #1: 0x0000000000201ed2 out`main + 50
    frame #2: 0x00007ffff7bb4d0a libc.so.6`__libc_start_main + 234
    frame #3: 0x0000000000201e1a out`_start + 42


More information about the libcxx-dev mailing list