RTTI & Clang: glibc detected
===

The following code fails dramatically with a segfault, any ideas why? I am using the latest Clang (git) with libcxxrt and libunwind on a Fedora 64-bit Linux. There seems to be a problem with `typeid(std::string)` in particular, as this is where the program goes down.

Unfortunately I did not receive any response on the Clang mailing list, any pointers to trace down this bug would thus be greatly appreciated.

    #include <string>
    #include <vector>
    #include <cstddef>
    #include <iostream>
    #include <typeinfo>
    #include <cxxabi.h>
    
    using std::cerr;
    using std::cout;
    using std::endl;
    
    int main()
    {
        std::vector<const std::type_info*> tinfos
            {&typeid(int), &typeid(float), &typeid(std::string), &typeid(char16_t)};
    
        for (auto ptr : tinfos)
        {
            size_t size;
            int status;
            char* undecorated =
                abi::__cxa_demangle(ptr->name(), nullptr, &size, &status);
    
            if (status)
                cerr << "could not demangle type name \"" << ptr->name() << "\"" << endl;
            cout << "\"" << ptr->name() << "\" => \"" << undecorated << "\"" << endl;
            if (undecorated)
                free(undecorated);
        }
    
        return 0;
    }

Here is the abort message:


    "i" => "int"
    "f" => "float"
    "NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE" => "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >"
    *** glibc detected *** ./a.out: free(): invalid next size (fast): 0x0000000000602d10 ***
    ======= Backtrace: =========
    /lib64/libc.so.6[0x3190e7703a]
    /opt/llvm/lib/libcxxrt.so(__cxa_demangle+0xcc)[0x7f26b6f6d4c6]
    ./a.out[0x401392]
    /lib64/libc.so.6(__libc_start_main+0xed)[0x3190e2139d]
    ./a.out[0x400ed9]
    ======= Memory map: ========                                                                                                                                                                      [1/9422]
    00400000-00403000 r-xp 00000000 fd:00 697                                /tmp/a.out
    00602000-00603000 rw-p 00002000 fd:00 697                                /tmp/a.out
    00fba000-00fdb000 rw-p 00000000 00:00 0                                  [heap]
    3190a00000-3190a1f000 r-xp 00000000 fd:00 1054                           /lib64/ld-2.14.so
    3190c1e000-3190c1f000 r--p 0001e000 fd:00 1054                           /lib64/ld-2.14.so
    3190c1f000-3190c20000 rw-p 0001f000 fd:00 1054                           /lib64/ld-2.14.so
    3190c20000-3190c21000 rw-p 00000000 00:00 0 
    3190e00000-3190f8f000 r-xp 00000000 fd:00 1058                           /lib64/libc-2.14.so
    3190f8f000-319118f000 ---p 0018f000 fd:00 1058                           /lib64/libc-2.14.so
    319118f000-3191193000 r--p 0018f000 fd:00 1058                           /lib64/libc-2.14.so
    3191193000-3191194000 rw-p 00193000 fd:00 1058                           /lib64/libc-2.14.so
    3191194000-319119a000 rw-p 00000000 00:00 0 
    3191200000-3191216000 r-xp 00000000 fd:00 1061                           /lib64/libpthread-2.14.so
    3191216000-3191415000 ---p 00016000 fd:00 1061                           /lib64/libpthread-2.14.so
    3191415000-3191416000 r--p 00015000 fd:00 1061                           /lib64/libpthread-2.14.so
    3191416000-3191417000 rw-p 00016000 fd:00 1061                           /lib64/libpthread-2.14.so
    3191417000-319141b000 rw-p 00000000 00:00 0 
    3191600000-3191683000 r-xp 00000000 fd:00 461                            /lib64/libm-2.14.so
    3191683000-3191882000 ---p 00083000 fd:00 461                            /lib64/libm-2.14.so
    3191882000-3191883000 r--p 00082000 fd:00 461                            /lib64/libm-2.14.so
    3191883000-3191884000 rw-p 00083000 fd:00 461                            /lib64/libm-2.14.so
    3191a00000-3191a02000 r-xp 00000000 fd:00 1099                           /lib64/libdl-2.14.so
    3191a02000-3191c02000 ---p 00002000 fd:00 1099                           /lib64/libdl-2.14.so
    3191c02000-3191c03000 r--p 00002000 fd:00 1099                           /lib64/libdl-2.14.so
    3191c03000-3191c04000 rw-p 00003000 fd:00 1099                           /lib64/libdl-2.14.so
    3191e00000-3191e07000 r-xp 00000000 fd:00 1068                           /lib64/librt-2.14.so
    3191e07000-3192006000 ---p 00007000 fd:00 1068                           /lib64/librt-2.14.so
    3192006000-3192007000 r--p 00006000 fd:00 1068                           /lib64/librt-2.14.so
    3192007000-3192008000 rw-p 00007000 fd:00 1068                           /lib64/librt-2.14.so
    3192600000-3192615000 r-xp 00000000 fd:00 1182                           /lib64/libgcc_s-4.6.1-20110908.so.1
    3192615000-3192814000 ---p 00015000 fd:00 1182                           /lib64/libgcc_s-4.6.1-20110908.so.1
    3192814000-3192815000 rw-p 00014000 fd:00 1182                           /lib64/libgcc_s-4.6.1-20110908.so.1
    319aa00000-319aae8000 r-xp 00000000 fd:00 265025                         /usr/lib64/libstdc++.so.6.0.16
    319aae8000-319ace8000 ---p 000e8000 fd:00 265025                         /usr/lib64/libstdc++.so.6.0.16
    319ace8000-319acf0000 r--p 000e8000 fd:00 265025                         /usr/lib64/libstdc++.so.6.0.16
    319acf0000-319acf2000 rw-p 000f0000 fd:00 265025                         /usr/lib64/libstdc++.so.6.0.16
    319acf2000-319ad07000 rw-p 00000000 00:00 0 
    7f26b6c9d000-7f26b6ca3000 rw-p 00000000 00:00 0 
    7f26b6cc0000-7f26b6cc2000 rw-p 00000000 00:00 0 
    7f26b6cc2000-7f26b6d58000 r-xp 00000000 fd:00 24424978                   /opt/llvm/lib/libc++.so.1.0
    7f26b6d58000-7f26b6f58000 ---p 00096000 fd:00 24424978                   /opt/llvm/lib/libc++.so.1.0
    7f26b6f58000-7f26b6f5e000 rw-p 00096000 fd:00 24424978                   /opt/llvm/lib/libc++.so.1.0
    7f26b6f5e000-7f26b6f62000 rw-p 00000000 00:00 0 
    7f26b6f62000-7f26b6f7a000 r-xp 00000000 fd:00 24424979                   /opt/llvm/lib/libcxxrt.so.1.0
    7f26b6f7a000-7f26b7179000 ---p 00018000 fd:00 24424979                   /opt/llvm/lib/libcxxrt.so.1.0
    7f26b7179000-7f26b717b000 rw-p 00017000 fd:00 24424979                   /opt/llvm/lib/libcxxrt.so.1.0
    7f26b717b000-7f26b7180000 rw-p 00000000 00:00 0 
    7fff70cd4000-7fff70cf5000 rw-p 00000000 00:00 0                          [stack]
    7fff70dff000-7fff70e00000 r-xp 00000000 00:00 0                          [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
        
