From patchwork Wed Nov 17 21:03:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47852 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 471B13858409 for ; Wed, 17 Nov 2021 21:04:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 471B13858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637183093; bh=4O+4WPHE5mpBQPA5argGrDEzNah5Q77okRV2fbMmjm4=; 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=sKkULiVyv2FcRj9L3wpSaDBufHOmAwoJh4isAdSEGfUuQQYGfzSYXbfFLSiaGw1ql kj1HBiX/iR08vI0rfPW6Lb1SpqFRD6DchjCjOPWAJwACdIZtj24QyeDsy2u8zeLnMG h+ippMbkTAnovKfHU9echN0lY9C+zwRMsl/Y0XHY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id ACAA2385840C for ; Wed, 17 Nov 2021 21:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACAA2385840C Received: by mail-wm1-x32c.google.com with SMTP id p18so3405593wmq.5 for ; Wed, 17 Nov 2021 13:03:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=4O+4WPHE5mpBQPA5argGrDEzNah5Q77okRV2fbMmjm4=; b=H3a/FWLgNAhIeE+OjvizT7z9iNw+PQQZ23wR136Wau5I9Aif7z1vUlnjzHGlJWdy++ TySoXAw5luCRmoHcW0kKDfZXha6U0LjKYtvPYEmadFI8A1xq3hke45pro+nG4877c/T0 At46acFW/kt9cliWVOjRqrUoNfpnzZuIG6E7XOC/7NMwESPYTzREcnp8VDlzCbFNe0x3 +QloNk4VwpEU+S2WvbBoRht6BytiuvSZZj7J8jxgDhoWf1KrX40d9SKj8uz6UnSax0+K h+9mU/ANGCKfPWIu6SHJOGzN85DF9tnj0Sst/vMnhDPYVg/oR/hHuHD+xi2T5zsgpK61 gDqQ== X-Gm-Message-State: AOAM5313EcTFONLCM/xcXBpxiNWjUP0ts4iVoVOnykxiiMdPEAE7Sgko YTLDPIFm5eLUlFAcqFMd0917IEUWWps= X-Google-Smtp-Source: ABdhPJw5Fl9r4IqdsgCJSZRsEV5iNc4nZg+Ebn1R3izG7Oa+yKi74+LTnDUnBxgCUncAbYoCyoKPLA== X-Received: by 2002:a05:600c:1d97:: with SMTP id p23mr3283177wms.144.1637183006823; Wed, 17 Nov 2021 13:03:26 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id m17sm945118wrz.22.2021.11.17.13.03.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 13:03:26 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/4] Darwin : Handle rpaths given on the command line. Date: Wed, 17 Nov 2021 21:03:17 +0000 Message-Id: <20211117210319.92514-3-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211117210319.92514-2-iain@sandoe.co.uk> References: <20211117210319.92514-1-iain@sandoe.co.uk> <20211117210319.92514-2-iain@sandoe.co.uk> MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , joseph@codesourcery.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" We want to produce a situation where a default rpath can be added to each executable (or dylib), but that can be overridden by any specific rpath provided by the user. gcc/ChangeLog: * config.gcc: Include rpath.opt * config/darwin-driver.c (darwin_driver_init): Detect cases where the user has added rpaths via a -Wl or -Xlinker command and suppress default rpaths in that case. * config/darwin.h (DRIVER_SELF_SPECS): Handle -rpath. (DARWIN_RPATH_SPEC): New. * config/darwin.opt: Add nodefaultrpath option. --- gcc/config/darwin-driver.c | 18 ++++++++++++++++++ gcc/config/darwin.h | 11 ++++++++++- gcc/config/darwin.opt | 4 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c index 4f0c6bad61f..ccc288f20ce 100644 --- a/gcc/config/darwin-driver.c +++ b/gcc/config/darwin-driver.c @@ -281,6 +281,7 @@ darwin_driver_init (unsigned int *decoded_options_count, const char *vers_string = NULL; bool seen_version_min = false; bool seen_sysroot_p = false; + bool seen_rpath_p = false; for (i = 1; i < *decoded_options_count; i++) { @@ -349,6 +350,13 @@ darwin_driver_init (unsigned int *decoded_options_count, seen_sysroot_p = true; break; + case OPT_Xlinker: + case OPT_Wl_: + gcc_checking_assert ((*decoded_options)[i].arg); + if (strncmp ((*decoded_options)[i].arg, "-rpath", 6) == 0) + seen_rpath_p = true; + break; + default: break; } @@ -474,4 +482,14 @@ darwin_driver_init (unsigned int *decoded_options_count, &(*decoded_options)[*decoded_options_count - 1]); } } + + if (seen_rpath_p) + { + ++*decoded_options_count; + *decoded_options = XRESIZEVEC (struct cl_decoded_option, + *decoded_options, + *decoded_options_count); + generate_option (OPT_nodefaultrpath, NULL, 1, CL_DRIVER, + &(*decoded_options)[*decoded_options_count - 1]); + } } diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 7ed01efa694..4423933890b 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -384,6 +384,7 @@ extern GTY(()) int darwin_ms_struct; DARWIN_NOPIE_SPEC \ DARWIN_RDYNAMIC \ DARWIN_NOCOMPACT_UNWIND \ + "%{!r:%{!nostdlib:%{!rpath:%{!nodefaultrpath:%(darwin_rpaths)}}}} " \ "}}}}}}} % 10.5 mmacosx-version-min= -lcrt1.o) \ @@ -542,6 +544,13 @@ extern GTY(()) int darwin_ms_struct; "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \ %{fgnu-tm: -lcrttms.o}}" +/* A default rpath, that picks up dependent libraries installed in the same + director as one being loaded. */ +#define DARWIN_RPATH_SPEC \ + "%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ + %:version-compare(>= 10.5 mmacosx-version-min= @loader_path) \ + %P " + #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION /* Emit macosx version (but only major). */ #define ASM_MMACOSX_VERSION_MIN_SPEC \ diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt index d1d1f816912..021d67b17c7 100644 --- a/gcc/config/darwin.opt +++ b/gcc/config/darwin.opt @@ -233,6 +233,10 @@ no_dead_strip_inits_and_terms Driver RejectNegative (Obsolete) Current linkers never dead-strip these items, so the option is not needed. +nodefaultrpath +Driver RejectNegative +Do not add a default rpath to executables, modules or dynamic libraries. + nofixprebinding Driver RejectNegative (Obsolete after 10.3.9) Set MH_NOPREFIXBINDING, in an executable.