Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion '!empty()' failed. #233

Closed
Jark5455 opened this issue May 26, 2024 · 26 comments · Fixed by plasma-umass/libelfin#2
Closed

Assertion '!empty()' failed. #233

Jark5455 opened this issue May 26, 2024 · 26 comments · Fixed by plasma-umass/libelfin#2

Comments

@Jark5455
Copy link

Hello,

Currently, I am trying to use coz, however whenever I run it with ANY application with no flags I get the following error

/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.

How do fix?

@Lanzaa
Copy link

Lanzaa commented Jul 12, 2024

I think this is related to a bug in the libelfin dependency:

aclements/libelfin#63

@Jark5455
Copy link
Author

Jark5455 commented Jul 16, 2024

I applied the patch in the pull request, I am still getting the same error :|

@Lanzaa
Copy link

Lanzaa commented Jul 18, 2024

Odd, I am unable to reproduce the issue. Could you include more details?

Also, I would double check that the patch applied and is being used.

@nicholasdejong
Copy link

Same issue here. I am not well versed in c++ toolchains, so I had some friction patching the fix.

I am on Arch linux kernel version 6.10.3-arch1-1 which meant downloading from the AUR. I changed cursor.cc, ran make install and copied all the libraries and archives produced by make into the tar from aur. Ran makepkg and installed with pacman. Pretty sure I did something wrong, but I wasn't sure what to actually do.

Still getting the same error message: /usr/include/c++/14.2.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.

Will do some digging in coz to see if I can fix it.

@WaviestBalloon
Copy link

Came here to say that I too am also experiencing this issue:

[libcoz.cpp:100] bootstrapping coz
[libcoz.cpp:128] Including MAIN, which is /home/wav/Documents/httpserver/httpserver-benchmark
/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.

Currently on Arch Linux, 6.10.7-zen1-1-zen

@Pspritechologist
Copy link

Ditto, same error. I'm on Manjaro 24.0.8 and I'm trying to run a Rust binary, although that doesn't seem relevant.

@nicholasdejong
Copy link

Ditto, same error. I'm on Manjaro 24.0.8 and I'm trying to run a Rust binary, although that doesn't seem relevant.

Funnily enough, I also tried using coz with Rust, but I doubt that's the problem.

@camelid
Copy link
Contributor

camelid commented Oct 8, 2024

Thanks for the bug reports! Could you provide information about the following?

  • which version of coz you're running -- i.e., the commit if from github or the version number and package index you're using.
  • an MCVE of how to reproduce the crash -- e.g., a C file, a GCC invocation, and a Coz invocation

This would be super helpful with debugging because I'm not getting an assert failure with either github HEAD (b855f59) or the latest apt package (coz 0.2.2-2).

@Pspritechologist
Copy link

Pspritechologist commented Oct 9, 2024

Thanks for the bug reports! Could you provide information about the following?

  • which version of coz you're running -- i.e., the commit if from github or the version number and package index you're using.
  • an MCVE of how to reproduce the crash -- e.g., a C file, a GCC invocation, and a Coz invocation

This would be super helpful with debugging because I'm not getting an assert failure with either github HEAD (b855f59) or the latest apt package (coz 0.2.2-2).

I was using whatever version was on AUR which seems to have not been updated for some time.

I went ahead and cloned from GitHub. Using a version built from that source following the instructions on the repo, I ran coz run --- ./target/debug/<BINARY> after using cargo build to build a Rust file containing only a "Hello, World!" print. I am using a nightly version of the Rust toolchain. That's all the steps I took, I do not have a C file to test with, sorry.

The full output of the program is

[/home/pspritechologist/tempcoz/coz/libcoz/libcoz.cpp:100] bootstrapping coz
[/home/pspritechologist/tempcoz/coz/libcoz/libcoz.cpp:128] Including MAIN, which is /home/pspritechologist/<SRC PATH>/target/debug/<BINARY>
/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.

@camelid
Copy link
Contributor

camelid commented Oct 10, 2024

Thanks for adding some more info. I'm still unable to reproduce this, which makes me wonder if it could be a problem specific to arch or to newer versions of the kernel. I'm on Ubuntu 22.04.1 (kernel 6.5.0-44-generic). Will do some more digging.

@camelid
Copy link
Contributor

camelid commented Oct 10, 2024

