$ uname -a
Linux localhost.localdomain 2.6.15-1.2054_FC5smp #1 SMP Tue Mar 14 16:05:46 EST
2006 i686 i686 i386 GNU/Linux
$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
It appears that -g is broken for use when trying to generate objects for shared
libraries. The following should demonstrate.
file XYZ.C
-------
#include <iostream>
class XYZ
{
public:
XYZ(void);
~XYZ(void);
};
XYZ::XYZ(void)
{ std::cout << "XYZ" << std::endl; }
XYZ::~XYZ(void)
{ std::cout << "~XYZ" << std::endl; }
-----------
build,create and check:
$ gcc -g -fPIC -o XYZ.o -c XYZ.C
$ gcc -shared -g -fPIC -o libXYZ.so.1 XYZ.o
$ /usr/bin/readelf -l ./libXYZ.so.1
Elf file type is DYN (Shared object file)
Entry point 0x730
There are 5 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg
Align
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0
Section to Segment mapping:
Segment Sections...
00
01
02
03
04
If you remove -g from the compile of XYZ.C then you get the right thing.
$ gcc -fPIC -o XYZ.o -c XYZ.C
$ gcc -shared -g -fPIC -o libXYZ.so.1 XYZ.o
$ /usr/bin/readelf -l ./libXYZ.so.1
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x00000000 0x00000000 0x000750 0x000750 R E 0x1000
LOAD 0x000750 0x00001750 0x00001750 0x0000cc 0x0000d0 RW 0x1000
DYNAMIC 0x000754 0x00001754 0x00001754 0x000098 0x000098 RW 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x000000 0x000000 RW 0x4
Section to Segment mapping:
Segment Sections...
00 [RO: .hash .dynsym .dynstr .rel.dyn .rel.plt .plt .text .rodata
.eh_frame]
01 .ctors .dynamic .got .got.plt .data .bss
02 .dynamic
03
--
Summary: gcc -g and shared objects
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jmbnyc at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28746