From ec4eb78a39aebe3d1358676822b9d586136304f8 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 22 Aug 2000 19:34:37 +0000 Subject: 2000-08-22 H.J. Lu * emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Search the DT_RPATH/DT_RUNPATH entries for DT_NEEDED after LD_LIBRARY_PATH for native linker. Display the needed DSO if trace_file_tries is non-zero. (gld${EMULATION_NAME}_try_needed): Report the needed DSO found if trace_file_tries is non-zero. * ld.texinfo: Document the usage of DT_RPATH/DT_RUNPATH. * News: Mention it. --- ld/ChangeLog | 12 ++++++++ ld/NEWS | 3 ++ ld/emultempl/elf32.em | 76 ++++++++++++++++++++++++++++++++++++++++++++------- ld/ld.texinfo | 5 ++++ 4 files changed, 86 insertions(+), 10 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 043f67f..af430e8 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,15 @@ +2000-08-22 H.J. Lu + + * emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Search + the DT_RPATH/DT_RUNPATH entries for DT_NEEDED after + LD_LIBRARY_PATH for native linker. Display the needed DSO if + trace_file_tries is non-zero. + (gld${EMULATION_NAME}_try_needed): Report the needed DSO found + if trace_file_tries is non-zero. + + * ld.texinfo: Document the usage of DT_RPATH/DT_RUNPATH. + * News: Mention it. + 2000-08-14 Jason Eckhardt * NEWS: Mention i860 support. diff --git a/ld/NEWS b/ld/NEWS index ab47dc7..0e0e98c 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* The native ELF linker now searches the directories in DT_RUNPATH or + DT_RPATH of a shared library for shared libraries needed by it. + * TI C54x support, by Timothy Wall. * Added command line switch --section-start to set the start address of any diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index c1f5e31..dee6e8c 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -254,6 +254,7 @@ gld${EMULATION_NAME}_try_needed (name, force) int force; { bfd *abfd; + const char *soname; abfd = bfd_openr (name, bfd_get_target (output_bfd)); if (abfd == NULL) @@ -337,6 +338,17 @@ cat >>e${EMULATION_NAME}.c <filename, '/'); + if (soname) + soname++; + else + soname = abfd->filename; + + if (trace_file_tries) + info_msg (_("found %s at %s\n"), soname, name); + global_found = false; lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); if (global_found) @@ -350,17 +362,10 @@ cat >>e${EMULATION_NAME}.c <filename, '/'); - if (name) - name++; - else - name = abfd->filename; - /* Tell the ELF backend that the output file needs a DT_NEEDED entry for this file if it is used to resolve the reference in a regular object. */ - bfd_elf_set_dt_needed_soname (abfd, name); + bfd_elf_set_dt_needed_soname (abfd, soname); /* Add this file into the symbol table. */ if (! bfd_link_add_symbols (abfd, &link_info)) @@ -565,11 +570,34 @@ static void gld${EMULATION_NAME}_after_open () { struct bfd_link_needed_list *needed, *l; +EOF +if [ "x${host}" = "x${target}" ] ; then + case " ${EMULATION_LIBPATH} " in + *" ${EMULATION_NAME} "*) +cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <next) @@ -599,12 +639,16 @@ gld${EMULATION_NAME}_after_open () if (global_found) continue; + if (trace_file_tries) + info_msg (_("%s needed by %B\n"), l->name, l->by); + /* We need to find this file and include the symbol table. We want to search for the file in the same way that the dynamic linker will search. That means that we want to use rpath_link, rpath, then the environment variable - LD_LIBRARY_PATH (native only), then the linker script - LIB_SEARCH_DIRS. We do not search using the -L arguments. + LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH + entries (native only), then the linker script LIB_SEARCH_DIRS. + We do not search using the -L arguments. We search twice. The first time, we skip objects which may introduce version mismatches. The second time, we force @@ -637,6 +681,18 @@ cat >>e${EMULATION_NAME}.c <name, force)) break; + + found = 0; + for (rp = run_path; !found && rp != NULL; rp = rp->next) + { + found = (rp->by == l->by + && gld${EMULATION_NAME}_search_needed (rp->name, + l->name, + force)); + } + if (found) + break; + EOF ;; esac diff --git a/ld/ld.texinfo b/ld/ld.texinfo index cce8322..e3ecaa4 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1101,6 +1101,11 @@ directories specified using @code{-L} options. For a native linker, the contents of the environment variable @code{LD_LIBRARY_PATH}. @item +For a native ELF linker, the directories in @code{DT_RUNPATH} or +@code{DT_RPATH} of a shared library are searched for shared +libraries needed by it. The @code{DT_RPATH} entries are ignored if +@code{DT_RUNPATH} entries exist. +@item The default directories, normally @file{/lib} and @file{/usr/lib}. @item For a native linker on an ELF system, if the file @file{/etc/ld.so.conf} -- cgit v1.1