PATCH: undefined symbols in shared libraries

H. J. Lu hjl@lucon.org
Fri Mar 12 03:24:00 GMT 2004


On Fri, Mar 12, 2004 at 01:29:30PM +1030, Alan Modra wrote:
> On Thu, Mar 11, 2004 at 01:18:08PM -0800, H. J. Lu wrote:
> > -	       ((info->shared && info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)				\
> > -		|| (!info->shared && info->unresolved_syms_in_objects == RM_GENERATE_ERROR)				\
> > +	       (info->unresolved_syms_in_objects == RM_GENERATE_ERROR							\
> >  		|| ELF_ST_VISIBILITY (h->other))									\
> 
> Ick, this macro needs trimming down to 80 columns.

Can we turn it into a function?

> 
> I don't think this is correct, nor was the test correct before.  It
> seems wrong to me that we're testing info->shared here (and also
> !info->executable a little earlier), as that just confuses the meaning

That is correct since when building DSO, undefined reference is allowed
by default.

> of info->unresolved_syms_in_shared_libs and
> info->unresolved_syms_in_objects.  This is all completely untested,
> but I think we should be using
> 
>       else if (h->root.type == bfd_link_hash_undefweak)
> 	;
>       else if (((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
> 		|| info->unresolved_syms_in_objects == RM_IGNORE)
> 	       && ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
> 		   || (info->unresolved_syms_in_shared_libs == RM_IGNORE))
> 	       && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)

H is referenced in the input object. Why do we care about DSO here?

	else if (!info->executable
		&& info->unresolved_syms_in_objects == RM_IGNORE
		&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
		;

looks OK to me.

> 	;
>       else
> 	{
> 	  bfd_boolean err;
> 	  err = (((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) != 0
> 		  && info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
> 		 || ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
> 		     && (info->unresolved_syms_in_shared_libs
> 			 == RM_GENERATE_ERROR))
> 		 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT);
> 
> 	  if (! info->callbacks->undefined_symbol (info, h->root.root.string,
> 						   input_bfd, input_section,
> 						   rel->r_offset, err))
> 	    return FALSE;
> 	  warned = TRUE;
> 	}

I believe the symbol is either defined or referenced when this macro
is used. I think my patch is correct. 

> 
> You might then need to tweak lexsup.c to set unresolved_syms_in_*

I think the current setting is OK.

> differently.  Note the comments in bfdlink.h disagree with the way ld
> currently sets these flags.

I think it meant to say executables and shared libraries instead of
static binaries and dynamic binaries. You can't have unresolved
references in dynamic binaries.


H.J.



More information about the Binutils mailing list