Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc relocation error at runtime

Tags:

c++

gcc

Currently I'm running some multi-threaded code which all compiles with no errors or warnings and I get this error when I execute the code:

relocation error: /lib/x86_64-linux-gnu/libgcc_s.so.1: 1thread_mutex_locXãƨ+�����Ȩ+ ������ƨ+�&쏭Ũ�Ȩ+e

What is a relocation error?

like image 525
shuttle87 Avatar asked Aug 31 '11 01:08

shuttle87


1 Answers

The relocation is process of adopting some offsets in the code to the actual memory layout. Relocations (places which will be edited by relocation process and the description of each relocation) are generated by compiler, e.g. for TLS variables, for dynamic library calls, for PIC/PIE code. Relocation description is stored in the binary file (e.g. in ELF format in Linux).

Relocations are partially done in linking step, by ld linker program in linux; other linkers in other OSes.

But there are some relocations which can't be done in offline (before starting program). Such relocations are needed to use ASLR (address space layout randomization), to load dynamic libraries. So some of them are done just before starting a program, by the program interpreter, (ld.so in linux), which is also called runtime linker. It will load your program and its dynamic libraries into memory and will do relocations.

Third place where relocations are done: is a call to dlopen() (in libdl.so in unix). It is library to dynamically load dynamic libraries; and because dynamic libraries has relocations, this library should do them too.

The error message is from some linker, and if you see this after starting a program, this is second (ld.so) or third case (libdl).

I can't find exact place where this message is generated, but it is possible due

  • memory or on-disk data corruption (non-ecc memory or other hardware bug), which made some data wrong. Do a reboot; filesystem and md5sums checks; reinstalling of packages which are used (glibc; libgcc); recompile your application; replug you memory, make memory frequency less.
  • some undefined symbol was used. Try to set environment variable LD_BIND_NOW (if you are on glibc or derivative) to non-null.
  • the program corrupted its memory itself. e.g. using the Stack Overflow, or Random Pointer Walk, or something like. Try to use a valgrind (if you are on intel).
  • synchronization error which allows you program to break itself memory. Use valgrind --tool=helgrind (if you are on intel and have a lot of time to wait)
like image 99
osgx Avatar answered Oct 27 '22 00:10

osgx