Is this happening for anyone on Ubuntu 22? I can't upgrade right now, so I'm not able to check if it's an Ubuntu vs Arch issue, a kernel version issue, or something else entirely.

@greaka
Copy link

greaka commented Oct 11, 2024

I can also reproduce it using the toy.rs example.

Linux 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux
cargo 1.83.0-nightly (80d82ca22 2024-09-27)

Installed via aur coz-git commit 62534a4.

/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.

@jullanggit
Copy link

I have the same issue with the following setup:

Linux 6.11.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 10 Oct 2024 20:11:06 +0000 x86_64 GNU/Linux
cargo 1.83.0-nightly (15fbd2f60 2024-10-08)
coz from coz-git (aur) commit 62534a4

@camelid
Copy link
Contributor

camelid commented Oct 14, 2024

I just setup an arch vm to try to reproduce this, and I still can't. I ran coz on a simple hello-world C file, a simple hello-world Rust crate, and the toy-rs benchmark. All of them worked fine.

Linux archlinux 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux
g++ (GCC) 14.2.1 20240910
cargo 1.81.0 (2dbb1af80 2024-08-20)

coz installed from source (62534a4)

@camelid
Copy link
Contributor

camelid commented Oct 14, 2024

When installing from git, are you following the instructions here? Obviously they need to be adapted to work on arch linux, but when I did, it worked fine. I also had to export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH and export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH for some reason, but that was to fix a cmake config error rather than a coz runtime assert.

@camelid
Copy link
Contributor

camelid commented Oct 14, 2024

Could you go into lldb/gdb and print a backtrace of the assert failure (lldb preferred because usually gives better backtraces)? This is a bit complicated because coz is actually a python script that then loads the coz dylib.

Basically (the (lldb) part is the prompt):

$ lldb ./path/to/benchmark/executable
(lldb) env LD_PRELOAD=/usr/local/lib/libcoz.so
(lldb) env COZ_BINARY_SCOPE=MAIN
(lldb) run
... assert failure printed here ...
(lldb) bt

EDIT: You can also try installing another project from this lab into lldb, which may help with the debugging: https://github.com/plasma-umass/ChatDBG

@Pspritechologist
Copy link

Does this seem to be the output you would expect?

[/<HOME_DIR>/coz/libcoz/libcoz.cpp:100] bootstrapping coz
[/<HOME_DIR>/coz/libcoz/libcoz.cpp:128] Including MAIN, which is /<HOME_DIR>/rust_test/target/debug/rust_test
/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.
Process 39127 stopped
* thread #1, name = 'rust_test', stop reason = signal SIGABRT
    frame #0: 0x00007ffff7d1d3f4 libc.so.6`___lldb_unnamed_symbol3669 + 276
libc.so.6`___lldb_unnamed_symbol3669:
->  0x7ffff7d1d3f4 <+276>: movl   %eax, %ebx
    0x7ffff7d1d3f6 <+278>: negl   %ebx
    0x7ffff7d1d3f8 <+280>: cmpl   $0xfffff000, %eax ; imm = 0xFFFFF000 
    0x7ffff7d1d3fd <+285>: movl   $0x0, %eax

Just let me know if I need to run it differently.

@jullanggit
Copy link

I got the following with one of my small projects:

❯ lldb target/coz/poker_bot
(lldb) target create "target/coz/poker_bot"
Current executable set to '/home/julius/.config/rebos/files/common/home/julius/Code/rust/poker_bot/target/coz/poker_bot' (x86_64).
(lldb) env LD_PRELOAD=/usr/local/lib/libcoz.so
(lldb) env COZ_BINARY_SCOPE=MAIN
(lldb)
(lldb) run
Process 159563 launched: '/home/julius/.config/rebos/files/common/home/julius/Code/rust/poker_bot/target/coz/poker_bot' (x86_64)
[/home/julius/coz/libcoz/libcoz.cpp:100] bootstrapping coz
[/home/julius/coz/libcoz/libcoz.cpp:128] Including MAIN, which is /home/julius/.config/rebos/files/common/home/julius/Code/rust/poker_bot/target/coz/poker_bot
/usr/include/c++/14.1.1/bits/basic_string.h:1328: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::front() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&]: Assertion '!empty()' failed.
Process 159563 stopped
* thread #1, name = 'poker_bot', stop reason = signal SIGABRT
    frame #0: 0x00007ffff7d923f4 libc.so.6`___lldb_unnamed_symbol3669 + 276
