Segfault在32位Linux上将64位数字插入字符串流

时间:2019-05-07 12:16:31

标签: linux c++11 32-bit

我有一些代码如下:

uint64_t           now;
std::stringstream  timestamp;

...

    now = GetElapsedTime();
    timestamp << "@" << std::setfill('0') << std::setw(6) << (now / 1000u) << ".";

在64位Windows系统上,它可以编译并正常运行。

在32位Ubuntu Linux系统上,代码可以编译并正常运行,但是随后出现段错误。回溯如下:

#0  0xb7fe132d in check_match (
    undef_name=undef_name@entry=0xb7e53396 "__udivdi3",
    ref=ref@entry=0xb7e1fc70, version=version@entry=0xb7fd2690, flags=1,
    type_class=1, sym=0x401638, symidx=323, strtab=0x401678 "",
    map=0xb7fff940, versioned_sym=0xbfffecc4, num_versions=0xbfffecc0)
    at dl-lookup.c:120
#1  0xb7fe173d in do_lookup_x (
    undef_name=undef_name@entry=0xb7e53396 "__udivdi3",
    new_hash=new_hash@entry=4161312091, old_hash=old_hash@entry=0xbfffed44,
    ref=0xb7e1fc70, result=0xbfffed4c, scope=0xb7fffa9c, i=<optimised out>,
    version=0xb7fd2690, flags=1, skip=0x0, type_class=1, undef_map=0xb7fd1400)
    at dl-lookup.c:406
#2  0xb7fe1f9b in _dl_lookup_symbol_x (undef_name=0xb7e53396 "__udivdi3",
    undef_map=0xb7fd1400, ref=0xbfffedc4, symbol_scope=0xb7fd15b8,
    version=0xb7fd2690, type_class=1, flags=1, skip_map=0x0) at dl-lookup.c:813
#3  0xb7fe6ff8 in _dl_fixup (l=<optimised out>, reloc_arg=<optimised out>)
    at dl-runtime.c:112
#4  0xb7fece20 in _dl_runtime_resolve () at ../sysdeps/i386/dl-trampoline.S:43
#5  0xb7f0a15c in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6  0xb7f0b2fe in std::ostreambuf_iterator<char, std::char_traits<char> > 
    std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >
    ::_M_insert_int<unsigned long long>(std::ostreambuf_iterator<char, 
    std::char_traits<char> >, std::ios_base&, char, unsigned long long) const ()
   from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7  0xb7f0b4b4 in std::num_put<char, std::ostreambuf_iterator<char, 
    std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, 
    std::char_traits<char> >, std::ios_base&, char, unsigned long long) const ()
   from /usr/lib/i386-linux-gnu/libstdc++.so.6
#8  0xb7f17403 in std::ostream& std::ostream::_M_insert<unsigned long long>(unsigned long
    long) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#9  0xb7f17590 in std::ostream::operator<<(unsigned long long) ()
   from /usr/lib/i386-linux-gnu/libstdc++.so.6

猜测,似乎gcc编译器认为<<运算符的重载值为unsigned long long,但是认为它需要动态加载库才能执行。但是,它似乎无法找到该符号。我不确定它是否此时已加载库。

任何人都可以给我一些有关如何解决此问题的建议吗?我尝试将值强制转换为uint32_t并解决了该问题,但这是一个令人讨厌的解决方法。必须有适当的解决方案。

0 个答案:

没有答案