From patchwork Fri Apr 21 06:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1771690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mBks2TLI; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q2lTD20Dpz23rW for ; Fri, 21 Apr 2023 16:47:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7320F385842D for ; Fri, 21 Apr 2023 06:47:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7320F385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682059659; bh=xtqlIqsLb0mQBognY90GUnJvScFr6sleTHkoa5rLGR4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mBks2TLIPw3CQD6RWN1gXHGCQznrKXpLglAhixZOo7e2PIclwz0lGBonl+sVluPir qsZtOKM/MIBXJeYKY/ez6kRHQlCg0nJCbY5FcRoQ/+ueyu7mretekGjp/G9KdvQJh9 uDgmtrKSu/slyeEynbDW0Akq9nccXFnMFwX00pzo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 8F47B3858D20 for ; Fri, 21 Apr 2023 06:47:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F47B3858D20 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1a92369761cso16732975ad.3 for ; Thu, 20 Apr 2023 23:47:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682059637; x=1684651637; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xtqlIqsLb0mQBognY90GUnJvScFr6sleTHkoa5rLGR4=; b=k3Bwj1fGsq6lvY0zXDzfv6L3o/EDrozW6Nq3sJGXWwA+o2WHINmhYpz8eRZn5KZlFq 2OOkJ7NYJMJsuNislfj3L+65ksGGA8f4y/2ZXUqA2ttgh6S7dmHV4b7dGtwGje0nNQq2 1Vep9E29VZ+5UbYYZt1tCCTVh7bKCYAxBR+5/SmJB2j1xsmSAjCbhYHyHrToUycdtMKi QAX19X1Jq+ypL/D1enps93rWburthr6VWeYEwlGrIZPeCxibi0bfHQQr7ubXQqKjniH2 a8gkurXXU2iyT//HQAhpHK4HM7cLNR+66wXRM9RKiyr2T/Im3wCBfwv2zg3t4aT82eGq kbMQ== X-Gm-Message-State: AAQBX9erukPlG2Mnd0hiao3/WztHs4JRg8Wd3JQUbwtvfa9OMui/ssR/ /df/eAj47nhUkFGbtcZj3o1/JqF1gVBQ3wzclK82rahEnQ5EI89syJBUnQTiQJJDWWy1w+rPlH8 gIzr+OxV4ko6itT5zfPVMSLZluT518G7Snv8fDwlrpQ0ITZtzTHg7nFHehQhAkVq7VQv9bTJpQD bRbMs= X-Google-Smtp-Source: AKy350aJFkdrIp1kyjo2MynSez9nKuPafc12abJVlPdSxkepHtF7WZ3iWWlkHUO6IJJC92sthV3gig== X-Received: by 2002:a17:902:f1d1:b0:1a6:47aa:dbd7 with SMTP id e17-20020a170902f1d100b001a647aadbd7mr3555161plc.53.1682059636479; Thu, 20 Apr 2023 23:47:16 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id m3-20020a170902c44300b0019abd4ddbf2sm2084064plm.179.2023.04.20.23.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 23:47:15 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Kito Cheng Subject: [committed v2] RISC-V: Handle multi-lib path correclty for linux [DRAFT] Date: Fri, 21 Apr 2023 14:47:12 +0800 Message-Id: <20230421064712.60139-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kito Cheng via Gcc-patches From: Kito Cheng Reply-To: Kito Cheng Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" --- gcc/common/config/riscv/riscv-common.cc | 118 ++++++++++++++++-------- gcc/config/riscv/linux.h | 13 ++- 2 files changed, 90 insertions(+), 41 deletions(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 309a52def75f..75bfe198d4c6 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -1597,6 +1597,73 @@ riscv_check_conds ( return match_score + ok_count * 100; } +static const char * +riscv_select_multilib_by_abi ( + const std::string &riscv_current_arch_str, + const std::string &riscv_current_abi_str, + const riscv_subset_list *subset_list, + const struct switchstr *switches, + int n_switches, + const std::vector &multilib_infos + ) +{ + for (size_t i = 0; i < multilib_infos.size (); ++i) + if (riscv_current_abi_str == multilib_infos[i].abi_str) + return xstrdup (multilib_infos[i].path.c_str ()); + + return NULL; +} + + +static const char * +riscv_select_multilib ( + const std::string &riscv_current_arch_str, + const std::string &riscv_current_abi_str, + const riscv_subset_list *subset_list, + const struct switchstr *switches, + int n_switches, + const std::vector &multilib_infos + ) +{ + int match_score = 0; + int max_match_score = 0; + int best_match_multi_lib = -1; + /* Try to decision which set we should used. */ + /* We have 3 level decision tree here, ABI, check input arch/ABI must + be superset of multi-lib arch, and other rest option checking. */ + for (size_t i = 0; i < multilib_infos.size (); ++i) + { + /* Check ABI is same first. */ + if (riscv_current_abi_str != multilib_infos[i].abi_str) + continue; + + /* Found a potential compatible multi-lib setting! + Calculate the match score. */ + match_score = subset_list->match_score (multilib_infos[i].subset_list); + + /* Checking other cond in the multi-lib setting. */ + match_score = riscv_check_conds (switches, + n_switches, + match_score, + multilib_infos[i].conds); + + /* Record highest match score multi-lib setting. */ + if (match_score > max_match_score) + { + best_match_multi_lib = i; + max_match_score = match_score; + } + } + + if (best_match_multi_lib == -1) + { + riscv_no_matched_multi_lib = true; + return NULL; + } + else + return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ()); +} + /* Implement TARGET_COMPUTE_MULTILIB. */ static const char * riscv_compute_multilib ( @@ -1621,6 +1688,12 @@ riscv_compute_multilib ( std::string option_cond; riscv_multi_lib_info_t multilib_info; + bool check_abi_only = false; + +#if TARGET_LINUX == 1 + check_abi_only = true; +#endif + /* Already found suitable, multi-lib, just use that. */ if (multilib_dir != NULL) return multilib_dir; @@ -1672,7 +1745,11 @@ riscv_compute_multilib ( } this_path_len = p - this_path; - multilib_info.path = std::string (this_path, this_path_len); + const char *multi_os_dir_pos = (const char*)memchr (this_path, ':', this_path_len); + if (multi_os_dir_pos) + multilib_info.path = std::string (this_path, multi_os_dir_pos - this_path); + else + multilib_info.path = std::string (this_path, this_path_len); option_conds.clear (); /* Pasrse option check list into vector. @@ -1707,43 +1784,10 @@ riscv_compute_multilib ( p++; } - int match_score = 0; - int max_match_score = 0; - int best_match_multi_lib = -1; - /* Try to decision which set we should used. */ - /* We have 3 level decision tree here, ABI, check input arch/ABI must - be superset of multi-lib arch, and other rest option checking. */ - for (size_t i = 0; i < multilib_infos.size (); ++i) - { - /* Check ABI is same first. */ - if (riscv_current_abi_str != multilib_infos[i].abi_str) - continue; - - /* Found a potential compatible multi-lib setting! - Calculate the match score. */ - match_score = subset_list->match_score (multilib_infos[i].subset_list); - - /* Checking other cond in the multi-lib setting. */ - match_score = riscv_check_conds (switches, - n_switches, - match_score, - multilib_infos[i].conds); - - /* Record highest match score multi-lib setting. */ - if (match_score > max_match_score) - { - best_match_multi_lib = i; - max_match_score = match_score; - } - } - - if (best_match_multi_lib == -1) - { - riscv_no_matched_multi_lib = true; - return multilib_dir; - } + if (check_abi_only) + return riscv_select_multilib_by_abi (riscv_current_arch_str, riscv_current_abi_str, subset_list, switches, n_switches, multilib_infos); else - return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ()); + return riscv_select_multilib (riscv_current_arch_str, riscv_current_abi_str, subset_list, switches, n_switches, multilib_infos); } #undef TARGET_COMPUTE_MULTILIB diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h index b9557a75dc72..46256f78e5df 100644 --- a/gcc/config/riscv/linux.h +++ b/gcc/config/riscv/linux.h @@ -72,7 +72,12 @@ along with GCC; see the file COPYING3. If not see #define TARGET_ASM_FILE_END file_end_indicate_exec_stack #define STARTFILE_PREFIX_SPEC \ - "/lib" XLEN_SPEC "/" ABI_SPEC "/ " \ - "/usr/lib" XLEN_SPEC "/" ABI_SPEC "/ " \ - "/lib/ " \ - "/usr/lib/ " + "%{mabi=lp64d: /lib64/lp64d/ /usr/lib64/lp64d/ /lib/ /usr/lib/}" \ + "%{mabi=lp64f: /lib64/lp64f/ /usr/lib64/lp64f/ /lib/ /usr/lib/}" \ + "%{mabi=lp64: /lib64/lp64/ /usr/lib64/lp64/ /lib/ /usr/lib/}" \ + "%{mabi=ilp32d: /lib32/ilp32d /usr/lib32/ilp32d/ /lib/ /usr/lib/}" \ + "%{mabi=ilp32f: /lib32/ilp32f/ /usr/lib32/ilp32f/ /lib/ /usr/lib/}" \ + "%{mabi=ilp32: /lib32/ilp32/ /usr/lib32/ilp32/ /lib/ /usr/lib/}" + +#define RISCV_USE_CUSTOMISED_MULTI_LIB 1 +#define TARGET_LINUX 1