libc.so.6`___lldb_unnamed_symbol3669:
->  0x7ffff7d923f4 <+276>: movl   %eax, %ebx
    0x7ffff7d923f6 <+278>: negl   %ebx
    0x7ffff7d923f8 <+280>: cmpl   $0xfffff000, %eax ; imm = 0xFFFFF000
    0x7ffff7d923fd <+285>: movl   $0x0, %eax
(lldb) bt
* thread #1, name = 'poker_bot', stop reason = signal SIGABRT
  * frame #0: 0x00007ffff7d923f4 libc.so.6`___lldb_unnamed_symbol3669 + 276
    frame #1: 0x00007ffff7d39120 libc.so.6`raise + 32
    frame #2: 0x00007ffff7d204c3 libc.so.6`abort + 223
    frame #3: 0x00007ffff7ad3af0 libstdc++.so.6`std::__glibcxx_assert_fail(file=<unavailable>, line=<unavailable>, function=<unavailable>, condition=<unavailable>) at assert_fail.cc:41:10
    frame #4: 0x00007ffff7cdaf50 libdwarf++.so.0`dwarf::cursor::string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) + 144
    frame #5: 0x00007ffff7cec714 libdwarf++.so.0`dwarf::line_table::line_table(std::shared_ptr<dwarf::section> const&, unsigned long, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) + 2212
    frame #6: 0x00007ffff7ce5944 libdwarf++.so.0`dwarf::compilation_unit::get_line_table() const + 388
    frame #7: 0x00007ffff7f5686a libcoz.so`memory_map::process_file(this=<unavailable>, name=<unavailable>, load_address=<unavailable>, source_scope=<unavailable>) at inspect.cpp:487:48
    frame #8: 0x00007ffff7f59684 libcoz.so`memory_map::build(this=0x0000000000000000, binary_scope=size=0, source_scope=size=0) at inspect.cpp:315:24
    frame #9: 0x00007ffff7f5f333 libcoz.so`wrapped_main(argc=0, argv=0x00007ffff7ffd000, env=0x000055555569a848) at libcoz.cpp:175:13
    frame #10: 0x00007ffff7d21ecc libc.so.6`__libc_start_main + 140
    frame #11: 0x0000555555590025 poker_bot`_start + 37 

@camelid
Copy link
Contributor

camelid commented Oct 16, 2024

Thank you so much! This indicates a bug in the libelfin dependency (that's what libdwarf++ is). Essentially, it calls string::front() on an empty string, which causes an assert failure only when assertions are enabled. They are apparently enabled by default on Arch but not other architectures. I will create a patched version of libelfin soon.

@jullanggit
Copy link

Thanks!

@camelid
Copy link
Contributor

camelid commented Oct 16, 2024

Ok, can you try applying this PR's patch to your local libelfin clone? plasma-umass/libelfin#2

Make sure to re-make and make install both libelfin and Coz afterward.

@jullanggit
Copy link

Mabe its something on my side, but i get this error when compiling:

cursor.cc: In member function ‘void dwarf::cursor::string(std::string&)’:
cursor.cc:95:27: error: lvalue required as unary ‘&’ operand
   95 |         memmove(&out.c_str(), p, size);
      |                  ~~~~~~~~~^~

@jullanggit
Copy link

Chatgpt suggested changing the line to memmove(&out[0], p, size);, which compiles and, as far as I can tell, works!

@camelid
Copy link
Contributor

camelid commented Oct 22, 2024

Whoops, sorry about that. It's actually probably simplest to just guard the original front() call by a condition checking for an empty string. C++ has some weird version-specific behavior around null-termination and thus safety of dereferencing pointers to empty strings.

@jullanggit can you try this updated version of the PR? plasma-umass/libelfin#2

@jullanggit
Copy link

I tried it and, as far as I can tell, it works! Thanks!

@camelid
Copy link
Contributor

camelid commented Oct 23, 2024

Awesome! Thanks for your help with the debugging.

camelid added a commit to camelid/coz that referenced this issue Oct 23, 2024
For now, this gives us more control over fixing bugs like plasma-umass#233.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants