8

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?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
shuttle87
  • 15,466
  • 11
  • 77
  • 106
  • 1
    How do you compile and link the code? – Kerrek SB Aug 31 '11 at 01:20
  • 2
    Without code this is impossible to diagnose. Make the smallest compilable example that exhibits the problem. – Martin York Aug 31 '11 at 02:43
  • 1
    @Martin, I'm more interested in what the error message itself is as I have never seen it before. I'm fairly sure I have already fixed the problem. – shuttle87 Aug 31 '11 at 02:56
  • 1
    do a reboot and check file system. Compare md5 sums; rebuild your application. This looks like memory error or disk data corruption – osgx Aug 31 '11 at 20:54

1 Answers1

11

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)
osgx
  • 90,338
  • 53
  • 357
  • 513