Search code examples
clinuxgcclinkerglibc

Glibc link difference causing segmentation fault


Something about the server I build on is broken (I am not the only one who uses it...). It is SLES 11 (no SP). I have tried uninstalling and reinstalling gcc, glibc etc with no success.

The problem is my built program seg-faults as soon as it hits a library function such as memset or strlen (note it is the calling of this function and not the function itself, the parameters are fine). I think it is definitely linking wrong and I can prove it is different to how it was with readelf. eg:

# readelf -s myprog | grep memset
  247: 081461d0    52 <OS specific>: 10 GLOBAL DEFAULT   27 memset@GLIBC_2.0 (3)
  3530: 081461d0    52 <OS specific>: 10 GLOBAL DEFAULT   27 memset@@GLIBC_2.0

vs a previous working version that says:

  69: 00000000     0 FUNC    GLOBAL DEFAULT  UND memset@GLIBC_2.0 (2)
  2035: 00000000     0 FUNC    GLOBAL DEFAULT  UND memset@@GLIBC_2.0

Its a fairly standard makefile and nothing has changed. The linker flags are:

LDFLAGS = -L$(companylibrarypath) -lourcompanylibrary -L$(mysql_lib_path) -lmysqlclient -L/usr/tls/ -lpthread -pthread -lz -L$(curl_lib_path) -lcurl -lxslt

Solution

  • Your programs by some bad way redefines functions like memset (instead of using the std library provided versions). It is likely caused by some headers, which may be "standard"... Also may be your compiler (gcc?) by some way generates (elf) code not for your platform...
    Also you say the link process is failing, did you mean the linker is failing and cannot produce an executable?