Remove search path from -l:namespec DT_NEEDED
authorAlan Modra <amodra@gmail.com>
Fri, 14 Mar 2014 00:55:59 +0000 (11:25 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 14 Mar 2014 02:24:24 +0000 (12:54 +1030)
For libraries without a soname, -l:libfoo.so set DT_NEEDED to the search
dir plus filename, while gold and -lfoo just use the filename.  This
patch fixes the inconsistency.

* ldlang.h (full_name_provided): New input flag.
* ldlang.c (new_afile): Don't use lang_input_file_is_search_file_enum
for -l:namespec.  Instead use lang_input_file_is_l_enum with
full_name_provided flag.
* ldlfile.c (ldfile_open_file_search): Don't complete lib name if
full_name_provided flag is set.
* emultempl/elf32.em (gld${EMULATION_NAME}_open_dynamic_archive):
Handle full_name_provided libraries.  Tidy EXTRA_SHLIB_EXTENSION
support.  Set DT_NEEDED for -l:namespec as namespec.
* emultempl/aix.em (ppc_after_open_output): Handle full_name_provided.
* emultempl/linux.em (gld${EMULATION_NAME}_open_dynamic_archive):
Don't handle full_name_provided libraries.
* emultempl/pe.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.
* emultempl/pep.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.
* emultempl/vms.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.

ld/ChangeLog
ld/emultempl/aix.em
ld/emultempl/elf32.em
ld/emultempl/linux.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/emultempl/vms.em
ld/ldfile.c
ld/ldlang.c
ld/ldlang.h

index cc5f8286cb29c9743e9fe7cef18df3ec256f5c22..9c728aee74605b9e06a3d32dd5e2063629675927 100644 (file)
@@ -1,3 +1,22 @@
+2014-03-14  Romain Geissler  <romain.geissler@amadeus.com>
+           Alan Modra  <amodra@gmail.com>
+
+       * ldlang.h (full_name_provided): New input flag.
+       * ldlang.c (new_afile): Don't use lang_input_file_is_search_file_enum
+       for -l:namespec.  Instead use lang_input_file_is_l_enum with
+       full_name_provided flag.
+       * ldlfile.c (ldfile_open_file_search): Don't complete lib name if
+       full_name_provided flag is set.
+       * emultempl/elf32.em (gld${EMULATION_NAME}_open_dynamic_archive):
+       Handle full_name_provided libraries.  Tidy EXTRA_SHLIB_EXTENSION
+       support.  Set DT_NEEDED for -l:namespec as namespec.
+       * emultempl/aix.em (ppc_after_open_output): Handle full_name_provided.
+       * emultempl/linux.em (gld${EMULATION_NAME}_open_dynamic_archive):
+       Don't handle full_name_provided libraries.
+       * emultempl/pe.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.
+       * emultempl/pep.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.
+       * emultempl/vms.em (gld${EMULATION_NAME}_open_dynamic_archive): Ditto.
+
 2014-03-12  Alan Modra  <amodra@gmail.com>
 
        * Makefile.in: Regenerate.
index 4a06c71c332afa2e8ca03b96efe5772db726f41c..caa74a990e2a3a7aa2690f8962b62227eb1dcef0 100644 (file)
@@ -1509,7 +1509,13 @@ gld${EMULATION_NAME}_open_dynamic_archive (const char *arch,
   if (!entry->flags.maybe_archive)
     return FALSE;
 
-  path = concat (search->name, "/lib", entry->filename, arch, ".a", NULL);
+  if (entry->flags.full_name_provided)
+    path = concat (search->name, "/", entry->filename,
+                  (const char *) NULL);
+  else
+    path = concat (search->name, "/lib", entry->filename, arch, ".a",
+                  (const char *) NULL);
+
   if (!ldfile_try_open_bfd (path, entry))
     {
       free (path);
index 789e12c2298c4be7f2c9128b8d3febac7b563817..7ea5adcc42b23cbd317351b383e7a7507046bde6 100644 (file)
@@ -1656,42 +1656,46 @@ gld${EMULATION_NAME}_open_dynamic_archive
 {
   const char *filename;
   char *string;
+  size_t len;
+  bfd_boolean opened = FALSE;
 
   if (! entry->flags.maybe_archive)
     return FALSE;
 
   filename = entry->filename;
+  len = strlen (search->name) + strlen (filename);
+  if (entry->flags.full_name_provided)
+    {
+      len += sizeof "/";
+      string = (char *) xmalloc (len);
+      sprintf (string, "%s/%s", search->name, filename);
+    }
+  else
+    {
+      size_t xlen = 0;
 
-  /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
-     is defined, but it does not seem worth the headache to optimize
-     away those two bytes of space.  */
-  string = (char *) xmalloc (strlen (search->name)
-                            + strlen (filename)
-                            + strlen (arch)
+      len += strlen (arch) + sizeof "/lib.so";
 #ifdef EXTRA_SHLIB_EXTENSION
-                            + strlen (EXTRA_SHLIB_EXTENSION)
+      xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
+             ? strlen (EXTRA_SHLIB_EXTENSION) - 3
+             : 0);
 #endif
-                            + sizeof "/lib.so");
-
-  sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
-
+      string = (char *) xmalloc (len + xlen);
+      sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
 #ifdef EXTRA_SHLIB_EXTENSION
-  /* Try the .so extension first.  If that fails build a new filename
-     using EXTRA_SHLIB_EXTENSION.  */
-  if (! ldfile_try_open_bfd (string, entry))
-    {
-      sprintf (string, "%s/lib%s%s%s", search->name,
-              filename, arch, EXTRA_SHLIB_EXTENSION);
+      /* Try the .so extension first.  If that fails build a new filename
+        using EXTRA_SHLIB_EXTENSION.  */
+      opened = ldfile_try_open_bfd (string, entry);
+      if (!opened)
+       strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
 #endif
+    }
 
-  if (! ldfile_try_open_bfd (string, entry))
+  if (!opened && !ldfile_try_open_bfd (string, entry))
     {
       free (string);
       return FALSE;
     }
-#ifdef EXTRA_SHLIB_EXTENSION
-    }
-#endif
 
   entry->filename = string;
 
@@ -1716,7 +1720,8 @@ gld${EMULATION_NAME}_open_dynamic_archive
       /* Rather than duplicating the logic above.  Just use the
         filename we recorded earlier.  */
 
-      filename = lbasename (entry->filename);
+      if (!entry->flags.full_name_provided)
+        filename = lbasename (entry->filename);
       bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
     }
 
index e7fa35d2c63c2a356a27081d5a81e2817a5e5e08..b30e872c3e663090155017ca17ea38fdfb8c44b7 100644 (file)
@@ -61,7 +61,7 @@ gld${EMULATION_NAME}_open_dynamic_archive
 {
   char *string;
 
-  if (! entry->flags.maybe_archive)
+  if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
     return FALSE;
 
   string = (char *) xmalloc (strlen (search->name)
index 6de71bd18bf008fae603f471fa045472d9f10f34..67df2bc4dba7896fc66963ca58db32b948112ef7 100644 (file)
@@ -2108,7 +2108,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive
   unsigned int i;
 
 
-  if (! entry->flags.maybe_archive)
+  if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
     return FALSE;
 
   filename = entry->filename;
index 9309c11fd64b5993588c805b54dc19e508e02946..dca36cc341aabfa2ec9db139b8ec94690165201a 100644 (file)
@@ -1879,7 +1879,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive
   unsigned int i;
 
 
-  if (! entry->flags.maybe_archive)
+  if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
     return FALSE;
 
   filename = entry->filename;
index 08650f5e1e6a3f2f306861ebeebfdb6847b0f210..b1f61d5b3b0665aca4796311d237c0e2f4573d5e 100644 (file)
@@ -57,7 +57,7 @@ gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED,
 {
   char *string;
 
-  if (! entry->flags.maybe_archive)
+  if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
     return FALSE;
 
   string = (char *) xmalloc (strlen (search->name)
index 61660ab889d6c4efa7759ef8b1109abb04b0a4c2..782ed7f03a1fdcf723bccc4e1a1ccfebe68d6869 100644 (file)
@@ -367,7 +367,7 @@ ldfile_open_file_search (const char *arch,
            return TRUE;
        }
 
-      if (entry->flags.maybe_archive)
+      if (entry->flags.maybe_archive && !entry->flags.full_name_provided)
        string = concat (search->name, slash, lib, entry->filename,
                         arch, suffix, (const char *) NULL);
       else
index 57e2ee82af73294c734d3d3ecbc9a3f413dea496..37ef2652e3acec30b50ded06d738738cc894d7fe 100644 (file)
@@ -1063,13 +1063,6 @@ new_afile (const char *name,
   p->flags.whole_archive = input_flags.whole_archive;
   p->flags.sysrooted = input_flags.sysrooted;
 
-  if (file_type == lang_input_file_is_l_enum
-      && name[0] == ':' && name[1] != '\0')
-    {
-      file_type = lang_input_file_is_search_file_enum;
-      name = name + 1;
-    }
-
   switch (file_type)
     {
     case lang_input_file_is_symbols_only_enum:
@@ -1083,7 +1076,13 @@ new_afile (const char *name,
       p->local_sym_name = name;
       break;
     case lang_input_file_is_l_enum:
-      p->filename = name;
+      if (name[0] == ':' && name[1] != '\0')
+        {
+          p->filename = name + 1;
+          p->flags.full_name_provided = TRUE;
+        }
+      else
+        p->filename = name;
       p->local_sym_name = concat ("-l", name, (const char *) NULL);
       p->flags.maybe_archive = TRUE;
       p->flags.real = TRUE;
index 8f525d189f68848ea5b61d8200f997da02f711da..aacd5dcaed53188974c69ff4aa96c693633794a6 100644 (file)
@@ -235,6 +235,9 @@ struct lang_input_statement_flags
   /* 1 means this file was specified in a -l option.  */
   unsigned int maybe_archive : 1;
 
+  /* 1 means this file was specified in a -l:namespec option.  */
+  unsigned int full_name_provided : 1;
+
   /* 1 means search a set of directories for this file.  */
   unsigned int search_dirs : 1;