Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* 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; 8+ 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] 8+ messages in thread

* Re: BUG: probs with resolving functions in shared library
  1998-08-05 16:16 BUG: probs with resolving functions in shared library Eric Ding
@ 1998-08-08 22:29 ` Richard Henderson
  1998-08-10 15:54   ` Eric Ding
  1998-08-12 17:07   ` Eric Ding
  0 siblings, 2 replies; 8+ messages in thread
From: Richard Henderson @ 1998-08-08 22:29 UTC (permalink / raw)
  To: Eric Ding, axp-list; +Cc: gafton

On Wed, Aug 05, 1998 at 12:16:57PM -0400, Eric Ding wrote:
> 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?

No, you are doing nothing wrong.  This is a bug in binutils.
Here is a patch.


r~


	* elf64-alpha.c (alpha_elf_dynamic_symbol_p): Undef weak symbols
	are always dynamic.
	(elf64_alpha_calc_dynrel_sizes): Allow enough room for RELATIVE
	.got relocs in -Bsymbolic shared objects.


Index: elf64-alpha.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf64-alpha.c,v
retrieving revision 1.33
diff -u -p -r1.33 elf64-alpha.c
--- elf64-alpha.c	1998/07/21 01:54:28	1.33
+++ elf64-alpha.c	1998/08/08 22:13:39
@@ -229,7 +229,8 @@ struct alpha_elf_link_hash_table
   (((info)->shared && !(info)->symbolic && (h)->dynindx != -1)		\
    || (((h)->elf_link_hash_flags					\
 	& (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))	\
-       == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
+       == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))	\
+   || (h)->root.type == bfd_link_hash_undefweak)
 
 /* Create an entry in a Alpha ELF linker hash table.  */
 
@@ -3137,39 +3138,31 @@ elf64_alpha_calc_dynrel_sizes (h, info)
 
   /* If the symbol is dynamic, we'll need all the relocations in their
      natural form.  If it has been forced local, we'll need the same 
-     number of RELATIVE relocations.  */
-  if (alpha_elf_dynamic_symbol_p (&h->root, info)
-      || (info->shared && h->root.dynindx == -1))
-    {
-      struct alpha_elf_reloc_entry *relent;
-
-      for (relent = h->reloc_entries; relent; relent = relent->next)
-	{
-	  relent->srel->_raw_size +=
-	    sizeof (Elf64_External_Rela) * relent->count;
-	}
+     number of RELATIVE relocations. 
+     Except, don't add a .got reloc if we're not using a .plt entry.  */
 
-      /* Only add a .rela.got entry if we're not using a .plt entry.  */
-      if (h->root.plt.offset == MINUS_ONE)
+  if ((alpha_elf_dynamic_symbol_p (&h->root, info)
+       || info->shared)
+      && h->root.plt.offset == MINUS_ONE)
+    {
+      bfd *dynobj = elf_hash_table(info)->dynobj;
+      struct alpha_elf_got_entry *gotent;
+      bfd_size_type count = 0;
+      asection *srel;
+
+      for (gotent = h->got_entries; gotent ; gotent = gotent->next)
+	count++;
+      if (count > 0)
 	{
-	  bfd *dynobj = elf_hash_table(info)->dynobj;
-	  struct alpha_elf_got_entry *gotent;
-	  bfd_size_type count = 0;
-	  asection *srel;
-
-	  for (gotent = h->got_entries; gotent ; gotent = gotent->next)
-	    count++;
-	  if (count > 0)
-	    {
-	      srel = bfd_get_section_by_name (dynobj, ".rela.got");
-	      BFD_ASSERT (srel != NULL);
-	      srel->_raw_size += sizeof (Elf64_External_Rela) * count;
-	    }
+	  srel = bfd_get_section_by_name (dynobj, ".rela.got");
+	  BFD_ASSERT (srel != NULL);
+	  srel->_raw_size += sizeof (Elf64_External_Rela) * count;
 	}
     }
-  /* Otherwise, shared objects require RELATIVE relocs for all REFQUAD
+
+  /* Shared objects require at least RELATIVE relocs for all REFQUAD
      and REFLONG relocations.  */
-  else if (info->shared)
+  if (info->shared)
     {
       struct alpha_elf_reloc_entry *relent;
 
@@ -3610,7 +3603,8 @@ elf64_alpha_relocate_section (output_bfd
 		    /* If the symbol has been forced local, output a
 		       RELATIVE reloc, otherwise it will be handled in
 		       finish_dynamic_symbol.  */
-		    if (info->shared && h->root.dynindx == -1)
+		    if (info->shared
+			&& !alpha_elf_dynamic_symbol_p (&h->root, info))
 		      {
 			Elf_Internal_Rela outrel;
 


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

* Re: BUG: probs with resolving functions in shared library
  1998-08-08 22:29 ` Richard Henderson
@ 1998-08-10 15:54   ` Eric Ding
  1998-08-10 17:52     ` Richard Henderson
  1998-08-12 17:07   ` Eric Ding
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Ding @ 1998-08-10 15:54 UTC (permalink / raw)
  To: axp-list

Is this patch broken?  It appears that h->root.plt.offset ought to instead
by h->root.plt_offset.  I'm patching against binutils-2.9.1.0.4.

Thanks,
Eric

Richard Henderson <rth@dot.cygnus.com> writes:

> No, you are doing nothing wrong.  This is a bug in binutils.
> Here is a patch.
[...]
> +      && h->root.plt.offset == MINUS_ONE)
> +    {
> +      bfd *dynobj = elf_hash_table(info)->dynobj;
> +      struct alpha_elf_got_entry *gotent;
> +      bfd_size_type count = 0;
> +      asection *srel;
[...]


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

* Re: BUG: probs with resolving functions in shared library
  1998-08-10 15:54   ` Eric Ding
