title: Segmentation fault: 0x0000000000000001 in ?? () trying to compile/link under Linux
body: <p>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.</p>
  
  <p>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):</p>
  
  <pre><code>/usr/bin/gcc -L/tmp/lib -L/tmp/usr/lib -c -fPIC -g -I$WORKING_DIR $INCLUDE $WORKING_DIR/$FILE
  </code></pre>
  
  <p>Most of the source is then placed in shared (.so) libraries, also via script, using the following command:</p>
  
  <pre><code>ld $GLOSS_SUB_DIR/$REL_DIR/obj/$PREFIX*".o" -G -o $GLOSS_SUB_DIR/$REL_DIR/lib/$LIB$NEW_MIN_VER_NO
  </code></pre>
  
  <p>A sample makefile for an executable called 'gsproc' is as follows:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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 &lt;http://gnu.org/licenses/gpl.html&gt;
  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:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;...
  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 ?? ()
  </code></pre>
  
  <p>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.</p>