Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segmentation fault: 0x0000000000000001 in ?? () trying to compile/link under Linux

I have a suite of software written in 'C'. This is normally compiled using acc and run on a UNIX Solaris system but I have been given the task of getting it to run under Linux on an x86_64 box.

I am not particularly familiar with gcc or Linux but I have managed to get the code to compile with just a minimum of changes to remove warnings that weren't there under Solaris. I am using the following compile command (invoked from a script, hence the environment variables):

/usr/bin/gcc -L/tmp/lib -L/tmp/usr/lib -c -fPIC -g -I$WORKING_DIR $INCLUDE $WORKING_DIR/$FILE

Most of the source is then placed in shared (.so) libraries, also via script, using the following command:

ld $GLOSS_SUB_DIR/$REL_DIR/obj/$PREFIX*".o" -G -o $GLOSS_SUB_DIR/$REL_DIR/lib/$LIB$NEW_MIN_VER_NO

A sample makefile for an executable called 'gsproc' is as follows:

CONTROL_NO = $(shell awk 'BEGIN{FS=","} /control/ {printf "%s%s", $$3,$$4} END{}' $$GLOSS_DIR/subenv_list)

CTRL_PATH = $(GLOSS_DIR)/control/$(CONTROL_NO)

OBJECTS = $(CTRL_PATH)/nolib/gsproc.o  \
          $(CTRL_PATH)/nolib/w_bkg_shared.o

LIBS    = -lcontrolw \
          -lsharew \
          -lsybdb64


gsproc: $(OBJECTS)
     gcc -shared -fPIC -o $(TMP_DIR)/gsproc \
         -L $(SYBASE)/$(SYBASE_OCS)/devlib \
          $(OBJECTS) $(LIBS) -lm -lc –lnsl

I have been successful in compiling and then linking all of the code but every executable now falls over immediately on startup with a segmentation fault and core dump. All I get from gdb is:

GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /gloss_env/GLSLAZ_TST2/control/C2.0.0/bin/gsproc...done.
(gdb) run
Starting program: /gloss_env/GLSLAZ_TST2/control/C2.0.0/bin/gsproc 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000001 in ?? ()

So it doesn't look like the problem is with the code, as such. Presumably I am doing something wrong with my compiler or linker options.

like image 644
user2311565 Avatar asked Apr 23 '13 14:04

user2311565


1 Answers

This Makefile rule / gcc command

gsproc: $(OBJECTS)
     gcc -shared -fPIC -o $(TMP_DIR)/gsproc \
         -L $(SYBASE)/$(SYBASE_OCS)/devlib \
          $(OBJECTS) $(LIBS) -lm -lc –lnsl

makes a shared object namde gsproc (without the normal lib prefix and .so suffix). An executable and a library is the same fileformat in many operating systems, with the side-effect that you can try to run a shared-library as an executable. But the result is usually what you see, instant crash etc.

like image 122
Stian Skjelstad Avatar answered Oct 13 '22 12:10

Stian Skjelstad