@ 1998-08-10 17:52     ` Richard Henderson
  1998-08-10 19:51       ` Eric Ding
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 1998-08-10 17:52 UTC (permalink / raw)
  To: axp-list

On Mon, Aug 10, 1998 at 11:54:32AM -0400, Eric Ding wrote:
> Is this patch broken?  It appears that h->root.plt.offset ought to instead
> by h->root.plt_offset.  I'm patching against binutils-2.9.1.0.4.

Ah yes.  The problem being that the patch was not generated against
binutils 2.9.1, but rather current sources. 

There is another problem as well that affects static linking.  Use
the following definition instead of the one in the patch.

#define alpha_elf_dynamic_symbol_p(h, info)                             \
  ((((info)->shared && !(info)->symbolic)                               \
    || (((h)->elf_link_hash_flags                                       \
         & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))     \
        == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))     \
    || (h)->root.type == bfd_link_hash_undefweak                        \
    || (h)->root.type == bfd_link_hash_defweak)                         \
   && (h)->dynindx != -1)


r~


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

* Re: BUG: probs with resolving functions in shared library
  1998-08-10 17:52     ` Richard Henderson
@ 1998-08-10 19:51       ` Eric Ding
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Ding @ 1998-08-10 19:51 UTC (permalink / raw)
  To: axp-list

Richard Henderson <rth@dot.cygnus.com> writes:

> On Mon, Aug 10, 1998 at 11:54:32AM -0400, Eric Ding wrote:
> > Is this patch broken?  It appears that h->root.plt.offset ought to instead
> > by h->root.plt_offset.  I'm patching against binutils-2.9.1.0.4.
> 
> Ah yes.  The problem being that the patch was not generated against
> binutils 2.9.1, but rather current sources. 
> 
> There is another problem as well that affects static linking.  Use
> the following definition instead of the one in the patch.

The patch doesn't apply cleanly against 2.9.1.0.4, either; and even if I do
patch the appropriate function, things go awry in actually using ld.  Hm.
I'm also trying out 2.9.1.0.9, but that goes off and aborts on me during
the linking stage.  Argh.

Eric


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

* Re: BUG: probs with resolving functions in shared library
  1998-08-08 22:29 ` Richard Henderson
  1998-08-10 15:54   ` Eric Ding
@ 1998-08-12 17:07   ` Eric Ding
  1998-08-12 17:31     ` Applix? Port? (was re: BUG...) Keith Baker
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Ding @ 1998-08-12 17:07 UTC (permalink / raw)
  To: axp-list

Hey all,

thanks to H.J. Lu, who's fixed this bug in the upcoming 2.9.1.0.10 release
of binutils.  :)  I don't think I'm gonna be able to convince management to
put his name in Applixware proper, so this is as close as we get to saying
that he's been a crucial link toward making this a reality.  =b

Eric

Richard Henderson <rth@dot.cygnus.com> writes:

> On Wed, Aug 05, 1998 at 12:16:57PM -0400, Eric Ding wrote:
> > 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?
> 
> No, you are doing nothing wrong.  This is a bug in binutils.
> Here is a patch.


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

* Applix? Port? (was re: BUG...)
  1998-08-12 17:07   ` Eric Ding
@ 1998-08-12 17:31     ` Keith Baker
  1998-08-12 21:08       ` Eric Ding
  0 siblings, 1 reply; 8+ messages in thread
From: Keith Baker @ 1998-08-12 17:31 UTC (permalink / raw)
  To: axp-list

I think I missed the beginning of this...  Applixware?  Port?  Alpha?

On 12 Aug 1998, Eric Ding wrote:

> Hey all,
> 
> thanks to H.J. Lu, who's fixed this bug in the upcoming 2.9.1.0.10 release
> of binutils.  :)  I don't think I'm gonna be able to convince management to
> put his name in Applixware proper, so this is as close as we get to saying
> that he's been a crucial link toward making this a reality.  =b
> 
> Eric
> 
> Richard Henderson <rth@dot.cygnus.com> writes:
> 
> > On Wed, Aug 05, 1998 at 12:16:57PM -0400, Eric Ding wrote:
> > > 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?
> > 
> > No, you are doing nothing wrong.  This is a bug in binutils.
> > Here is a patch.
> 
> -- 
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com
> 
> 


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

* Re: Applix? Port? (was re: BUG...)
  1998-08-12 17:31     ` Applix? Port? (was re: BUG...) Keith Baker
@ 1998-08-12 21:08       ` Eric Ding
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Ding @ 1998-08-12 21:08 UTC (permalink / raw)
  To: axp-list

Keith Baker <toaster@cybercom.net> writes:

> I think I missed the beginning of this...  Applixware?  Port?  Alpha?

Heh... did I let the cat out of the bag?  =b  

That's right, the Applixware port to Linux/Alpha is in progress.  While
there are a few things out of our hands (for example, the Gallium font
server is not available on Linux/Alpha), the build is in good shape as we
speak.  I've got Applixware natively running quite cleanly on Linux/Alpha
already, and we'll likely start beta testing sometime soon.

No release date has been set yet, though, so don't ask.  :)

Eric
-- 
Software Development Engineer / ericding@applix.com               <><
Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
TEL: (508) 870-0300 x284 / FAX: (508) 366-4873


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-08-05 16:16 BUG: probs with resolving functions in shared library 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
1998-08-12 17:31     ` Applix? Port? (was re: BUG...) Keith Baker
1998-08-12 21:08       ` Eric Ding

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