From patchwork Wed Aug 19 15:38:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1347903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=H701a7sg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BWsfH39XXz9sPB for ; Thu, 20 Aug 2020 01:49:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B219A386F807; Wed, 19 Aug 2020 15:49:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B219A386F807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1597852146; bh=bihl4EY/tx2nMqOwwpRbmv6JfkaDVRsmlTSfL6/HJvI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=H701a7sgPiMk1w8LJE54eKniUKVqN2eaty9TsgLyDedIyv2SvMIYxWTQUHmQxDT+q inS5v2iQav2HGy/5Qal2kUnV/xc2XY4+lwF9urAodEWB3dmiYtXlLIZFq7J3t8Eez5 M0b4nGLMgAeULRRu2VzvFyrGY9y0ChfX0+0/f8oI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by sourceware.org (Postfix) with ESMTPS id 98C6C386F810 for ; Wed, 19 Aug 2020 15:49:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 98C6C386F810 IronPort-SDR: 4xF0JBgAUR7gFZixdAYBb81QNq2Y2kbFl0LaBCMj/rpkCouTAVBCJQLw2Rb0XHsULaziSnCOuO /SKhZEvOz2ku0H4gd6SqZm1oSkL48BUgkaBgGn0xmpI5a5JTLtbEexczpLqtZz7O3Zf6RE+OzE Tlqpje4PN6R9z6Rgd7HX6GNqMJk8l8Ovuy8kFe/HyHRIMt84xjLXFXP5maegTUkoywVI5GQ2lu Ue979Yip+lhGmsjxFJPQl+U9CZ0foOz/+mcq0leUVBkXqNp/+Se775WCWncKCjJmoVkBy3/k4P uik= X-IronPort-AV: E=Sophos;i="5.76,331,1592841600"; d="scan'208";a="254766946" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2020 23:49:03 +0800 IronPort-SDR: lhMm+iaxmof+/lQllr+aGHX0Dpx0YpgXs1meZ56jFKN2HW11PpvAMODO4etThgzPlG0cy5eI5T AXXKuyx8axzw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2020 08:36:01 -0700 IronPort-SDR: gmQmttowMQWzjaCz/vD7Kg2FRS85D0jiDUHtMsXWjmbdSTNm1JHErmcSGqnJRmNHXhZtMfQbz1 G/i8R4Li/BeA== WDCIronportException: Internal Received: from lpt-kalia-a.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.59.58]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Aug 2020 08:49:02 -0700 To: libc-alpha@sourceware.org Subject: [PATCH v5 06/17] RISC-V: Add path of library directories for the 32-bit Date: Wed, 19 Aug 2020 08:38:54 -0700 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alistair Francis via Libc-alpha From: Alistair Francis Reply-To: Alistair Francis Cc: alistair.francis@wdc.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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 --- 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 @@ . */ #include +#include /* 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)