From: Iain Sandoe <iains.gcc@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: joseph@codesourcery.com
Subject: [PATCH 2/4] Darwin : Handle rpaths given on the command line.
Date: Wed, 17 Nov 2021 21:03:17 +0000 [thread overview]
Message-ID: <20211117210319.92514-3-iain@sandoe.co.uk> (raw)
In-Reply-To: <20211117210319.92514-2-iain@sandoe.co.uk>
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)}}}} " \
"}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath "
/* Spec that controls whether the debug linker is run automatically for
@@ -516,7 +517,8 @@ extern GTY(()) int darwin_ms_struct;
{ "darwin_crt2", DARWIN_CRT2_SPEC }, \
{ "darwin_crt3", DARWIN_CRT3_SPEC }, \
{ "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \
- { "darwin_bundle1", DARWIN_BUNDLE1_SPEC },
+ { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, \
+ { "darwin_rpaths", DARWIN_RPATH_SPEC },
#define DARWIN_CRT1_SPEC \
"%:version-compare(!> 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.
--
2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-11-17 21:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 21:03 [PATCH 0/4] Darwin: Replace environment runpath with embedded [PR88590] Iain Sandoe
2021-11-17 21:03 ` [PATCH 1/4] Driver : Provide a spec to insert rpaths for compiler lib dirs Iain Sandoe
2021-11-17 21:03 ` Iain Sandoe [this message]
2021-11-17 21:03 ` [PATCH 3/4] Darwin : Allow for configuring Darwin to use embedded runpath Iain Sandoe
2021-11-17 21:03 ` [PATCH 4/4] Darwin, Ada : Add loader path as a default rpath Iain Sandoe
2021-11-18 7:28 ` Arnaud Charlet
2021-11-17 22:50 ` [PATCH 3/4] Darwin : Allow for configuring Darwin to use embedded runpath Joseph Myers
2021-11-17 23:30 ` Iain Sandoe
2021-11-18 21:49 ` Joseph Myers
[not found] ` <160318AE-E2F4-4612-AEC1-5013419B6359@gmail.com>
2021-11-18 15:34 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211117210319.92514-3-iain@sandoe.co.uk \
--to=iains.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=iain@sandoe.co.uk \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).