[PATCH v3 07/19] RISC-V: Add path of library directories for the 32-bit

Alistair Francis alistair.francis@wdc.com
Sun Jul 12 15:47:39 GMT 2020


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_di () 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.
---
 sysdeps/unix/sysv/linux/riscv/dl-cache.h | 39 +++++++++++++++++-------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/riscv/dl-cache.h b/sysdeps/unix/sysv/linux/riscv/dl-cache.h
index b3cda4ef9f..7317406036 100644
--- a/sysdeps/unix/sysv/linux/riscv/dl-cache.h
+++ b/sysdeps/unix/sysv/linux/riscv/dl-cache.h
@@ -30,10 +30,12 @@
   ((flags) == _DL_CACHE_DEFAULT_ID)
 
 /* If given a path to one of our library directories, adds every library
-   directory via add_dir (), otherwise just adds the giver directory.  On
+   directory via add_dir (), otherwise just adds the given directory.  On
    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.
 
@@ -45,25 +47,40 @@
 	 architectures and have that automatically imply /usr/local/lib64/lp64d
 	 etc. so that libraries can be found that come from software that does
 	 use the ABI-specific directories.  */
+
 #define add_system_dir(dir) 									\
   do							    					\
     {												\
+	static const char* lib_dirs[] = {							\
+		"/lib64/lp64d",									\
+		"/lib64/lp64",									\
+		"/lib32/ilp32d",								\
+		"/lib32/ilp32",									\
+		NULL,										\
+	};											\
 	size_t len = strlen (dir);								\
-	char path[len + 9];									\
+	char path[len + 10];									\
 	memcpy (path, dir, len + 1);								\
-	if (len >= 12 && ! memcmp(path + len - 12, "/lib64/lp64d", 12))				\
-	{											\
-	  len -= 8;										\
-	  path[len] = '\0';									\
-	}											\
-	if (len >= 11 && ! memcmp(path + len - 11, "/lib64/lp64", 11))				\
-	{											\
-	  len -= 7;										\
-	  path[len] = '\0';									\
+	int i = 0;										\
+	const char* lib_dir = lib_dirs[0];								\
+												\
+	while (lib_dir != NULL) {								\
+		size_t dir_len = strlen (lib_dir);						\
+		if (len >= dir_len && ! memcmp(path + len - dir_len, lib_dir, dir_len)) {	\
+			len -= dir_len + 4;							\
+			path[len] = '\0';							\
+			break;									\
+		}										\
+		i++;										\
+		lib_dir = lib_dirs[i];								\
 	}											\
 	add_dir (path);										\
 	if (len >= 4 && ! memcmp(path + len - 4, "/lib", 4))					\
 	{											\
+	  memcpy (path + len, "32/ilp32d", 10);							\
+	  add_dir (path);									\
+	  memcpy (path + len, "32/ilp32", 9);							\
+	  add_dir (path);									\
 	  memcpy (path + len, "64/lp64d", 9);							\
 	  add_dir (path);									\
 	  memcpy (path + len, "64/lp64", 8);							\
-- 
2.27.0



More information about the Libc-alpha mailing list