powerpc: Use the correct flag for 32-bit known libraries

Message ID 20211022211201.983646-1-lamm@linux.ibm.com
State Rejected
Headers
Series powerpc: Use the correct flag for 32-bit known libraries |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686
codonell/TryBot-64bit success Build for 64bit

Commit Message

Lucas A. M. Magalhaes Oct. 22, 2021, 9:12 p.m. UTC
  In systems with more versions of the known libraries, i.e. on IBM
Advance Toolchain, ldconfig will order them incorrectly on ld.cache.

The issue only occurs with 32-bit libraries that don't depend on libc or
libm. That's because process_elf32_file check if the elf depends on one
of the libraries at known_libs to select the elf flag. For example, as
libc.so.6 don't depend on itself or on libm it will be flagged as
FLAG_ELF instead of FLAG_LIBC6 as expected.

This commit fixes this by checking if a appropriate flag was set by
process_elf32_file. If not it will search on known_libs and use the flag
in there.
---
 sysdeps/unix/sysv/linux/powerpc/readelflib.c | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
  

Comments

Florian Weimer Oct. 25, 2021, 6:22 p.m. UTC | #1
* Lucas A. M. Magalhaes via Libc-alpha:

> In systems with more versions of the known libraries, i.e. on IBM
> Advance Toolchain, ldconfig will order them incorrectly on ld.cache.
>
> The issue only occurs with 32-bit libraries that don't depend on libc or
> libm. That's because process_elf32_file check if the elf depends on one
> of the libraries at known_libs to select the elf flag. For example, as
> libc.so.6 don't depend on itself or on libm it will be flagged as
> FLAG_ELF instead of FLAG_LIBC6 as expected.

FLAG_ELF_LIBC6 instead of FLAG_LIBC6.

I have not looked at this patch in detail.  I would prefer if we removed
unified cache support for libc.so.4, libc.so.5 and always wrote
FLAG_ELF_LIBC6 to the cache instead.  The older Linux libcs have been
obsolete for more than twenty years.  I do not know how much work this
would be, so if someone can review your patch and it can go in, that's
fine with me.

Thanks,
Florian
  

Patch

diff --git a/sysdeps/unix/sysv/linux/powerpc/readelflib.c b/sysdeps/unix/sysv/linux/powerpc/readelflib.c
index 51f8a9496a..94da21c407 100644
--- a/sysdeps/unix/sysv/linux/powerpc/readelflib.c
+++ b/sysdeps/unix/sysv/linux/powerpc/readelflib.c
@@ -33,11 +33,26 @@  process_elf_file (const char *file_name, const char *lib, int *flag,
 		  char **soname, void *file_contents, size_t file_length)
 {
   ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
-  int ret;
+  int ret, j;
 
   if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
-    return process_elf32_file (file_name, lib, flag, osversion, isa_level,
-			       soname, file_contents, file_length);
+    {
+      ret = process_elf32_file (file_name, lib, flag, osversion, isa_level,
+                                soname, file_contents, file_length);
+      /* Use the apropriate flag for known_libs instead of FLAG_ELF.  */
+      if (*flag == FLAG_ELF)
+        {
+          for (j = 0;
+               j < sizeof (known_libs) / sizeof (known_libs [0]);
+               ++j)
+            if (strcmp (lib, known_libs [j].soname) == 0)
+              {
+                *flag = known_libs [j].flag;
+                break;
+              }
+        }
+      return ret;
+    }
   else
     {
       ret = process_elf64_file (file_name, lib, flag, osversion, isa_level,