Reputation: 11
The following code executes fine when compiled using GLIBC (g++ on Ubuntu 18.04). But when cross-compiling with a buildroot toolchain that uses uclibc with C++ support (g++), the result is a segmentation fault. Inspection of the core dump indicates an uncaught exception occurred.
I can't figure out why the uncaught exception and segfault occur. Any thoughts?
# aarch64 qemu environment
./helloworld
Main entry.
Error trySegmentation fault
ulimit -c unlimited
./hellworold
Main entry.
Error trySegmentation fault (core dumped)
gdb -c core helloworld
# Core was generated by `helloworld'.
# Program terminated with signal SIGSEGV, Segmentation fault.
# #0 std::uncaught_exception ()
# at ../../../../libstdc++-v3/libsupc++/eh_catch.cc:141
//main.cpp
#include <iostream>
int main()
{
printf("\nMain entry.\n");
try {
std::cerr << "Error try" << std::endl;
}
catch (...) {
std::cout << "Error catch" << std::endl;
}
return 0;
}
# Makefile for main.cpp
CXX ?= g++
SOURCE_DIR += .
SOURCES += $(wildcard $(addsuffix /*.cpp, $(SOURCE_DIR)))
OBJECTS += $(patsubst %.cpp, %.o, $(SOURCES))
BIN := helloworld
CXXFLAGS += -std=c++11 -ggdb -g3
.PHONY: all clean
all: $(BIN)
$(OBJECTS): %.o: %.cpp
@echo "CXX" $(CXX)
@echo $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OBJECTS) $(LDFLAGS) $(LIBS)
@echo [CXX] -c $< -o $@
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BIN): $(OBJECTS)
@echo [LD] $(OBJECTS) $(LIBS) -o $@
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
clean:
rm -f a.out helloworld
rm -f *.o
Update:
It's possible this a uClibc-ng bug: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=106581
Statically linking with libstdc++ as mentioned resulted in correct behavior, no segfault.
Version info: uclibc-ng 1.0.41 gcc version 11.3.0
Upvotes: 1
Views: 196