mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support
BSD 2-Clause "Simplified" License
734 stars 120 forks source link

On ARM: pure virtual method called #134

Closed thorstink closed 4 years ago

thorstink commented 4 years ago

Hi, first of all, thanks for your fun library!

I have a minimal working example that works on my x86 laptop, but run-time crashes on a raspberry pi. Also, if I change the construction of the server-object, I can make it run on a pi.. but I'd not expect this behaviour nor can explain it.. Maybe it is a bug?

I compiled Seasocks (most recent master) and the program on the (same) pi (version 4). I can try to get more detailed information if you instruct me how to gather them / or what you want to know :-)

I am using g++ (Raspbian 8.3.0-6+rpi1) 8.3.0.. I am building using cmake, using:

target_link_libraries(app seasocks)

Failing source:

#include <seasocks/PrintfLogger.h>
#include <seasocks/Server.h>

using namespace seasocks;

int main() { 
  Server server(std::make_shared<PrintfLogger>());        
  server.serve("ui", 2222);
}

results in (on pi, runs fine on x86)

pure virtual method called
terminate called without an active exception
Aborted

However, changing to

#include <seasocks/PrintfLogger.h>
#include <seasocks/Server.h>

using namespace seasocks;

int main() {
  auto logger = std::make_shared<PrintfLogger>();
  Server server(logger); 
  server.serve("ui", 2222);
}

works just fine on pi and x86...

info: Serving content from ui
info: Listening on http://raspberrypi:2222/
thorstink commented 4 years ago

Addition.. Ok, I am probably doing something else wrong.

Running the server and visiting it also results in a crash:

info: Serving content from ui
info: Listening on http://raspberrypi:2222/
info: 192.168.1.13:45594 : Accepted on descriptor 6
pure virtual method called
terminate called without an active exception
Aborted

and running one of the examples works fine.. hmm

thorstink commented 4 years ago

Additional info; It's getting weirder.

I try to combine it with another library, GTSAM, which as Seasocks gives this nice CMake auto-stuff that I only need to do: target_link_libraries(app seasocks gtsam)

However, target_link_libraries(app seasocks gtsam) -> pure virtual method called target_link_libraries(app gtsam seasocks) -> malloc(): unsorted double linked list corrupted target_link_libraries(app seasocks) -> works target_link_libraries(app gtsam) -> works

I'm not sure if gtsam or seasocks is messing up?

offa commented 4 years ago

But it still fails with your minimal example (without gtsam)? Do you link the static library or the SO version?

Have you way to get a backtrace somehow (eg. coredump or running it from gdb and us bt after crash)?

thorstink commented 4 years ago

The minimal example without gtsam works.

Compiling using g++ main.cc -lseasocks -lgtsam also results in a running executable / working server.

As far as I know I am linking both libraries' SO's.

I am going to reproduce the things I mentioned before and see if I can get a meaningful backtrace. I'll also take a closer look at the cmake output.. because it seems there's something fishy going on there. I hope I can do that tomorrow evening.

edit

I see my own contradiction in the first post, I'll verify tomorrow.. The reason I initially opened this request because it failed without gtsam at all.

edit

If I remember what I did yesterday, linking against seasocks gives the error, linking against Seasocks::seasocks didnt?!

offa commented 4 years ago

If I remember what I did yesterday, linking against seasocks gives the error, linking against Seasocks::seasocks didnt?!

Can you check if whether both link the same version or one the so / static library?

Seasock itself links some additional dependencies (threads, and optinal zlib). Do you build both version with cmake? If so, do you search properly for he library using find_package(...)?

thorstink commented 4 years ago

Hi, sorry for the long wait. I was a bit slowed by a flu.

I just spend a few minutes on it and noticed that GTSAM exports some flags; most importantly, -march=native (which is, optionally, used in GTSAM for performance reasons).

Apparently if Seasocks is compiled without -march=native added (which is default) I get either;

malloc(): unsorted double linked list corrupted
Aborted

In case of Release mode, or

pure virtual method called
terminate called without an active exception
Aborted

in debug mode.

However, adding -march=native to the compiler option list in the Seasocks CMakeLists.txt fixed everything!


So, I think this is apparent on ARM and not on x86-64 because the compiler defaults are just different...

So not really a Seasocks bug, but a good to know thing.