From patchwork Wed Nov 17 21:03:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47851 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 6B50D385800C for ; Wed, 17 Nov 2021 21:03:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B50D385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637183036; bh=5nnkABHZJrYH7T/9UghblzzDjrXnp1kZqu/2IyIeFwk=; 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=COoU1MdehFu6zb10z+lnJyfNMUyizAHVFRYgTwlp5xnxvxPIwLPRaP77LHrKhsWfJ 62tkroO2jWuxoDq/UCk4Wim+TY6ApG6k9Fr67bmGXOw6WfRkri2OPwGr5/6pcav7Z/ +lf/FVRTYXtwTWCiccyLzekaNJd9ovNWBkDwPwDw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 71D883858409 for ; Wed, 17 Nov 2021 21:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71D883858409 Received: by mail-wm1-x334.google.com with SMTP id 137so467106wma.1 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=5nnkABHZJrYH7T/9UghblzzDjrXnp1kZqu/2IyIeFwk=; b=ZOm8px98525L/w93zg1cRdzM1fvX5UrxH2DwfCr9x5UBhxxcq2MoI8DYPpPUq30tqZ GPuCOx05QRArc+Ju6N/3NhhERW23q0BFxyCsWOvm5kg0zGpbpNwJ+EkAdWGO1IhNNMZj C2P9kUZJ/5iij/1ih8rJ7rhs/imR4mf6+ieNxTOBpZuD0k2VzZrYbfB8l77glpHYcDjb 1vZeaGeRmMLYmlZkTaZHbLksnPx49lbLuHWDXDE+iawUEPzSiCTBAnEPsnYB+wwKHQHe gWMEP3vS1gok1atPIaUqISaTodc1mcUWGlTJd26YPG4b1/M6D28U4pwiguloDUJ2CSD3 pOFA== X-Gm-Message-State: AOAM533W2Dojhk1gCnWAIdDqFjkCBUGBSWG1naql/OB0mXzDT4cJz5dL /Qr0SJduRBAGSatXacRsjwPO9buJXp0= X-Google-Smtp-Source: ABdhPJwagY3b6lQqG+IHP4Bru/SD7kEjtkF8qgCI3HCJkcPrhAL+NteN9eXDyTPmN6lJtt/1PVwwKA== X-Received: by 2002:a7b:c7cb:: with SMTP id z11mr3292795wmk.152.1637183006279; 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.25 (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 1/4] Driver : Provide a spec to insert rpaths for compiler lib dirs. Date: Wed, 17 Nov 2021 21:03:16 +0000 Message-Id: <20211117210319.92514-2-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211117210319.92514-1-iain@sandoe.co.uk> References: <20211117210319.92514-1-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" This provides a spec to insert "-rpath DDD" for each DDD corresponding to a compiler startfile directory. This allows a target to use @rpath as the install path for libraries, and have the compiler provide the necessary rpath to handle this. gcc/ChangeLog: * gcc.c (RUNPATH_OPTION): New. (do_spec_1): Provide '%P' as a spec to insert rpaths for each compiler startfile path. --- gcc/gcc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gcc/gcc.c b/gcc/gcc.c index 506c2acc282..7b52d0bcbfd 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -572,6 +572,7 @@ or with constant text in a single argument. %l process LINK_SPEC as a spec. %L process LIB_SPEC as a spec. %M Output multilib_os_dir. + %P Output a RUNPATH_OPTION for each directory in startfile_prefixes. %G process LIBGCC_SPEC as a spec. %R Output the concatenation of target_system_root and target_sysroot_suffix. @@ -1191,6 +1192,10 @@ proper position among the other output files. */ # define SYSROOT_HEADERS_SUFFIX_SPEC "" #endif +#ifndef RUNPATH_OPTION +# define RUNPATH_OPTION "-rpath" +#endif + static const char *asm_debug = ASM_DEBUG_SPEC; static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; static const char *cpp_spec = CPP_SPEC; @@ -6130,6 +6135,19 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) } break; + case 'P': + { + struct spec_path_info info; + + info.option = RUNPATH_OPTION; + info.append_len = 0; + info.omit_relative = false; + info.separate_options = true; + + for_each_path (&startfile_prefixes, true, 0, spec_path, &info); + } + break; + case 'e': /* %efoo means report an error with `foo' as error message and don't execute any more commands for this file. */ 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. From patchwork Wed Nov 17 21:03:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47855 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 344003858409 for ; Wed, 17 Nov 2021 21:07:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 344003858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637183271; bh=CjD1Z6eNkt494d8Unq1nAPaa+OT8SpDzFKB1DQ/LePk=; 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=xpnmaTuJcXgv2BpEfy9veCnoFVkxsONGq1uW8DWXjyxwrwA3X+brSvjTzKTFWrm5K Dj1vp7Kaw/34mC/DITGpfMAFkMntGzqSQU/DBHJQzsujiz/+4F7lMnrz5okusC81yO JwzccCDAiJfnPnpzRbZt5mpNukqdJu3AaHf2JVOI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 990F73858410 for ; Wed, 17 Nov 2021 21:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 990F73858410 Received: by mail-wr1-x430.google.com with SMTP id u1so7161615wru.13 for ; Wed, 17 Nov 2021 13:03:28 -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=CjD1Z6eNkt494d8Unq1nAPaa+OT8SpDzFKB1DQ/LePk=; b=e733Cjp5vXmbM3BZkVQaUHOu+evQBFTuaPWm8aK1h0I+qWf/2e80+ey3VJvRhwcxmX 2ZHFoZIZPpELcfapuDyhDlR9lozGoFVRgXp5xkegocfEiYwrOhKC4EFqnHFd8e26jqpn pgYNY/wSG3YCmlvDrZSZAPYg7HBiXrovtEeaF/L8oiwQfaCUEZFe0PQ20lEb8jl67NFE aDFb16ic/f+8B/LcBcu0H6Zfh+VWqlAYd3eiDBQ38/UojH92EYBBARnPiJ8UO+nPz3BT rXhh//hMc8knbRHzW1gKrHSYYUPDoN8soMs3OnSufcI5Iwdhz06gEE4RXY7vezalMXsN e25g== X-Gm-Message-State: AOAM530hkDStuLd8+d+viNbM3h+9UzzSiQ8fPii7BchneZq0+h3VOwxF cXZPRVbkFM+aIXZ+upftRgeQXu7XXMc= X-Google-Smtp-Source: ABdhPJw02N6qmjwu4+BC/y0SnemlfnK2OQ5bA9VlBmNqZl54Hq3Jbi0/gpA64F0L2D038hTrHSHyNA== X-Received: by 2002:a05:6000:15c8:: with SMTP id y8mr24692892wry.101.1637183007425; Wed, 17 Nov 2021 13:03:27 -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:27 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/4] Darwin : Allow for configuring Darwin to use embedded runpath. Date: Wed, 17 Nov 2021 21:03:18 +0000 Message-Id: <20211117210319.92514-4-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211117210319.92514-3-iain@sandoe.co.uk> References: <20211117210319.92514-1-iain@sandoe.co.uk> <20211117210319.92514-2-iain@sandoe.co.uk> <20211117210319.92514-3-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" Recent Darwin versions place contraints on the use of run paths specified in environment variables. This breaks some assumptions in the GCC build. This change allows the user to configure a Darwin build to use '@rpath/libraryname.dylib' in library names and then to add an embedded runpath to executables (and libraries with dependents). The embedded runpath is added by default unless: 1. the user adds an explicit -rpath / -Wl,-rpath,.... 2. the user adds '-nodefaultrpath'. For an installed compiler, it means that any executable built with that compiler will reference the runtimes installed with the compiler (equivalent to hard-coding the library path into the name of the library). During build-time configurations any "-B" entries will be added to the runpath thus the newly-built libraries will be found by exes. Since the install name is set in libtool, that decision needs to be available here (but might also cause dependent ones in Makefiles, so we need to export a conditional). This facility is not available for Darwin 8 or earlier, however the existing environment variable runpath does work there. We default this on for systems where the external DYLD_LIBRARY_PATH does not work and off for Darwin 8 or earlier. For systems that can use either method, if the value is unset, we use the default (which is currently DYLD_LIBRARY_PATH). ChangeLog: * configure: Regenerate. * configure.ac: Do not add default runpaths to GCC exes when we are building -static-libstdc++/-static-libgcc (the default). * libtool.m4: Add 'enable-darwin-at-runpath'. Act on the enable flag to alter Darwin libraries to use @rpath names. gcc/ChangeLog: * aclocal.m4: Regenerate. * configure: Regenerate. libatomic/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.in: Regenerate. libcc1/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libffi/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libgcc/ChangeLog: * config/t-slibgcc-darwin: Generate libgcc_s with an @rpath name. libgfortran/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Handle Darwin rpaths libgomp/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libhsail-rt/ChangeLog: * configure: Regenerate. libitm/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libobjc/ChangeLog: * configure: Regenerate. * configure.ac: Handle Darwin rpaths. liboffloadmic/ChangeLog: * configure: Regenerate. * plugin/Makefile.in: Regenerate. * plugin/aclocal.m4: Regenerate. * plugin/configure: Regenerate. libphobos/ChangeLog: * configure: Regenerate. * libdruntime/Makefile.am: Handle Darwin rpaths. * libdruntime/Makefile.in: Regenerate. * src/Makefile.am: Handle Darwin rpaths. * src/Makefile.in: Regenerate. libquadmath/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Handle Darwin rpaths. libsanitizer/ChangeLog: * asan/Makefile.am: Handle Darwin rpaths. * asan/Makefile.in: Regenerate. * configure: Regenerate. * hwasan/Makefile.am: Handle Darwin rpaths. * hwasan/Makefile.in: Regenerate. * lsan/Makefile.am: Handle Darwin rpaths. * lsan/Makefile.in: Regenerate. * tsan/Makefile.am: Handle Darwin rpaths. * tsan/Makefile.in: Regenerate. * ubsan/Makefile.am: Handle Darwin rpaths. * ubsan/Makefile.in: Regenerate. libssp/ChangeLog: * Makefile.am: Handle Darwin rpaths. * Makefile.in: Regenerate. * configure: Regenerate. libstdc++-v3/ChangeLog: * configure: Regenerate. * src/Makefile.am: Handle Darwin rpaths. * src/Makefile.in: Regenerate. Darwin, libtool : Provide a mechanism to enable embedded rpaths. We need to be able to build libraries with install names that begin with @rpath so that we can use rpaths in DSOs that depend on them. Since the install name is set in libtool, that decision needs to be available here (but might also cause dependent ones in Makefiles, so we need to export a conditional). --- configure | 5 + configure.ac | 5 + gcc/aclocal.m4 | 50 +++++++ gcc/configure | 157 +++++++++++++++++++-- libatomic/Makefile.am | 6 +- libatomic/Makefile.in | 5 +- libatomic/configure | 82 ++++++++++- libatomic/testsuite/Makefile.in | 1 + libbacktrace/configure | 80 ++++++++++- libcc1/Makefile.am | 9 ++ libcc1/Makefile.in | 12 +- libcc1/configure | 157 +++++++++++++++++++-- libffi/Makefile.am | 7 +- libffi/Makefile.in | 6 +- libffi/configure | 157 +++++++++++++++++++-- libgcc/config.host | 22 ++- libgcc/config/t-darwin-rpath | 5 + libgcc/config/t-slibgcc-darwin | 13 +- libgfortran/Makefile.am | 3 + libgfortran/Makefile.in | 30 ++-- libgfortran/configure | 155 ++++++++++++++++++-- libgfortran/configure.ac | 4 +- libgomp/Makefile.am | 6 +- libgomp/Makefile.in | 3 +- libgomp/configure | 151 ++++++++++++++++++-- libitm/Makefile.am | 5 +- libitm/Makefile.in | 3 +- libitm/configure | 171 ++++++++++++++++++++--- libobjc/configure | 96 +++++++++++-- libobjc/configure.ac | 14 +- liboffloadmic/configure | 199 +++++++++++++++++++++----- liboffloadmic/plugin/Makefile.in | 2 +- liboffloadmic/plugin/aclocal.m4 | 2 +- liboffloadmic/plugin/configure | 199 +++++++++++++++++++++----- libphobos/configure | 151 ++++++++++++++++++-- libphobos/libdruntime/Makefile.am | 5 +- libphobos/libdruntime/Makefile.in | 3 +- libphobos/src/Makefile.am | 5 +- libphobos/src/Makefile.in | 3 +- libquadmath/Makefile.am | 6 +- libquadmath/Makefile.in | 4 +- libquadmath/configure | 225 +++++++++++++++++++++++++++++- libquadmath/configure.ac | 2 + libsanitizer/asan/Makefile.am | 6 +- libsanitizer/asan/Makefile.in | 5 +- libsanitizer/configure | 157 +++++++++++++++++++-- libsanitizer/hwasan/Makefile.am | 6 +- libsanitizer/hwasan/Makefile.in | 5 +- libsanitizer/lsan/Makefile.am | 7 +- libsanitizer/lsan/Makefile.in | 6 +- libsanitizer/tsan/Makefile.am | 6 +- libsanitizer/tsan/Makefile.in | 5 +- libsanitizer/ubsan/Makefile.am | 6 +- libsanitizer/ubsan/Makefile.in | 5 +- libssp/Makefile.am | 5 +- libssp/Makefile.in | 3 +- libssp/configure | 82 ++++++++++- libstdc++-v3/configure | 169 +++++++++++++++++++--- libstdc++-v3/src/Makefile.am | 6 +- libstdc++-v3/src/Makefile.in | 3 +- libtool.m4 | 64 ++++++++- libvtv/configure | 171 ++++++++++++++++++++--- lto-plugin/Makefile.in | 1 - lto-plugin/configure | 80 ++++++++++- zlib/configure | 82 ++++++++++- 67 files changed, 2780 insertions(+), 532 deletions(-) create mode 100644 libgcc/config/t-darwin-rpath diff --git a/configure.ac b/configure.ac index bed60bcaf72..bd79a2ffcb9 100644 --- a/configure.ac +++ b/configure.ac @@ -1769,6 +1769,11 @@ AC_ARG_WITH(boot-ldflags, if test "$poststage1_libs" = ""; then poststage1_ldflags="-static-libstdc++ -static-libgcc" fi]) +if test "x$enable_darwin_at_rpath" = "xyes"; then + if test "x$host_shared" != "xyes"; then + poststage1_ldflags="$poststage1_ldflags -nodefaultrpath" + fi +fi AC_SUBST(poststage1_ldflags) # GCC GRAPHITE dependency isl. diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am index 0f3cd6f7121..cde856e532e 100644 --- a/libatomic/Makefile.am +++ b/libatomic/Makefile.am @@ -65,8 +65,12 @@ libatomic_version_script = libatomic_version_dep = endif libatomic_version_info = -version-info $(libtool_VERSION) +if ENABLE_DARWIN_AT_RPATH +libatomic_darwin_rpath = -Wl,-rpath,@loader_path +endif -libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) +libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ + $(lt_host_flags) $(libatomic_darwin_rpath) libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ fenv.c fence.c flag.c diff --git a/libcc1/Makefile.am b/libcc1/Makefile.am index 49a9543ea7d..aa07d5923bb 100644 --- a/libcc1/Makefile.am +++ b/libcc1/Makefile.am @@ -55,6 +55,9 @@ marshall_c_source = marshall-c.hh marshall_cxx_source = marshall-cp.hh libcc1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1plugin.sym +if ENABLE_DARWIN_AT_RPATH +libcc1plugin_la_LDFLAGS += -Wl,-rpath,@loader_path +endif libcc1plugin_la_SOURCES = libcc1plugin.cc context.cc context.hh \ $(shared_source) $(marshall_c_source) libcc1plugin.lo_CPPFLAGS = $(CPPFLAGS_FOR_C) @@ -65,6 +68,9 @@ libcc1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ $(CXXFLAGS) $(libcc1plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@ libcp1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcp1plugin.sym +if ENABLE_DARWIN_AT_RPATH +libcp1plugin_la_LDFLAGS += -Wl,-rpath,@loader_path +endif libcp1plugin_la_SOURCES = libcp1plugin.cc context.cc context.hh \ $(shared_source) $(marshall_cxx_source) libcp1plugin.lo_CPPFLAGS = $(CPPFLAGS_FOR_CXX) @@ -76,6 +82,9 @@ libcp1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym +if ENABLE_DARWIN_AT_RPATH +libcc1_la_LDFLAGS += -Wl,-rpath,@loader_path +endif libcc1_la_SOURCES = findcomp.cc libcc1.cc libcp1.cc \ compiler.cc compiler.hh names.cc names.hh $(shared_source) \ $(marshall_c_source) $(marshall_cxx_source) diff --git a/libffi/Makefile.am b/libffi/Makefile.am index c6d6f849c53..d2ae0c04c7b 100644 --- a/libffi/Makefile.am +++ b/libffi/Makefile.am @@ -214,7 +214,12 @@ libffi.map: $(top_srcdir)/libffi.map.in $(COMPILE) -D$(TARGET) -DGENERATE_LIBFFI_MAP \ -E -x assembler-with-cpp -o $@ $(top_srcdir)/libffi.map.in -libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) +if ENABLE_DARWIN_AT_RPATH +libffi_darwin_rpath = -Wl,-rpath,@loader_path +endif +libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ + $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ + $(libffi_darwin_rpath) libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src diff --git a/libffi/Makefile.in b/libffi/Makefile.in index 5524a6a571e..34e77a45d1a 100644 --- a/libffi/Makefile.in +++ b/libffi/Makefile.in @@ -597,7 +597,11 @@ AM_CFLAGS = -Wall -g -fexceptions $(CET_FLAGS) $(am__append_2) @LIBFFI_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map @LIBFFI_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map-sun libffi_version_info = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) +@ENABLE_DARWIN_AT_RPATH_TRUE@libffi_darwin_rpath = -Wl,-rpath,@loader_path +libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ + $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ + $(libffi_darwin_rpath) + libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src AM_CCASFLAGS = $(AM_CPPFLAGS) $(CET_FLAGS) diff --git a/libgcc/config.host b/libgcc/config.host index 168535b1780..5306a509ff8 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -214,7 +214,27 @@ esac case ${host} in *-*-darwin*) asm_hidden_op=.private_extern - tmake_file="$tmake_file t-darwin ${cpu_type}/t-darwin t-libgcc-pic t-slibgcc-darwin" + tmake_file="$tmake_file t-darwin ${cpu_type}/t-darwin " + tmake_file="$tmake_file t-libgcc-pic t-slibgcc-darwin " + # We are not using libtool to build the libs here, so we need to replicate + # a little of the logic around setting Darwin rpaths. Setting an explicit + # yes or no is honoured, otherwise we choose a suitable default. + # Sadly, this has to be kept in line with the rules in libtool.m4. + if test "x$enable_darwin_at_rpath" = "xyes"; then + tmake_file="$tmake_file t-darwin-rpath " + elif test "x$enable_darwin_at_rpath" = "x"; then + echo "enable_darwin_at_rpath is unset" 1>&2 + case ${host} in + *-darwin[45678]*) ;; + *-darwin9* | *-darwin1[01234]*) ;; # We might default these on later. + *-darwin*) + echo "but is needed after macOS 10.11 (setting it on)" 1>&2 + tmake_file="$tmake_file t-darwin-rpath " + ;; + esac + else + echo "enable_darwin_at_rpath is '$enable_darwin_at_rpath'" 1>&2 + fi extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o" ;; *-*-dragonfly*) diff --git a/libgcc/config/t-darwin-rpath b/libgcc/config/t-darwin-rpath new file mode 100644 index 00000000000..7cf63d9cb6b --- /dev/null +++ b/libgcc/config/t-darwin-rpath @@ -0,0 +1,5 @@ +# Use @rpath and add a search path to exes and dylibs that depend on this. +SHLIB_RPATH = @rpath + +# Which does not work for Darwin < 9 +HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=10.5 diff --git a/libgcc/config/t-slibgcc-darwin b/libgcc/config/t-slibgcc-darwin index bd1e9631c17..b800a9aa175 100644 --- a/libgcc/config/t-slibgcc-darwin +++ b/libgcc/config/t-slibgcc-darwin @@ -10,17 +10,16 @@ SHLIB_OBJS = @shlib_objs@ SHLIB_DIR = @multilib_dir@ SHLIB_LC = -lc -# Darwin only searches in /usr/lib for shared libraries, not in subdirectories, -# so the libgcc variants have different names not different locations. -# Note that this version is used for the loader, not the linker; the linker -# uses the stub versions named by the versioned members of $(INSTALL_FILES). +# Instead of using @shlib_slibdir@, use @rpath and add a search path to exes +# and dylibs that depend on this. +SHLIB_RPATH = @shlib_slibdir@ SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ - -install_name @shlib_slibdir@/$(SHLIB_INSTALL_NAME) \ + -install_name $(SHLIB_RPATH)/$(SHLIB_INSTALL_NAME) \ -single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \ -Wl,-exported_symbols_list,$(SHLIB_MAP) \ - $(SHLIB_VERSTRING) \ - @multilib_flags@ $(SHLIB_OBJS) $(SHLIB_LC) + $(SHLIB_VERSTRING) -nodefaultrpath \ + @multilib_flags@ @shlib_objs@ $(SHLIB_LC) SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk SHLIB_MKMAP_OPTS = -v leading_underscore=1 diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index 008f2e7549c..e036b88119e 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -29,6 +29,9 @@ else version_arg = version_dep = endif +if ENABLE_DARWIN_AT_RPATH +extra_ldflags_libgfortran += -Wl,-rpath,@loader_path +endif gfor_c_HEADERS = ISO_Fortran_binding.h gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index f8b2a06d63e..4dca7e532bf 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -53,9 +53,13 @@ else libgomp_version_script = libgomp_version_dep = endif + libgomp_version_info = -version-info $(libtool_VERSION) +if ENABLE_DARWIN_AT_RPATH +libgomp_darwin_rpath = -Wl,-rpath,@loader_path +endif libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ - $(lt_host_flags) + $(lt_host_flags) $(libgomp_darwin_rpath) libgomp_la_DEPENDENCIES = $(libgomp_version_dep) libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 22cb2136a08..7a45add6a36 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -546,8 +546,9 @@ nodist_toolexeclib_HEADERS = libgomp.spec @LIBGOMP_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver @LIBGOMP_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver-sun libgomp_version_info = -version-info $(libtool_VERSION) +@ENABLE_DARWIN_AT_RPATH_TRUE@libgomp_darwin_rpath = -Wl,-rpath,@loader_path libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ - $(lt_host_flags) + $(lt_host_flags) $(libgomp_darwin_rpath) libgomp_la_DEPENDENCIES = $(libgomp_version_dep) libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) diff --git a/libitm/Makefile.am b/libitm/Makefile.am index 3f31ad30556..053a54fb093 100644 --- a/libitm/Makefile.am +++ b/libitm/Makefile.am @@ -54,7 +54,10 @@ libitm_version_info = -version-info $(libtool_VERSION) # want or need libstdc++. libitm_la_DEPENDENCIES = $(libitm_version_dep) libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) -libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) +if ENABLE_DARWIN_AT_RPATH +libitm_darwin_rpath = -Wl,-rpath,@loader_path +endif +libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) $(libitm_darwin_rpath) libitm_la_SOURCES = \ aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc barrier.cc beginend.cc \ diff --git a/libobjc/configure.ac b/libobjc/configure.ac index c1104db85f0..92b77dc1700 100644 --- a/libobjc/configure.ac +++ b/libobjc/configure.ac @@ -148,10 +148,20 @@ m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) # extra LD Flags which are required for targets ACX_LT_HOST_FLAGS case "${host}" in - *-darwin*) - # Darwin needs -single_module when linking libobjc + *-darwin[[4567]]*) + # Earlier Darwin versions need -single_module when linking libobjc; they + # do not support @rpath. extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' ;; + *-darwin*) + # Otherwise, single_module is the default and multi-module is ignored and + # obsolete. + if test "x$enable_darwin_at_rpath" = "xyes"; then + extra_ldflags_libobjc='$(lt_host_flags) -Wl,-rpath,@loader_path' + else + extra_ldflags_libobjc='$(lt_host_flags)' + fi + ;; *-cygwin*|*-mingw*) # Tell libtool to build DLLs on Windows extra_ldflags_libobjc='$(lt_host_flags)' diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am index 4f802f723d6..86ac110466b 100644 --- a/libsanitizer/asan/Makefile.am +++ b/libsanitizer/asan/Makefile.am @@ -60,7 +60,11 @@ libasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la endif libasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) +if ENABLE_DARWIN_AT_RPATH +libasan_darwin_rpath = -Wl,-rpath,@loader_path +endif +libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(link_libasan) $(libasan_darwin_rpath) libasan_preinit.o: asan_preinit.o cp $< $@ diff --git a/libsanitizer/hwasan/Makefile.am b/libsanitizer/hwasan/Makefile.am index e12c0a0ce71..d73bcac782a 100644 --- a/libsanitizer/hwasan/Makefile.am +++ b/libsanitizer/hwasan/Makefile.am @@ -46,7 +46,11 @@ libhwasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la endif libhwasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) +if ENABLE_DARWIN_AT_RPATH +libhwasan_darwin_rpath = -Wl,-rpath,@loader_path +endif +libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(link_libhwasan) $(libhwasan_darwin_rpath) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am index 6ff28ff5eea..34a9f7b9977 100644 --- a/libsanitizer/lsan/Makefile.am +++ b/libsanitizer/lsan/Makefile.am @@ -41,8 +41,11 @@ if LIBBACKTRACE_SUPPORTED liblsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la endif liblsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) - +if ENABLE_DARWIN_AT_RPATH +liblsan_darwin_rpath = -Wl,-rpath,@loader_path +endif +liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(link_liblsan) $(liblsan_darwin_rpath) liblsan_preinit.o: lsan_preinit.o cp $< $@ diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am index ae588a67df6..eed8f321b3c 100644 --- a/libsanitizer/tsan/Makefile.am +++ b/libsanitizer/tsan/Makefile.am @@ -58,7 +58,11 @@ libtsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la libtsan_la_DEPENDENCIES +=$(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la endif libtsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) +if ENABLE_DARWIN_AT_RPATH +libtsan_darwin_rpath = -Wl,-rpath,@loader_path +endif +libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(link_libtsan) $(libtsan_darwin_rpath) libtsan_preinit.o: tsan_preinit.o cp $< $@ diff --git a/libsanitizer/ubsan/Makefile.am b/libsanitizer/ubsan/Makefile.am index d480f26adc0..0bfae37ba09 100644 --- a/libsanitizer/ubsan/Makefile.am +++ b/libsanitizer/ubsan/Makefile.am @@ -36,7 +36,11 @@ if LIBBACKTRACE_SUPPORTED libubsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la endif libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) +if ENABLE_DARWIN_AT_RPATH +libubsan_darwin_rpath = -Wl,-rpath,@loader_path +endif +libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(link_libubsan) $(libubsan_darwin_rpath) # Use special rules for files that require RTTI support. ubsan_handlers_cxx.% ubsan_type_hash.% ubsan_type_hash_itanium.% : AM_CXXFLAGS += -frtti diff --git a/libssp/Makefile.am b/libssp/Makefile.am index 6045c320cfa..1155e987a9b 100644 --- a/libssp/Makefile.am +++ b/libssp/Makefile.am @@ -49,8 +49,11 @@ libssp_la_SOURCES = \ vsnprintf-chk.c vsprintf-chk.c libssp_la_LIBADD = libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) +if ENABLE_DARWIN_AT_RPATH +libssp_darwin_rpath = -Wl,-rpath,@loader_path +endif libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ - $(version_arg) $(lt_host_flags) + $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) libssp_nonshared_la_SOURCES = \ ssp-local.c diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index f27d3f8c87e..77e7cedb17a 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -122,8 +122,12 @@ libstdc___la_DEPENDENCIES = \ $(top_builddir)/src/c++17/libc++17convenience.la \ $(top_builddir)/src/c++20/libc++20convenience.la +if ENABLE_DARWIN_AT_RPATH +libstdc___darwin_rpath = -Wl,-rpath,@loader_path +endif + libstdc___la_LDFLAGS = \ - -version-info $(libtool_VERSION) ${version_arg} -lm + -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 05b25ed5e9d..c4eb9e8c546 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -534,8 +534,9 @@ libstdc___la_DEPENDENCIES = \ $(top_builddir)/src/c++17/libc++17convenience.la \ $(top_builddir)/src/c++20/libc++20convenience.la +@ENABLE_DARWIN_AT_RPATH_TRUE@libstdc___darwin_rpath = -Wl,-rpath,@loader_path libstdc___la_LDFLAGS = \ - -version-info $(libtool_VERSION) ${version_arg} -lm + -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) @GLIBCXX_LDBL_ALT128_COMPAT_FALSE@@GLIBCXX_LDBL_COMPAT_TRUE@LTCXXCOMPILE64 = $(LTCXXCOMPILE) diff --git a/libtool.m4 b/libtool.m4 index 17f8e5f3074..b474089fc3e 100644 --- a/libtool.m4 +++ b/libtool.m4 @@ -1039,6 +1039,47 @@ _LT_EOF m4_defun([_LT_DARWIN_LINKER_FEATURES], [ m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + + # Publish an arg to allow the user to select that Darwin host (and target) + # libraries should be given install-names like @rpath/libfoo.dylib. This + # requires that the user of the library then adds an 'rpath' to the DSO that + # needs access. + # NOTE: there are defaults below, for systems that support rpaths. The person + # configuring can override the defaults for any system version that supports + # them - they are, however, forced off for system versions without support. + AC_ARG_ENABLE([darwin-at-rpath], + AS_HELP_STRING([--enable-darwin-at-path], + [install libraries with @rpath/library-name, requires rpaths to be added to executables]), + [if test "x$enable_darwin_at_rpath" = "xyes"; then + # This is not supported before macOS 10.5 / Darwin9. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in + UNSET,darwin[[45678]]*|UNSET,rhapsody*|10.[[01234]][[,.]]*) + echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&AS_MESSAGE_LOG_FD + enable_darwin_at_rpath=no + ;; + esac + fi], + [case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in + # As above, before 10.5 / Darwin9 this does not work. + UNSET,darwin[[45678]]*|UNSET,rhapsody*|10.[[01234]][[,.]]*) + enable_darwin_at_rpath=no + ;; + + # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use + # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key + # system executables (e.g. /bin/sh). Force rpaths on for these systems. + UNSET,darwin1[[56789]]*|UNSET,darwin2*|10.1[[123456789]][[,.]]*|1[[12]].*[[,.]]* ) + echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&AS_MESSAGE_LOG_FD + enable_darwin_at_rpath=yes + ;; + # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can + # work with either DYLD_LIBRARY_PATH or embedded rpaths. + + esac + ]) + + AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test "x$enable_darwin_at_rpath" = "xyes"]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=yes @@ -1056,13 +1097,26 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], esac if test "$_lt_dar_can_shared" = "yes"; then output_verbose_link_cmd=func_echo_all - _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" - _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" - _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" - _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "x$enable_darwin_at_rpath" = "xyes"; then + echo "using Darwin @rpath" 1>&AS_MESSAGE_LOG_FD + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + else + echo "NOT using Darwin @rpath" 1>&AS_MESSAGE_LOG_FD + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + fi m4_if([$1], [CXX], [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then - _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + if test "x$enable_darwin_at_rpath" = "xyes"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" + else + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + fi _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" fi ],[]) diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in index f8df31bb1e8..591a1624e98 100644 --- a/lto-plugin/Makefile.in +++ b/lto-plugin/Makefile.in @@ -323,7 +323,6 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ real_target_noncanonical = @real_target_noncanonical@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ From patchwork Wed Nov 17 21:03:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47853 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 3BE4D3858409 for ; Wed, 17 Nov 2021 21:05:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BE4D3858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637183150; bh=ZuXUqLm9cBWMsKDwfoUyTb5k0YmmPvc3C7b6H7ojZaw=; 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=kIybGxNQ2pbjFm2C2R5Ymc6o0ANeVziztjG8LB7PjIVz/mVeRGBs05XygE5PaYoHl m0Xox2zPsxfUS5Z1lpITBzAjt4N8yST2DacZUlaf+QMaexNvgAH7jN4eUKZ0kSNpJf eUEeDlUxAL8I/or/2cbIGPe5Yjn7u1+owtNZ4nPM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id B9C9D3858414 for ; Wed, 17 Nov 2021 21:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9C9D3858414 Received: by mail-wm1-x32f.google.com with SMTP id p18so3405626wmq.5 for ; Wed, 17 Nov 2021 13:03:28 -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=ZuXUqLm9cBWMsKDwfoUyTb5k0YmmPvc3C7b6H7ojZaw=; b=aVP8A3XWrEGmfy0DTsz/5sLnmihNsk8xEOZwPj2NaootK+Dw/s4Pf/974JY6xEpThw K92jsoqKBnz0t7eXmlTv4wzwccS5BfJwr5Feo+6tMY1owqpo4S3DZA9ySxRhR0WtBD+4 ehClwCmz/OlYYhdkYSdin22QMXPE0x5KW5tWvExpYjdG6c3104o2StmnWgSR3IFsgn8N doTkHaxn+KiHr+73R64uNj7N+vCM4HEg6wN5QeZfzexfl9cN/uABvGGKocqeGPEQrG+h fAfiH4HiDO8uNQRFjYKre6Sz+I5Z+0wPNyNnbLs7Dv+B041qtv+ZP/Qzt737oigAwPNf lnNQ== X-Gm-Message-State: AOAM531uUJOLg8TH0D/7/wlFOzdnhsUwfg/f0uVDKnz9Ik1B/8oOqmJd bE3HBeP0V4X9XwID4bPgh6ENqp6t8KM= X-Google-Smtp-Source: ABdhPJzVV7rx+CfgQdgM9aHZ/s3nTodg0cfw9B0glMlt6Lse4R155o7fvRu+1UOaA6sIqCOHOLp/rw== X-Received: by 2002:a7b:c744:: with SMTP id w4mr3420854wmk.50.1637183007931; Wed, 17 Nov 2021 13:03:27 -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.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 13:03:27 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH 4/4] Darwin, Ada : Add loader path as a default rpath. Date: Wed, 17 Nov 2021 21:03:19 +0000 Message-Id: <20211117210319.92514-5-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211117210319.92514-4-iain@sandoe.co.uk> References: <20211117210319.92514-1-iain@sandoe.co.uk> <20211117210319.92514-2-iain@sandoe.co.uk> <20211117210319.92514-3-iain@sandoe.co.uk> <20211117210319.92514-4-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" Allow the Ada runtimes to find GCC runtimes relative to their non- standard install positions. gcc/ada/ * gcc-interface/Makefile.in: Add @loader_path runpaths to the libgnat and libgnarl shared library builds. --- gcc/ada/gcc-interface/Makefile.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in index 53d0739470a..bffe9de4c89 100644 --- a/gcc/ada/gcc-interface/Makefile.in +++ b/gcc/ada/gcc-interface/Makefile.in @@ -788,6 +788,7 @@ gnatlib-shared-darwin: $(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \ $(SO_OPTS) \ -Wl,-install_name,@rpath/libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \ + -Wl,-rpath,@loader_path \ $(MISCLIB) cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \ | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(PICFLAG_FOR_TARGET) \ @@ -795,6 +796,7 @@ gnatlib-shared-darwin: $(GNATRTL_TASKING_OBJS) \ $(SO_OPTS) \ -Wl,-install_name,@rpath/libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \ + -Wl,-rpath,@loader_path \ $(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) cd $(RTSDIR); $(LN_S) libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \ libgnat$(soext)