Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: BUG: probs with resolving functions in shared library
@ 1998-08-05 22:48 Quant-X Alpha Linux Support
  1998-08-06  2:38 ` Eric Ding
  0 siblings, 1 reply; 11+ messages in thread
From: Quant-X Alpha Linux Support @ 1998-08-05 22:48 UTC (permalink / raw)
  To: Eric Ding; +Cc: axp-list

Hi Eric !

> gcc -shared -Xlinker -Bsymbolic -Xlinker --noinhibit-exec -o libtest2.so \
>      test2.o test3.o

I don't know if it helps:

ld -shared -Bdynamic --noinhibit-exec -o libtest2.so test2.o test3.o

works here as expected. (The difference is only that I'm using
-Bdynamic instead of -Bsymbolic) 

It is a bug. But ok so.
If you want -Bdynamic work as the specs say, you need to compile the main
program (!) with -Xlinker -export-dynamic. If you do this, you
get the "OOPS!".


Hope it helps.

  ciao -
    Stefan

-- 

Quant-X Service &                         Ph:  (+43) 4212 6004-0
Consulting Ges.m.b.H.                     Fax: (+43) 4212 600420
http://www.quant-x.com                    Email: support@quant-x.com


^ permalink raw reply	[flat|nested] 11+ messages in thread
* BUG: probs with resolving functions in shared library
@ 1998-08-05 16:16 Eric Ding
  1998-08-08 22:29 ` Richard Henderson
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Ding @ 1998-08-05 16:16 UTC (permalink / raw)
  To: axp-list

Hi,

I've looked over the Linux-Alpha FAQ; this question is not the same as
the gdb issue with dynamic functions.  I'm running on a RedHat 5.1
system with egcs 1.0.3a and the latest binutils-2.9.1.0.4 RPM update.
Summary: the linker seems to be improperly resolving global function
references within a shared library.

I have three files: test.c, test2.c, test3.c, as included below.  I
compile test.c into an executable which loads libtest2.so, a shared
library created with test2.o and test3.o.  In test.c, I call a function
in test2.c which calls testme(), a function defined in both the
executable and in the shared library.

Note that I do link the shared library with the -Bsymbolic flag, so I
expect testme() to be resolved to the shared library's version.

1) On Linux/Intel, this produces expected results: a message "hello
there from test2".  On Linux/Alpha, I get a segmentation fault when
testme() is called from within test2().

2) If I combine the contents of test2.c and test3.c and link the
resulting object file into a shared library, then I get the expected
message rather than a segmentation fault.

While #2 is an acceptable workaround in my test case, it indicates to me
that there's a significant linker (?) bug that I can't work around in the
case of the software I'm actually porting (Applixware).  Any thoughts?
Am I doing something wrong?

Thanks,
Eric

BTW, here's my compile and link commmands:

gcc -g -c -fPIC test2.c
gcc -g -c -fPIC test3.c
gcc -shared -Xlinker -Bsymbolic -Xlinker --noinhibit-exec -o libtest2.so \
     test2.o test3.o
gcc -g -c test.c
gcc -o test test.o -ldl

And here's the test case source code:

/* ---- clip here ---- */
/* beginning of test.c */

#include <stdio.h>
#include <dlfcn.h>

void testme();

int main(int argc, char **argv) {
	void *handle;
	void* (*test2)();
	
	handle = dlopen("./libtest2.so", RTLD_NOW);
	test2 = dlsym(handle, "test2");
	(*test2)();
	dlclose(handle);
	return(0);
}

void testme() {
	fprintf(stderr, "OOPS! called testme() from test.c\n");
}

/* end of test.c */

/* ---- clip here ---- */
/* beginning of test2.c */

extern void testme();

void test2() {
	testme();
}

/* end of test2.c */

/* ---- clip here ---- */
/* beginning of test3.c */

#include <stdio.h>

void testme() {
	printf("hello there from test2\n");
}

/* end of test3.c */


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~1998-08-12 17:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-08-05 22:48 BUG: probs with resolving functions in shared library Quant-X Alpha Linux Support
1998-08-06  2:38 ` Eric Ding
1998-08-06 12:59   ` Quant-X Alpha Linux Support
1998-08-06 16:30     ` Eric Ding
1998-08-06 21:24       ` Quant-X Alpha Linux Support
  -- strict thread matches above, loose matches on Subject: below --
1998-08-05 16:16 Eric Ding
1998-08-08 22:29 ` Richard Henderson
1998-08-10 15:54   ` Eric Ding
1998-08-10 17:52     ` Richard Henderson
1998-08-10 19:51       ` Eric Ding
1998-08-12 17:07   ` Eric Ding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox