2

I'm stuck and can use a fresh pair of eyes.

I have a relatively simple Linux program that I have cross compiled for a Variscite OMAP4 development board using the CodeSourcery tool chain. The program simply creates a thread, waits for the thread to finish, and exists. The thread just outputs a few strings with sleeps in between.

My problem is that the program segmentation faults in the thread right after the thread is created. The backtrace is suggesting that that crash occurred in a standard shared library. GDB can tell me the libraries that are loaded by not the address of the loaded .so files so I have no idea which library is crashing and the offset into the library.

The code, build output, program output, and GDB output is below.

Anyone have ideas of things to check to help get to the root cause?

MyMain.cpp

#include <thread>
#include <iostream>
using namespace std;

void MyThreadStart ();

int main ()
{
  cout << "main started." << endl;
  std::thread t2 (&MyThreadStart);
  cout << "thread CTOR invokved." << endl;
  t2.join();
  cout << "thread join completed." << endl;
  return 0;
}

MyThread.cpp

#include <iostream>
using namespace std;
#ifdef __cplusplus
extern "C" {
#include <unistd.h>
}
#endif

void MyThreadStart ()
{
  cout << "thread started." << endl;
  int loops = 3;
  while (loops--)
  {
    cout << "thread going to sleep." << endl;
    sleep (2);
    cout << "thread woke up." << endl;
    sleep (1);
  }
}

Make output

16:51:39 **** Build of configuration Debug for project SegFaultTest ****
make all
Building file: ../MyMain.cpp
Invoking: ARM Sourcery Linux GCC C++ Compiler
arm-none-eabi-g++ -nostdinc -nostdinc++ -I/opt/arm/arm-none-linux-gnueabi/libc/usr/include -I/opt/arm/lib/gcc/arm-none-linux-gnueabi/4.7.2/include -I/opt/arm/arm-none-linux-gnueabi/include/c++/4.7.2 -I/opt/arm/arm-none-linux-gnueabi/include/c++/4.7.2/arm-none-linux-gnueabi -O0 -Wall -Wa,-adhlns="MyMain.o.lst" -fno-exceptions -fno-rtti -c -fmessage-length=0 -std=c++11  -mno-thumb-interwork -MMD -MP -MF"MyMain.d" -MT"MyMain.d" -mcpu=arm7 -g3 -gdwarf-2 -o "MyMain.o" "../MyMain.cpp"
Finished building: ../MyMain.cpp

Building file: ../MyThread.cpp
Invoking: ARM Sourcery Linux GCC C++ Compiler
arm-none-eabi-g++ -nostdinc -nostdinc++ -I/opt/arm/arm-none-linux-gnueabi/libc/usr/include -I/opt/arm/lib/gcc/arm-none-linux-gnueabi/4.7.2/include -I/opt/arm/arm-none-linux-gnueabi/include/c++/4.7.2 -I/opt/arm/arm-none-linux-gnueabi/include/c++/4.7.2/arm-none-linux-gnueabi -O0 -Wall -Wa,-adhlns="MyThread.o.lst" -fno-exceptions -fno-rtti -c -fmessage-length=0 -std=c++11  -mno-thumb-interwork -MMD -MP -MF"MyThread.d" -MT"MyThread.d" -mcpu=arm7 -g3 -gdwarf-2 -o "MyThread.o" "../MyThread.cpp"
Finished building: ../MyThread.cpp

Building target: SegFaultTest.elf
Invoking: ARM Sourcery Linux GCC C++ Linker
arm-none-eabi-g++ -Wl,-Map,SegFaultTest.map -mcpu=arm7 -g3 -gdwarf-2 -o "SegFaultTest.elf"  ./MyMain.o ./MyThread.o   -lpthread

Finished building target: SegFaultTest.elf

Program Output

$ ./SegFaultTest.elf
main started.
thread CTOR invokved.
Segmentation fault (core dumped)

GDB Output

info shared
From        To          Syms Read   Shared Object Library
                        No          /lib/arm-linux-gnueabihf/libpthread.so.0
                        No          /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
                        No          /lib/arm-linux-gnueabihf/libm.so.6
                        No          /lib/arm-linux-gnueabihf/libgcc_s.so.1
                        No          /lib/arm-linux-gnueabihf/libc.so.6
                        No          /lib/ld-linux.so.3
bt
#0  0xb6f5e3d0 in ?? ()
#1  0xb6fb8ed2 in ?? ()
Backtrace stopped: frame did not save the PC

1 Answer 1

0

After more investigation and experimentation, I determined that the crash occurred due to a defect in the stdc++ library for the Variscite board I am using. I had enabled the 2011 C++ standard extension in my code so I could use the thread class. When the thread constructor is called, the pthread library start_thread function calls some unnown function in the stdc++ library and a crash occurs. I changed my code to not use the 2011 C++ extensions but instead use pthread calls and my simple code then worked. I have informed Variscite of this defect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.