public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] RISC-V: Add path of library directories for the 32-bit
@ 2020-08-27 18:36 Alistair Francis
  0 siblings, 0 replies; only message in thread
From: Alistair Francis @ 2020-08-27 18:36 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=708b92e878d8c4bded5dfff9416742ff7793fbd4

commit 708b92e878d8c4bded5dfff9416742ff7793fbd4
Author: Alistair Francis <alistair.francis@wdc.com>
Date:   Thu Jul 9 10:02:06 2020 -0700

    RISC-V: Add path of library directories for the 32-bit
    
    With RV32 support the list of possible RISC-V system directories
    increases to:
         - /lib64/lp64d
         - /lib64/lp64
         - /lib32/ilp32d
         - /lib32/ilp32
         - /lib (only ld.so)
    
    This patch changes the add_system_dir () macro to support the new ilp32d
    and ilp32 directories for RV32.  While refactoring this code let's split
    out the confusing if statements into a loop to make it easier to
    understand and extend.
    
    Reviewed-by: Maciej W. Rozycki <macro@wdc.com>

Diff:
---
 sysdeps/unix/sysv/linux/riscv/dl-cache.h | 54 ++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/riscv/dl-cache.h b/sysdeps/unix/sysv/linux/riscv/dl-cache.h
index c297dfe84f..331e6015f4 100644
--- a/sysdeps/unix/sysv/linux/riscv/dl-cache.h
+++ b/sysdeps/unix/sysv/linux/riscv/dl-cache.h
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <ldconfig.h>
+#include <assert.h>
 
 /* For now we only support the natural XLEN ABI length on all targets, so the
    only bits that need to go into ld.so.cache are the FLEG ABI length.  */
@@ -34,6 +35,8 @@
    RISC-V, libraries can be found in paths ending in:
      - /lib64/lp64d
      - /lib64/lp64
+     - /lib32/ilp32d
+     - /lib32/ilp32
      - /lib (only ld.so)
    so this will add all of those paths.
 
@@ -48,27 +51,46 @@
 #define add_system_dir(dir) 						\
   do							    		\
     {									\
+      static const char* lib_dirs[] = {					\
+	"/lib64/lp64d",							\
+	"/lib64/lp64",							\
+	"/lib32/ilp32d",						\
+	"/lib32/ilp32",							\
+	NULL,								\
+      };								\
+      const size_t lib_len = sizeof ("/lib") - 1;			\
       size_t len = strlen (dir);					\
-      char path[len + 9];						\
+      char path[len + 10];						\
+      const char **ptr;							\
+									\
       memcpy (path, dir, len + 1);					\
-      if (len >= 12 && ! memcmp(path + len - 12, "/lib64/lp64d", 12))	\
+									\
+      for (ptr = lib_dirs; *ptr != NULL; ptr++)				\
 	{								\
-	  len -= 8;							\
-	  path[len] = '\0';						\
-	}								\
-      if (len >= 11 && ! memcmp(path + len - 11, "/lib64/lp64", 11))	\
-	{								\
-	  len -= 7;							\
-	  path[len] = '\0';						\
+	  const char *lib_dir = *ptr;					\
+	  size_t dir_len = strlen (lib_dir);				\
+									\
+	  if (len >= dir_len						\
+	      && !memcmp (path + len - dir_len, lib_dir, dir_len))	\
+	    {								\
+	      len -= dir_len - lib_len;					\
+	      path[len] = '\0';						\
+	      break;							\
+	    }								\
 	}								\
       add_dir (path);							\
-      if (len >= 4 && ! memcmp(path + len - 4, "/lib", 4))		\
-	{								\
-	  memcpy (path + len, "64/lp64d", 9);				\
-	  add_dir (path);						\
-	  memcpy (path + len, "64/lp64", 8);				\
-	  add_dir (path);						\
-	}								\
+      if (len >= lib_len						\
+	  && !memcmp (path + len - lib_len, "/lib", lib_len))		\
+	for (ptr = lib_dirs; *ptr != NULL; ptr++)			\
+	  {								\
+	    const char *lib_dir = *ptr;					\
+	    size_t dir_len = strlen (lib_dir);				\
+									\
+	    assert (dir_len >= lib_len);				\
+	    memcpy (path + len, lib_dir + lib_len,			\
+		    dir_len - lib_len + 1);				\
+	    add_dir (path);						\
+	  }								\
     } while (0)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-27 18:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 18:36 [glibc] RISC-V: Add path of library directories for the 32-bit Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).