This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: finding libraries from linker via $ORIGIN

On Fri, Apr 12, 2013 at 12:12:05AM +0200, Oliver Kiddle wrote:
> Alan Modra wrote:
> > It might be reasonable to omit loading DT_NEEDED libraries if both
> > --no-copy-dt-needed-entries *and* --allow-shlib-undefined is specified.
> That makes sense, thanks. It seems to work well as far as my testing
> goes. I've put the corresponding small patch below. Is there any chance
> of this change or a similar one being included?

When HJ added the code to skip loading DT_NEEDED libs when creating a
shared lib,,
he used !link_info.executable.  I didn't notice on review that what
really should be tested is the flag set by --allow-shlib-undefined.
For -shared the flag defaults to "ignore undefined syms", but you may
well want to build a shared lib reporting undefined syms, in which
case DT_NEEDED libs ought to be loaded.  Fixed with the following

> I'd also be happy to put together a patch for expanding $ORIGIN when
> searching for DT_NEEDED libraries if there's any willingness to include
> such a change(?).

Yes, I think that would be reasonable.

	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Test
	unresolved_syms_in_shared_libs rather than !executable to
	determine whether to load DT_NEEDED libraries.

Index: ld/emultempl/elf32.em
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.242
diff -u -p -r1.242 elf32.em
--- ld/emultempl/elf32.em	4 Apr 2013 14:38:47 -0000	1.242
+++ ld/emultempl/elf32.em	25 Apr 2013 23:54:01 -0000
@@ -1178,13 +1178,16 @@ gld${EMULATION_NAME}_after_open (void)
       int force;
       /* If the lib that needs this one was --as-needed and wasn't
-	 found to be needed, then this lib isn't needed either.  Skip
-	 the lib when creating a shared object unless we are copying
-	 DT_NEEDED entres.  */
+	 found to be needed, then this lib isn't needed either.  */
       if (l->by != NULL
-	  && ((bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0
-	      || (!link_info.executable
-		  && bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0))
+	  && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
+	continue;
+      /* Skip the lib if --no-copy-dt-needed-entries and
+	 --allow-shlib-undefined is in effect.  */
+      if (l->by != NULL
+	  && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
+	  && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
       /* If we've already seen this file, skip it.  */

Alan Modra
Australia Development Lab, IBM

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]