Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Apr 1999 03:09:39 -0400
From:      Brad Karp <karp@eecs.harvard.edu>
To:        freebsd-ports@freebsd.org
Subject:   egcs-1.1.2 shared library linking bummage
Message-ID:  <199904110709.DAA12115@dominator.eecs.harvard.edu>

next in thread | raw e-mail | index | archive | help
I run FreeBSD 3.1-RELEASE, with a /usr/ports updated to that of 4/8/99.

I built the egcs-1.1.2 port as of 4/10/99, and the build and resulting
compiler were fine, or so I thought, until I tried using egcc to produce
shared libraries and link against those shared libraries.

Say I have a function bar() defined in bar.c, and I compile bar.c into a
shared library, libbar.so, using egcc:

	egcc -shared -fPIC -DPIC -Wl,-h -Wl,libbar.so -o libbar.so bar.c

Then say I have main() in foo.c, and main() calls bar(). I build the
executable foo as follows:

	egcc -o foo foo.c -L`pwd` -lbar

The link goes fine, and an executable foo is created. I set my
LD_LIBRARY_PATH to include `pwd`, and run foo, but I get the error:

/usr/libexec/ld-elf.so.1: /usr/home/karp/egcs-bug/libbar.so: Undefined symbol "__deregister_frame_info"

After some sleuthing by adding the -v option to the above egcc commmand
lines, and nm'ing around in
/usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/,
where the egcc-specific .o files and libgcc.a live, I've learned:

	- {crtbegin,crtbeginS,crtend,crtendS}.o all contain an unresolved
	  reference to __register_frame_info and __deregister_frame_info

	- libgcc.a contains text for these functions

	- the build of foo *does* link against libgcc.a, so it *should*
	  bring in these *_frame_info functions successfuly...but it
	  doesn't

	- explicitly adding -lgcc to the end of the link line doesn't help

	- extracting the .o file (frame.o) that defines *_frame_info in
	  egcc's libgcc.a, and manually including it in the link successfully
	  includes the text for these functions in the executable

	- the output of egcc -v -Wl,--verbose shows that the proper libgcc.a
	  is being used (i.e., not the old 2.7.2.1 libgcc.a, which doesn't
	  have these frame_info functions...this was the first explanation I
	  [wrongly] seized on)

Even compiling a one-line "hello, world" program (no shared libraries of my
construction involved) with egcc gives an executable with these *_frame_info
symbols unresolved. However, the run-time loader doesn't complain when I run
that executable--only when I run one linked against a shared library I've
created myself, as above.

Does anyone else see similar behavior? Better still, does anyone have a fix?
I'm not a regular reader of the the ports mailing list, so if you could cc
your reply to me directly, that'd be great. Thanks!

Here are the exact files I use to demonstrate this behavior on my system:

bar.c
-----

#include <stdio.h>

void bar(void)
{
  printf("hello, world.\n");
}

foo.c
-----

main(int argc, char **argv)
{
  bar();
}

Here is a transcript of the behavior I see:

[dominatrix 119]  egcc -v -c -fPIC -DPIC bar.c
Reading specs from /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -Di386 -D__ELF__ -Dunix -D__FreeBSD__=3 -D__i386__ -D__ELF__ -D__unix__ -D__FreeBSD__=3 -D__i386 -D__unix -Acpu(i386) -Amachine(i386) -Asystem(unix) -Asystem(FreeBSD) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__PIC__ -D__pic__ -DPIC bar.c /var/tmp/ccQvcCix.i
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386 FreeBSD/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/i386-portbld-freebsd3.1/include
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/cc1 /var/tmp/ccQvcCix.i -quiet -dumpbase bar.c -version -fPIC -o /var/tmp/ccAvmCzW.s
GNU C version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386-portbld-freebsd3.1) compiled by GNU C version egcs-2.91.66 19990314 (egcs-1.1.2 release).
 as -V -Qy -o bar.o /var/tmp/ccAvmCzW.s
GNU assembler version 2.9.1 (i386-unknown-freebsdelf), using BFD version 2.9.1

[dominatrix 120]  egcc -v -shared -Wl,-h -Wl,libbar.so -o libbar.so bar.o
Reading specs from /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/collect2 -m elf_i386 -shared -o libbar.so /usr/lib/crti.o /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/crtbeginS.o -L/usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66 -L/usr/local/i386-portbld-freebsd3.1/lib -L/usr/local/lib -h libbar.so bar.o -lgcc -lgcc /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/crtendS.o /usr/lib/crtn.o

[dominatrix 122]  setenv LD_LIBRARY_PATH `pwd`':'$LD_LIBRARY_PATH

[dominatrix 124]  egcc -v -o foo foo.c -L. -lbar
Reading specs from /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -Di386 -D__ELF__ -Dunix -D__FreeBSD__=3 -D__i386__ -D__ELF__ -D__unix__ -D__FreeBSD__=3 -D__i386 -D__unix -Acpu(i386) -Amachine(i386) -Asystem(unix) -Asystem(FreeBSD) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ foo.c /var/tmp/cc8XhqFr.i
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386 FreeBSD/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/i386-portbld-freebsd3.1/include
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/cc1 /var/tmp/cc8XhqFr.i -quiet -dumpbase foo.c -version -o /var/tmp/ccCqek7J.s
GNU C version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386-portbld-freebsd3.1) compiled by GNU C version egcs-2.91.66 19990314 (egcs-1.1.2 release).
 as -V -Qy -o /var/tmp/cc2aJaT4.o /var/tmp/ccCqek7J.s
GNU assembler version 2.9.1 (i386-unknown-freebsdelf), using BFD version 2.9.1
 /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/collect2 -m elf_i386 -dynamic-linker /usr/libexec/ld-elf.so.1 -o foo /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/crtbegin.o -L. -L/usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66 -L/usr/local/i386-portbld-freebsd3.1/lib -L/usr/local/lib /var/tmp/cc2aJaT4.o -lbar -lgcc -lc -lgcc /usr/local/lib/gcc-lib/i386-portbld-freebsd3.1/egcs-2.91.66/crtend.o /usr/lib/crtn.o

[dominatrix 125]  ./foo
/usr/libexec/ld-elf.so.1: /usr/home/karp/egcs-bug/libbar.so: Undefined symbol "__deregister_frame_info"

-Brad, karp@eecs.harvard.edu


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904110709.DAA12115>