From patchwork Tue May 1 18:52:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 907169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477068-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TLdm2xVj"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40b9Wz2sGFz9ryk for ; Wed, 2 May 2018 04:52:44 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=A47kEihiozzt vB2047Rg8KYkHUr1/mpnWcSTimeGiZXPIblBlURDTHGs87N32BTGjir+J6dt2nbd czTNGFv0w9ig4N3zcSO86YesOCieFkfkPMKnIiv7osH2cfxbjixxLzS8DWB2TKK4 BQP3HkhGpXsroqYL5xPTFAATRuk5T4Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=fXfkHrNeGbpmxSUWkC b7hoL9VMw=; b=TLdm2xVjnyHPqVZ+m1pbPkmhQVuCqwwwD2IvouILtlVhT5Jp6A Y/M3uC67x3vv/2oCTT9yL9fmJpP5vIIVeep26l9A4n8dc1TfTKLnNIBnnfx6vWfZ lpJ/b7J69/bJUi8sDFuzDfejK6rkGQ35Bt8NrI00RHlVYqx7GtD2vA07Y= Received: (qmail 35673 invoked by alias); 1 May 2018 18:52:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 35654 invoked by uid 89); 1 May 2018 18:52:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=gap, H*r:sk:z129-v6, jim, mabi X-HELO: mail-pg0-f46.google.com Received: from mail-pg0-f46.google.com (HELO mail-pg0-f46.google.com) (74.125.83.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 May 2018 18:52:34 +0000 Received: by mail-pg0-f46.google.com with SMTP id z129-v6so4673887pgz.3 for ; Tue, 01 May 2018 11:52:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JzN72e1OtjinCzF2/LUTSrZUUL0mgqVPAAV+1NUjHkU=; b=uObqTum+8bjona/RITBZF5T7Xsz8tsNhxCH7wIOyuR22zSQPvgdwl3OxIx0X99Hg3c 7kFxduxjEwUIdPZ+EyyKb3avS570MX29lFyppnIDazRbIZzYz6tC9IJyFfzihW/+xCL3 8AefVUDjfBnIYhtLo2aD6UHejtHLFYv8Rpeax67y0lLGUAQ6Nb3v8RsPbAIXG41qOXfi hFdRkmkeSSlLqWvJqG8G8s+AIhNLwB4ZIIoTD2QU6eHnrm++foEwEadsJdxGvP+fISen ZnwoIzTLtzubXM3M1B8TTiHLo3/+kb1YhPHJNdvabqnkkqggxbn1ziV1lk/63TpOSmBb HRiA== X-Gm-Message-State: ALQs6tCs4cr5FMS15kPVx0BzWv+EwPf3Y8sUcEQx3T3czNGPUvBGu7EH WEKuJYCt6F0SGupqzaUyV8M42JbYYn8= X-Google-Smtp-Source: AB8JxZo3+zgpmusMACSrGjY/uEOcnz1bRUFOrBDlheVek6M6mqpg7xrgilUjdZGpIWVEvWvx1iG6gw== X-Received: by 2002:a65:4c82:: with SMTP id m2-v6mr14002774pgt.23.1525200752374; Tue, 01 May 2018 11:52:32 -0700 (PDT) Received: from rohan.internal.sifive.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id h18sm6084576pfi.133.2018.05.01.11.52.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 11:52:31 -0700 (PDT) From: Jim Wilson To: gcc-patches@gcc.gnu.org Cc: Jim Wilson Subject: [PATCH] RISC-V: Add with-multilib-list support. Date: Tue, 1 May 2018 11:52:28 -0700 Message-Id: <20180501185228.5298-1-jimw@sifive.com> This is an attempt to solve a packaging problem for linux distros. If the RISC-V port is built with --disable-multilib, libraries get installed into /lib which violates the ABI. If it is built with --enable-multilib, 32 versions of libraries are built which is useful for embedded linux cross compiler testing, but not useful for a native linux compiler. This adds support for the --with-multilib-list configure option to bridge the gap, to allow one to build a compiler with multilibs enabled, but without building all 32 default multilibs. Unfortunately, the RISC-V port is complicated in that ABI selection depends on two options, -march and -mabi, instead of one as usual. We also have a lot of different arch and abi options, some of which are aliases of others. This complicates the implementation, so for the moment, I'm only allowing one ABI in the list, and a few arch choices. This can be expanded later as necessary. I posting this before committing it in case anyone wants to comment on it. I've tested it with cross compiler build and make check, and a native build, and it appears to work correctly for me. But I'm not a distro person, so I can't easily verify that it fixes the problem that the distro people are having. Jim gcc/ PR target/84797 * config.gcc (riscv*-*-*): Handle --with-multilib-list. * config/riscv/t-withmultilib: New. * config/riscv/withmultilib.h: New. * doc/install.texi: Document RISC-V --with-multilib-list support. --- gcc/config.gcc | 52 +++++++++++++++++++++++++++++++++++++++++ gcc/config/riscv/t-withmultilib | 6 +++++ gcc/config/riscv/withmultilib.h | 51 ++++++++++++++++++++++++++++++++++++++++ gcc/doc/install.texi | 11 +++++++-- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 gcc/config/riscv/t-withmultilib create mode 100644 gcc/config/riscv/withmultilib.h diff --git a/gcc/config.gcc b/gcc/config.gcc index a5defb0f005..1700ef002a5 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -4129,6 +4129,58 @@ case "${target}" in exit 1 ;; esac + + # Handle --with-multilib-list. + if test "x${with_multilib_list}" != xdefault; then + tm_file="${tm_file} riscv/withmultilib.h" + tmake_file="${tmake_file} riscv/t-withmultilib" + + case ${with_multilib_list} in + ilp32 | ilp32f | ilp32d \ + | lp64 | lp64f | lp64d ) + TM_MULTILIB_CONFIG="${with_arch},${with_multilib_list}" + ;; + *) + echo "--with-multilib-list=${with_multilib_list} not supported." + exit 1 + esac + + # Define macros to select the default multilib. + case ${with_arch} in + rv32gc) + tm_defines="${tm_defines} TARGET_MLIB_ARCH=1" + ;; + rv64gc) + tm_defines="${tm_defines} TARGET_MLIB_ARCH=2" + ;; + *) + echo "unsupported --with-arch for --with-multilib-list" + exit 1 + esac + case ${with_abi} in + ilp32) + tm_defines="${tm_defines} TARGET_MLIB_ABI=1" + ;; + ilp32f) + tm_defines="${tm_defines} TARGET_MLIB_ABI=2" + ;; + ilp32d) + tm_defines="${tm_defines} TARGET_MLIB_ABI=3" + ;; + lp64) + tm_defines="${tm_defines} TARGET_MLIB_ABI=4" + ;; + lp64f) + tm_defines="${tm_defines} TARGET_MLIB_ABI=5" + ;; + lp64d) + tm_defines="${tm_defines} TARGET_MLIB_ABI=6" + ;; + *) + echo "unsupported --with-abi for --with-multilib" + exit 1 + esac + fi ;; mips*-*-*) diff --git a/gcc/config/riscv/t-withmultilib b/gcc/config/riscv/t-withmultilib new file mode 100644 index 00000000000..bcd0845b448 --- /dev/null +++ b/gcc/config/riscv/t-withmultilib @@ -0,0 +1,6 @@ +comma=, +MULTILIB_OPTIONS = $(subst lp64,mabi=lp64,$(subst ilp32,mabi=ilp32,$(subst rv,march=rv,$(subst $(comma), ,$(TM_MULTILIB_CONFIG))))) +MULTILIB_DIRNAMES = $(patsubst rv32%,lib32,$(patsubst rv64%,lib64,$(subst $(comma), ,$(TM_MULTILIB_CONFIG)))) +MULTILIB_OSDIRNAMES = $(subst lib,../lib,$(MULTILIB_DIRNAMES)) +MULTILIB_REQUIRED = $(subst lp64,mabi=lp64,$(subst ilp32,mabi=ilp32,$(subst rv,march=rv,$(subst $(comma),/,$(TM_MULTILIB_CONFIG))))) +MULTILIB_REUSE = diff --git a/gcc/config/riscv/withmultilib.h b/gcc/config/riscv/withmultilib.h new file mode 100644 index 00000000000..d703147fa64 --- /dev/null +++ b/gcc/config/riscv/withmultilib.h @@ -0,0 +1,51 @@ +/* MULTILIB_DEFAULTS definitions for --with-multilib-list. + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#if TARGET_MLIB_ARCH == 1 + +# if TARGET_MLIB_ABI == 1 +# define MULTILIB_DEFAULTS {"march=rv32gc", "mabi=ilp32" } +# elif TARGET_MLIB_ABI == 2 +# define MULTILIB_DEFAULTS {"march=rv32gc", "mabi=ilp32f" } +# elif TARGET_MLIB_ABI == 3 +# define MULTILIB_DEFAULTS {"march=rv32gc", "mabi=ilp32d" } +# else +# error "unsupported TARGET_MLIB_ABI value for rv32gc" +# endif + +#elif TARGET_MLIB_ARCH == 2 + +# if TARGET_MLIB_ABI == 4 +# define MULTILIB_DEFAULTS {"march=rv64gc", "mabi=lp64" } +# elif TARGET_MLIB_ABI == 5 +# define MULTILIB_DEFAULTS {"march=rv64gc", "mabi=lp64f" } +# elif TARGET_MLIB_ABI == 6 +# define MULTILIB_DEFAULTS {"march=rv64gc", "mabi=lp64d" } +# else +# error "unsupported TARGET_MLIB_ABI value for rv64gc" +# endif + +#else +# error "unsupported TARGET_MLIB_ARCH value" +#endif diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index ec20fd26685..7c5cdc762d3 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1072,8 +1072,8 @@ sysv, aix. @itemx --without-multilib-list Specify what multilibs to build. @var{list} is a comma separated list of values, possibly consisting of a single value. Currently only implemented -for arm*-*-*, sh*-*-* and x86-64-*-linux*. The accepted values and meaning -for each target is given below. +for arm*-*-*, riscv*-*-*, sh*-*-* and x86-64-*-linux*. The accepted +values and meaning for each target is given below. @table @code @item arm*-*-* @@ -1128,6 +1128,13 @@ and @code{rmprofile}. @code{-mfloat-abi=hard} @end multitable +@item riscv*-*-* +@var{list} is a single ABI name. The target architecture must be either +@code{rv32gc} or @code{rv64gc}. This will build a single multilib for the +specified architecture and ABI pair. If @code{--with-multilib-list} is not +given, then a default set of multilibs is selected based on the value of +@option{--target}. This is usually a large set of multilibs. + @item sh*-*-* @var{list} is a comma separated list of CPU names. These must be of the form @code{sh*} or @code{m*} (in which case they match the compiler option