public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-02-14 14:56 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-02-14 14:56 UTC (permalink / raw
  To: gentoo-commits

commit:     4d852a87f65738c62a3e4c7e68bd8d387023d000
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 14 13:50:57 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Feb 14 13:50:57 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=4d852a87

sys-devel/binutils-config: only add rpaths for absolute -L paths

Package-Manager: portage-2.2.20-prefix

 sys-devel/binutils-config/files/ldwrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 355840f..4256e78 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -211,7 +211,7 @@ main(int argc, char *argv[])
 		newargv[j] = argv[i];
 #ifndef TARGET_DARWIN
 		/* on ELF targets we add runpaths for all found search paths */
-		if (argv[i][0] == '-' && argv[i][1] == 'L') {
+		if (argv[i][0] == '-' && argv[i][1] == 'L' && argv[i][2] == '/') {
 			newargv[++j] = strdup(argv[i]);
 			if (newargv[j] == NULL) {
 				fprintf(stderr, "%s: failed to allocate memory for "


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-02-15 14:30 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-02-15 14:30 UTC (permalink / raw
  To: gentoo-commits

commit:     8cb9c22e827757a7c5151c53afb2b4d4e0a3d0c6
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 15 14:30:37 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Feb 15 14:30:37 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=8cb9c22e

sys-devel/binutils-config: position all added arguments after given arguments in ldwrapper

Package-Manager: portage-2.2.20-prefix

 sys-devel/binutils-config/files/ldwrapper.c | 58 +++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 4256e78..958bed4 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -151,6 +151,7 @@ main(int argc, char *argv[])
 	char *p;
 	int i;
 	int j;
+	int k;
 
 	/* cannonicanise wrapper, stripping path and CHOST */
 	if ((p = strrchr(wrapper, '/')) != NULL) {
@@ -207,36 +208,63 @@ main(int argc, char *argv[])
 	/* inject this first to make the intention clear */
 	newargv[j++] = "-search_paths_first";
 #endif
+	/* position k right after the original arguments */
+	k = j - 1 + argc;
 	for (i = 1; i < argc; i++, j++) {
 		newargv[j] = argv[i];
 #ifndef TARGET_DARWIN
 		/* on ELF targets we add runpaths for all found search paths */
-		if (argv[i][0] == '-' && argv[i][1] == 'L' && argv[i][2] == '/') {
-			newargv[++j] = strdup(argv[i]);
-			if (newargv[j] == NULL) {
+		if (argv[i][0] == '-' && argv[i][1] == 'L') {
+			char *path;
+			size_t len;
+
+			/* arguments can be in many ways here:
+			 * -L<path>
+			 * -L <path> (yes, this is accepted)
+			 * -L(whitespace)? <path in next argument>
+			 * where path is absolute (not relative) */
+			path = &argv[i][2];
+			while (*path != '\0' && isspace(*path))
+				path++;
+			if (*path == '\0') {
+				/* no more arguments?!? skip */
+				if (i + 1 >= argc)
+					continue;
+				path = argv[i + 1];
+				while (*path != '\0' && isspace(*path))
+					path++;
+			}
+			/* not absolute (or empty)?!? skip */
+			if (*path != '/')
+				continue;
+
+			len = 2 + strlen(path) + 1;
+			newargv[k] = malloc(sizeof(char) * len);
+			if (newargv[k] == NULL) {
 				fprintf(stderr, "%s: failed to allocate memory for "
 						"'%s' -R argument\n", wrapper, argv[i]);
 				exit(1);
 			}
-			newargv[j][1] = 'R';
+			snprintf(newargv[k], len, "-R%s", path);
+			k++;
 		}
 #endif
 	}
 	/* add the custom paths */
 #ifdef TARGET_DARWIN
-	newargv[j++] = "-L" EPREFIX "/usr/lib";
-	newargv[j++] = "-L" EPREFIX "/lib";
+	newargv[k++] = "-L" EPREFIX "/usr/lib";
+	newargv[k++] = "-L" EPREFIX "/lib";
 #else
-	newargv[j++] = "-L" EPREFIX "/usr/" CHOST "/lib/gcc";
-	newargv[j++] = "-R" EPREFIX "/usr/" CHOST "/lib/gcc";
-	newargv[j++] = "-L" EPREFIX "/usr/" CHOST "/lib";
-	newargv[j++] = "-R" EPREFIX "/usr/" CHOST "/lib";
-	newargv[j++] = "-L" EPREFIX "/usr/lib";
-	newargv[j++] = "-R" EPREFIX "/usr/lib";
-	newargv[j++] = "-L" EPREFIX "/lib";
-	newargv[j++] = "-R" EPREFIX "/lib";
+	newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib/gcc";
+	newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib/gcc";
+	newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib";
+	newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib";
+	newargv[k++] = "-L" EPREFIX "/usr/lib";
+	newargv[k++] = "-R" EPREFIX "/usr/lib";
+	newargv[k++] = "-L" EPREFIX "/lib";
+	newargv[k++] = "-R" EPREFIX "/lib";
 #endif
-	newargv[j] = NULL;
+	newargv[k] = NULL;
 
 	if (verbose) {
 		fprintf(stdout, "%s: invoking %s with arguments:\n", wrapper, ld);


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-04-18  8:07 Michael Haubenwallner
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Haubenwallner @ 2016-04-18  8:07 UTC (permalink / raw
  To: gentoo-commits

commit:     1f90d833970f8f6813a48f9385c234e197c3ee55
Author:     Michael Haubenwallner <michael.haubenwallner <AT> ssi-schaefer <DOT> com>
AuthorDate: Fri Apr 15 09:07:19 2016 +0000
Commit:     Michael Haubenwallner <haubi <AT> gentoo <DOT> org>
CommitDate: Mon Apr 18 08:06:00 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=1f90d833

ldwrapper.c: check last PATH env entry; restore PATH env value; fix missing string.h warnings

 sys-devel/binutils-config/files/ldwrapper.c | 36 ++++++++++++++---------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 958bed4..9823da8 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <strings.h>
+#include <string.h>
 #include <ctype.h>
 #include <sys/stat.h>
 #include <errno.h>
@@ -46,6 +47,9 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	char *e;
 	struct stat lde;
 
+	/* we may not succeed finding the linker */
+	*ld = NULL;
+
 	/* respect the override in environment */
 	ldoveride = getenv("BINUTILS_CONFIG_LD");
 	if (ldoveride != NULL && *ldoveride != '\0') {
@@ -67,23 +71,20 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 
 	/* find ld in PATH, allowing easy PATH overrides */
 	path = getenv("PATH");
-	if (path != NULL && *path != '\0') {
-		char *p;
-		char *q;
-
-		for (p = path; (q = strchr(p, ':')) != NULL; p = q + 1) {
-			if (q)
-				*q = '\0';
-			if (strstr(p, "/" CHOST "/binutils-bin/") != NULL) {
-				snprintf(e, ESIZ, "%s/%s", p, wrapper);
-				if (stat(e, &lde) == 0) {
-					*ld = e;
-					return;
-				}
-			}
-			if (!q)
-				break;
+	while (path > (char*)1 && *path != '\0') {
+		char *q = strchr(path, ':');
+		if (q)
+			*q = '\0';
+		if (strstr(path, "/" CHOST "/binutils-bin/") != NULL) {
+			snprintf(e, ESIZ, "%s/%s", path, wrapper);
+			if (stat(e, &lde) == 0)
+				*ld = e;
 		}
+		if (q)
+			*q = ':'; /* restore PATH value */
+		if (*ld)
+			return;
+		path = q + 1;
 	}
 	if (verbose)
 		fprintf(stdout, "%s: linker not found in PATH\n", wrapper);
@@ -135,9 +136,6 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	if (verbose)
 		fprintf(stdout, "%s: linker not found via binutils-config -c\n",
 				wrapper);
-
-	/* we didn't succeed finding the linker */
-	*ld = NULL;
 }
 
 int


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-05-13 12:14 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-05-13 12:14 UTC (permalink / raw
  To: gentoo-commits

commit:     80df42f4649c3695c0ab0258a98e3b5bf2db0e80
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri May 13 12:10:17 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri May 13 12:10:17 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=80df42f4

sys-devel/binutils-config/ldwrapper: fix cannonicalising of wrapper

When ld is invoked as CHOST-ld (no path) then we should also remove
CHOST, so don't do this only when we found a / earlier.

 sys-devel/binutils-config/files/ldwrapper.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index a08985f..8777ad6 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -157,12 +157,11 @@ main(int argc, char *argv[])
 	int k;
 
 	/* cannonicanise wrapper, stripping path and CHOST */
-	if ((p = strrchr(wrapper, '/')) != NULL) {
+	if ((p = strrchr(wrapper, '/')) != NULL)
 		wrapper = p + 1;
-		p = CHOST "-";
-		if (strncmp(wrapper, p, strlen(p)) == 0)
-			wrapper += strlen(p);
-	}
+	p = CHOST "-";
+	if (strncmp(wrapper, p, strlen(p)) == 0)
+		wrapper += strlen(p);
 
 	/* walk over the arguments to see if there's anything interesting
 	 * for us and calculate the final number of arguments */


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-05-13 12:14 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-05-13 12:14 UTC (permalink / raw
  To: gentoo-commits

commit:     95f7a7bd56f5cbb3fdcb5e28a7e2f776181e628b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri May 13 12:05:58 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri May 13 12:05:58 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=95f7a7bd

sys-devel/binutils-config/ldwrapper: some better error reporting

 sys-devel/binutils-config/files/ldwrapper.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 9823da8..a98b1e6 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -92,6 +92,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	/* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then
 	 * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should
 	 * be able to find ld */
+	*e = '\0';
 	if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) {
 		char p[ESIZ];
 		while (fgets(p, ESIZ, f) != NULL) {
@@ -115,10 +116,12 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	}
 	if (verbose)
 		fprintf(stdout, "%s: linker not found via " EPREFIX
-				"/etc/env.d/binutils/config-" CHOST "\n", wrapper);
+				"/etc/env.d/binutils/config-" CHOST " (ld=%s)\n",
+				wrapper, e);
 	
 	/* last try, call binutils-config to tell us what the linker is
 	 * supposed to be */
+	*e = '\0';
 	if ((f = popen("binutils-config -c", "r")) != NULL) {
 		char p[ESIZ];
 		if (fgets(p, ESIZ, f) != NULL) {
@@ -134,8 +137,8 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 		}
 	}
 	if (verbose)
-		fprintf(stdout, "%s: linker not found via binutils-config -c\n",
-				wrapper);
+		fprintf(stdout, "%s: linker not found via binutils-config -c (ld=%s)\n",
+				wrapper, e);
 }
 
 int


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-05-13 12:14 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-05-13 12:14 UTC (permalink / raw
  To: gentoo-commits

commit:     c76c1b6d1ee3fcb4462e191e58a5c1bc6569fb03
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri May 13 12:09:27 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri May 13 12:09:27 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=c76c1b6d

sys-devel/binutils-config/ldwrapper: strip CHOST from binutils-config -c output

we only need the number here, not the full profile name

 sys-devel/binutils-config/files/ldwrapper.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index a98b1e6..a08985f 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -125,6 +125,8 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	if ((f = popen("binutils-config -c", "r")) != NULL) {
 		char p[ESIZ];
 		if (fgets(p, ESIZ, f) != NULL) {
+			if (strncmp(p, CHOST "-", strlen(CHOST "-")) == 0)
+				p += strlen(CHOST "-");
 			snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
 					p, wrapper);
 		} else {


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2016-05-15 16:44 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2016-05-15 16:44 UTC (permalink / raw
  To: gentoo-commits

commit:     64c18bc7bb802464d841afcfa9b75cae848b2a0e
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun May 15 16:44:24 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun May 15 16:44:24 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=64c18bc7

sys-devel/binutils-config: fix compilation on Darwin, char[] != char*

 sys-devel/binutils-config/files/ldwrapper.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 8777ad6..6991784 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -124,11 +124,13 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	*e = '\0';
 	if ((f = popen("binutils-config -c", "r")) != NULL) {
 		char p[ESIZ];
+		char *q;
 		if (fgets(p, ESIZ, f) != NULL) {
-			if (strncmp(p, CHOST "-", strlen(CHOST "-")) == 0)
-				p += strlen(CHOST "-");
+			q = p;
+			if (strncmp(q, CHOST "-", strlen(CHOST "-")) == 0)
+				q += strlen(CHOST "-");
 			snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
-					p, wrapper);
+					q, wrapper);
 		} else {
 			*p = '\0';
 		}


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2017-11-25 18:33 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2017-11-25 18:33 UTC (permalink / raw
  To: gentoo-commits

commit:     e24576aae416fbe8c86b4bd528ba86dd79c5a062
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 25 15:40:49 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Nov 25 15:40:49 2017 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=e24576aa

sys-devel/binutils-config: avoid malloc for fixed-size bugger

Package-Manager: Portage-2.3.13-prefix, Repoman-2.3.4

 sys-devel/binutils-config/files/ldwrapper.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index c971ef4d9d..fda6e9b603 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -1,7 +1,8 @@
 /*
- * Copyright 1999-2013 Gentoo Foundation
+ * Copyright 1999-2017 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  * Authors: Fabian Groffen <grobian@gentoo.org>
+ *          Michael Haubenwallner <haubi@gentoo.org>
  */
 
 #include <stdio.h>
@@ -19,6 +20,7 @@
  *
  * On Darwin it adds -search_path_first to make sure the given paths are
  * searched before the default search path.
+ * On AIX it ensures -bsvr4 is the last argument.
  * The wrapper will inject -L entries for:
  *   - EPREFIX/usr/CHOST/lib/gcc (when gcc)
  *   - EPREFIX/usr/CHOST/lib     (when binutils)
@@ -44,7 +46,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	char *ldoveride;
 	char *path;
 #define ESIZ 1024
-	char *e;
+	char e[ESIZ];
 	struct stat lde;
 
 	/* we may not succeed finding the linker */
@@ -63,12 +65,6 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 		fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in environment\n",
 				wrapper);
 	
-	if ((e = malloc(sizeof(char) * ESIZ)) == NULL) {
-		fprintf(stderr, "%s: out of memory allocating string for path to ld\n",
-				wrapper);
-		exit(1);
-	}
-
 	/* find ld in PATH, allowing easy PATH overrides */
 	path = getenv("PATH");
 	while (path > (char*)1 && *path != '\0') {
@@ -92,7 +88,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	/* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then
 	 * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should
 	 * be able to find ld */
-	*e = '\0';
+	e[0] = '\0';
 	if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) {
 		char p[ESIZ];
 		while (fgets(p, ESIZ, f) != NULL) {
@@ -121,7 +117,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	
 	/* last try, call binutils-config to tell us what the linker is
 	 * supposed to be */
-	*e = '\0';
+	e[0] = '\0';
 	if ((f = popen("binutils-config -c", "r")) != NULL) {
 		char p[ESIZ];
 		char *q;


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2017-11-29 15:21 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2017-11-29 15:21 UTC (permalink / raw
  To: gentoo-commits

commit:     d469b099b5e8aed45ff2edf78f91822b805440d3
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 29 15:17:47 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Nov 29 15:17:47 2017 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=d469b099

sys-devel/binutils-config: fix returned buffer from find_real_ld, bug #639172

Package-Manager: Portage-2.3.13-prefix, Repoman-2.3.4

 sys-devel/binutils-config/files/ldwrapper.c | 35 ++++++++++++++++-------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 88f93a8602..80831a7142 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -45,8 +45,8 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	FILE *f = NULL;
 	char *ldoveride;
 	char *path;
-#define ESIZ 1024
-	char e[ESIZ];
+#define ESIZ 1024  /* POSIX_MAX_PATH */
+	char *ret;
 	struct stat lde;
 
 	/* we may not succeed finding the linker */
@@ -65,6 +65,10 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 		fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in environment\n",
 				wrapper);
 	
+	ret = malloc(sizeof(char) * ESIZ);
+	if (ret == NULL)
+		return;
+
 	/* find ld in PATH, allowing easy PATH overrides */
 	path = getenv("PATH");
 	while (path > (char*)1 && *path != '\0') {
@@ -72,9 +76,9 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 		if (q)
 			*q = '\0';
 		if (strstr(path, "/" CHOST "/binutils-bin/") != NULL) {
-			snprintf(e, ESIZ, "%s/%s", path, wrapper);
-			if (stat(e, &lde) == 0)
-				*ld = e;
+			snprintf(ret, ESIZ, "%s/%s", path, wrapper);
+			if (stat(ret, &lde) == 0)
+				*ld = ret;
 		}
 		if (q)
 			*q = ':'; /* restore PATH value */
@@ -88,7 +92,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 	/* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then
 	 * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should
 	 * be able to find ld */
-	e[0] = '\0';
+	ret[0] = '\0';
 	if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) {
 		char p[ESIZ];
 		while (fgets(p, ESIZ, f) != NULL) {
@@ -99,25 +103,25 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 				for (q--; isspace(*q); q--)
 					*q = '\0';
 					;
-				snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
+				snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
 						p + strlen("CURRENT="), wrapper);
 				break;
 			}
 		}
 		fclose(f);
-		if (stat(e, &lde) == 0) {
-			*ld = e;
+		if (stat(ret, &lde) == 0) {
+			*ld = ret;
 			return;
 		}
 	}
 	if (verbose)
 		fprintf(stdout, "%s: linker not found via " EPREFIX
 				"/etc/env.d/binutils/config-" CHOST " (ld=%s)\n",
-				wrapper, e);
+				wrapper, ret);
 	
 	/* last try, call binutils-config to tell us what the linker is
 	 * supposed to be */
-	e[0] = '\0';
+	ret[0] = '\0';
 	if ((f = popen("binutils-config -c", "r")) != NULL) {
 		char p[ESIZ];
 		char *q;
@@ -125,20 +129,21 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 			q = p;
 			if (strncmp(q, CHOST "-", strlen(CHOST "-")) == 0)
 				q += strlen(CHOST "-");
-			snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
+			snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
 					q, wrapper);
 		} else {
 			*p = '\0';
 		}
 		fclose(f);
-		if (*p && stat(e, &lde) == 0) {
-			*ld = e;
+		if (*p && stat(ret, &lde) == 0) {
+			*ld = ret;
 			return;
 		}
 	}
 	if (verbose)
 		fprintf(stdout, "%s: linker not found via binutils-config -c (ld=%s)\n",
-				wrapper, e);
+				wrapper, ret);
+	free(ret);
 }
 
 int


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2017-12-25 19:47 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2017-12-25 19:47 UTC (permalink / raw
  To: gentoo-commits

commit:     554171c6a3d43f87ac771e45be2b5136b18fd2af
Author:     Michael Weiser <michael <AT> weiser <DOT> dinsnail <DOT> net>
AuthorDate: Sun Dec 24 14:40:33 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 24 14:40:33 2017 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=554171c6

sys-devel/binutils-config: add cross-support to ldwrapper

I've extended ldwrapper:
- to detect a cross-ld at runtime from the argv[0] it was called with,
- always call ld with the full path in argv[0] so it can find its
ldscript directory relative to that
- incidentally fix a bug where finding ld via binutils-config could
never have worked since previous tries to find it via PATH had reduced
PATH to its first component where binutils-config would not usually be

 sys-devel/binutils-config/files/ldwrapper.c | 392 +++++++++++++++++++---------
 1 file changed, 274 insertions(+), 118 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 80831a7142..81b78adf20 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -13,6 +13,8 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <glob.h>
+#include <stdarg.h>
 
 /**
  * ldwrapper: Prefix helper to inject -L and -R flags to the invocation
@@ -38,9 +40,20 @@
 # error CHOST must be defined!
 #endif
 
+static inline int is_cross(const char *ctarget) {
+	return strcmp(ctarget, CHOST);
+}
+
+static inline int is_darwin(const char *ctarget) {
+	return (strstr(ctarget, "-darwin") != NULL);
+}
 
-static inline void
-find_real_ld(char **ld, char verbose, char *wrapper)
+static inline int is_aix(const char *ctarget) {
+	return (strstr(ctarget, "-aix") != NULL);
+}
+
+static inline char *
+find_real_ld(const char verbose, const char *wrapper, const char *ctarget)
 {
 	FILE *f = NULL;
 	char *ldoveride;
@@ -48,9 +61,9 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 #define ESIZ 1024  /* POSIX_MAX_PATH */
 	char *ret;
 	struct stat lde;
-
-	/* we may not succeed finding the linker */
-	*ld = NULL;
+	char *config;
+	const char *config_prefix;
+	size_t configlen;
 
 	/* respect the override in environment */
 	ldoveride = getenv("BINUTILS_CONFIG_LD");
@@ -58,92 +71,164 @@ find_real_ld(char **ld, char verbose, char *wrapper)
 		if (verbose)
 			fprintf(stdout, "%s: using BINUTILS_CONFIG_LD=%s "
 					"from environment\n", wrapper, ldoveride);
-		*ld = ldoveride;
-		return;
+		return ldoveride;
 	}
 	if (verbose)
 		fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in environment\n",
 				wrapper);
-	
+
 	ret = malloc(sizeof(char) * ESIZ);
-	if (ret == NULL)
-		return;
-
-	/* find ld in PATH, allowing easy PATH overrides */
-	path = getenv("PATH");
-	while (path > (char*)1 && *path != '\0') {
-		char *q = strchr(path, ':');
-		if (q)
-			*q = '\0';
-		if (strstr(path, "/" CHOST "/binutils-bin/") != NULL) {
-			snprintf(ret, ESIZ, "%s/%s", path, wrapper);
-			if (stat(ret, &lde) == 0)
-				*ld = ret;
+	if (ret == NULL) {
+		fprintf(stderr, "%s: out of memory allocating string for path to ld\n",
+				wrapper);
+		exit(1);
+	}
+
+	/* find ld in PATH, allowing easy PATH overrides. strdup it because
+	 * modifying it would otherwise corrupt the actual PATH environment
+	 * variable which we might need to be intact later on to call
+	 * binutils-config via popen. */
+	path = strdup(getenv("PATH"));
+	if (path != NULL && *path != '\0') {
+		char *p;
+		char *q;
+		char *match;
+		const char *match_anchor = "/binutils-bin/";
+		size_t matchlen = 1 + strlen(ctarget) +
+			strlen(match_anchor) + 1;
+
+		match = malloc(sizeof(char) * matchlen);
+		if (match == NULL) {
+			fprintf(stderr, "%s: out of memory allocating "
+					"buffer for path matching\n",
+					wrapper);
+			exit(1);
+		}
+
+		/* construct /CTARGET/binutils-bin/ for matchin against PATH */
+		snprintf(match, matchlen, "/%s%s", ctarget, match_anchor);
+
+		for (p = path; (q = strchr(p, ':')) != NULL; p = q + 1) {
+			if (q)
+				*q = '\0';
+			if (strstr(p, match) != NULL) {
+				snprintf(ret, ESIZ, "%s/%s", p, wrapper);
+				if (stat(ret, &lde) == 0) {
+					free(match);
+					return ret;
+				}
+			}
+			if (!q)
+				break;
 		}
-		if (q)
-			*q = ':'; /* restore PATH value */
-		if (*ld)
-			return;
-		path = q + 1;
+
+		free(match);
 	}
 	if (verbose)
 		fprintf(stdout, "%s: linker not found in PATH\n", wrapper);
 
-	/* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then
-	 * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should
+	/* parse EPREFIX/etc/env.d/binutils/config-CTARGET to get CURRENT, then
+	 * consider $EPREFIX/usr/CTARGET/binutils-bin/CURRENT where we should
 	 * be able to find ld */
-	ret[0] = '\0';
-	if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) {
+	config_prefix = EPREFIX "/etc/env.d/binutils/config-";
+	configlen = strlen(config_prefix) + strlen(ctarget) + 1;
+	config = malloc(sizeof(char) * configlen);
+	if (config == NULL) {
+		fprintf(stderr, "%s: out of memory allocating "
+			"buffer for configuration file name\n",
+			wrapper);
+		exit(1);
+	}
+
+	snprintf(config, configlen, "%s%s", config_prefix, ctarget);
+	if ((f = fopen(config, "r")) != NULL) {
 		char p[ESIZ];
+		char *q;
 		while (fgets(p, ESIZ, f) != NULL) {
-			if (strncmp(p, "CURRENT=", strlen("CURRENT=")) == 0) {
-				char *q = p + strlen(p);
-				/* strip trailing whitespace (fgets at least includes
-				 * the \n) */
-				for (q--; isspace(*q); q--)
-					*q = '\0';
-					;
+			if (strncmp(p, "CURRENT=", strlen("CURRENT=")) != 0)
+				continue;
+
+			q = p + strlen(p);
+			/* strip trailing whitespace (fgets at least includes
+			 * the \n) */
+			for (q--; isspace(*q); q--)
+				*q = '\0';
+
+			q = p + strlen("CURRENT=");
+			if (is_cross(ctarget)) {
+				snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/%s/binutils-bin/%s/%s",
+						ctarget, q, wrapper);
+			} else {
 				snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
-						p + strlen("CURRENT="), wrapper);
-				break;
+						q, wrapper);
 			}
+			break;
 		}
 		fclose(f);
 		if (stat(ret, &lde) == 0) {
-			*ld = ret;
-			return;
+			free(config);
+			return ret;
 		}
 	}
 	if (verbose)
-		fprintf(stdout, "%s: linker not found via " EPREFIX
-				"/etc/env.d/binutils/config-" CHOST " (ld=%s)\n",
-				wrapper, ret);
-	
+		fprintf(stdout, "%s: linker not found via %s\n", wrapper, config);
+	free(config);
+
 	/* last try, call binutils-config to tell us what the linker is
 	 * supposed to be */
-	ret[0] = '\0';
-	if ((f = popen("binutils-config -c", "r")) != NULL) {
+	config_prefix = "binutils-config -c ";
+	configlen = strlen(config_prefix) + strlen(ctarget) + 1;
+	config = malloc(sizeof(char) * configlen);
+	if (config == NULL) {
+		fprintf(stderr, "%s: out of memory allocating "
+			"buffer for binutils-config command\n",
+			wrapper);
+		exit(1);
+	}
+
+	snprintf(config, configlen, "%s%s", config_prefix, ctarget);
+	if ((f = popen(config, "r")) != NULL) {
 		char p[ESIZ];
-		char *q;
-		if (fgets(p, ESIZ, f) != NULL) {
-			q = p;
-			if (strncmp(q, CHOST "-", strlen(CHOST "-")) == 0)
-				q += strlen(CHOST "-");
-			snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
-					q, wrapper);
-		} else {
-			*p = '\0';
-		}
+		char *q = fgets(p, ESIZ, f);
 		fclose(f);
-		if (*p && stat(ret, &lde) == 0) {
-			*ld = ret;
-			return;
+		if (q != NULL) {
+			size_t ctargetlen = strlen(ctarget);
+
+			/* binutils-config should report CTARGET-<version> */
+			if (strncmp(p, ctarget, ctargetlen) == 0 &&
+					strlen(p) > ctargetlen &&
+					p[ctargetlen] == '-') {
+				/* strip trailing whitespace (fgets at least includes
+				 * the \n) */
+				q = p + strlen(p);
+				for (q--; isspace(*q); q--)
+					*q = '\0';
+
+				q = p + ctargetlen + 1;
+				if (is_cross(ctarget)) {
+					snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST
+							"/%s/binutils-bin/%s/%s",
+							ctarget, q, wrapper);
+				} else {
+					snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST
+							"/binutils-bin/%s/%s",
+							q, wrapper);
+				}
+
+				if (stat(ret, &lde) == 0) {
+					free(config);
+					return ret;
+				}
+			}
 		}
 	}
 	if (verbose)
-		fprintf(stdout, "%s: linker not found via binutils-config -c (ld=%s)\n",
-				wrapper, ret);
-	free(ret);
+		fprintf(stdout, "%s: linker not found via %s\n",
+				wrapper, config);
+	free(config);
+
+	/* we didn't succeed finding the linker */
+	return NULL;
 }
 
 int
@@ -153,6 +238,7 @@ main(int argc, char *argv[])
 	int newargc = 0;
 	char **newargv = NULL;
 	char *wrapper = argc > 0 ? argv[0] : "ld-wrapper";
+	char *wrapperdir = NULL;
 	char verbose = getenv("BINUTILS_CONFIG_VERBOSE") != NULL;
 	char *builddir = getenv("PORTAGE_BUILDDIR");
 	size_t builddirlen;
@@ -160,13 +246,68 @@ main(int argc, char *argv[])
 	int i;
 	int j;
 	int k;
+	glob_t m;
+	char *ctarget = CHOST;
+	size_t ctargetlen;
 
-	/* cannonicanise wrapper, stripping path and CHOST */
-	if ((p = strrchr(wrapper, '/')) != NULL)
+	/* two ways to determine CTARGET from argv[0]:
+	 * 1. called as <CTARGET>-ld (manually)
+	 * 2. called as EPREFIX/usr/libexec/gcc/<CTARGET>/ld (by gcc's collect2)
+	 *
+	 * TODO: Make argv[0] absolute without resolving symlinks so no. 2 can
+	 * work when added to PATH (which shouldn't happen in the wild, but
+	 * eh!?). */
+	if ((p = strrchr(wrapper, '/')) != NULL) {
+		/* cannonicanise wrapper step 1: strip path */
 		wrapper = p + 1;
-	p = CHOST "-";
-	if (strncmp(wrapper, p, strlen(p)) == 0)
-		wrapper += strlen(p);
+
+		/* remember directory to see if it's CTARGET but only
+		 * if parent is /gcc/ */
+		*p = '\0';
+		if ((p = strrchr(argv[0], '/')) != NULL) {
+			char *q;
+
+			*p = '\0';
+			if ((q = strrchr(argv[0], '/')) != NULL &&
+				strncmp(q + 1, "gcc", strlen("gcc")) == 0) {
+				wrapperdir = p + 1;
+			}
+		}
+	}
+
+	/* see if we have a known CTARGET prefix */
+	i = glob(EPREFIX "/etc/env.d/binutils/config-*", GLOB_NOSORT, NULL, &m);
+	if (i == GLOB_NOSPACE) {
+		fprintf(stderr, "%s: out of memory when inspecting "
+				"binutils configuration\n", wrapper);
+		exit(1);
+	}
+	if (i == 0) {
+		for (i = 0; i < m.gl_pathc; i++) {
+			p = strrchr(m.gl_pathv[i], '/');
+			if (p == NULL || strncmp(p, "/config-", strlen("/config-")) != 0)
+				continue;
+
+			/* EPREFIX/etc/env.d/binutils/config-arm-something-or-other
+			 *                         move here ^ */
+			p += strlen("/config-");
+			if (strncmp(wrapper, p, strlen(p)) == 0 ||
+				(wrapperdir != NULL && strcmp(wrapperdir, p) == 0)) {
+				/* this is us! (MEMLEAK) */
+				ctarget = strdup(p);
+				break;
+			}
+		}
+	}
+	/* ignore GLOB_NOMATCH and (possibly) GLOB_ABORTED */
+	globfree(&m);
+
+	/* cannonicanise wrapper step2: strip CTARGET */
+	ctargetlen = strlen(ctarget);
+	if (strncmp(wrapper, ctarget, ctargetlen) == 0 &&
+			wrapper[ctargetlen] == '-') {
+		wrapper += ctargetlen + 1;
+	}
 
 	/* ensure builddir is something useful */
 	if (builddir != NULL && *builddir != '/')
@@ -186,21 +327,28 @@ main(int argc, char *argv[])
 	}
 	/* account the original arguments */
 	newargc += argc > 0 ? argc : 1;
-#ifdef TARGET_DARWIN
-	/* add the 2 prefix paths (-L), -search_paths_first and a
-	 * null-terminator */
-	newargc += 2 + 1 + 1;
-#else
-	/* add the 4 paths we want (-L + -R) and a null-terminator */
-	newargc += 8 + 1;
-#endif
-#ifdef TARGET_AIX
-	/* AIX ld accepts -R only with -bsvr4 */
-	newargc++; /* -bsvr4 */
-#endif
+	/* we always add a null-terminator */
+	newargc ++;
+	/* If a package being cross-compiled injects standard directories, it's
+	 * non-cross-compilable on any platform, prefix or no prefix. So no
+	 * need to add PREFIX- or CTARGET-aware libdirs. */
+	if (!is_cross(ctarget)) {
+		if (is_darwin(ctarget)) {
+			/* add the 2 prefix paths (-L) and -search_paths_first */
+			newargc += 2 + 1;
+		} else {
+			/* add the 4 paths we want (-L + -R) */
+			newargc += 8;
+		}
+
+		if (is_aix(ctarget)) {
+			/* AIX ld accepts -R only with -bsvr4 */
+			newargc++; /* -bsvr4 */
+		}
+	}
 
 	/* let's first try to find the real ld */
-	find_real_ld(&ld, verbose, wrapper);
+	ld = find_real_ld(verbose, wrapper, ctarget);
 	if (ld == NULL) {
 		fprintf(stderr, "%s: failed to locate the real ld!\n", wrapper);
 		exit(1);
@@ -215,32 +363,38 @@ main(int argc, char *argv[])
 
 	/* construct the new argv */
 	j = 0;
-	if ((p = strrchr(ld, '/')) != NULL) {
-		newargv[j++] = p + 1;
-	} else {
-		newargv[j++] = ld;
+
+	/* put the full path to ld into the new argv[0] we're calling it with
+	 * because binutils ld finds its ldscripts directory relative to its
+	 * own call path derived from its argv[0] */
+	newargv[j++] = ld;
+
+	if (!is_cross(ctarget) && is_darwin(ctarget)) {
+		/* inject this first to make the intention clear */
+		newargv[j++] = "-search_paths_first";
 	}
-#ifdef TARGET_DARWIN
-	/* inject this first to make the intention clear */
-	newargv[j++] = "-search_paths_first";
-#endif
+
 	/* position k right after the original arguments */
 	k = j - 1 + argc;
 	for (i = 1; i < argc; i++, j++) {
-#ifdef TARGET_AIX
-		/* AIX ld has this problem:
-		 *   $ /usr/ccs/bin/ld -bsvr4 -bE:xx.exp -bnoentry xx.o
-		 *   ld: 0706-005 Cannot find or open file: l
-		 *       ld:open(): No such file or directory
-		 * Simplest workaround is to put -bsvr4 last.
-		 */
-		if (strcmp(argv[i], "-bsvr4") == 0) {
-			--j; --k;
-			continue;
+		if (is_aix(ctarget)) {
+			/* AIX ld has this problem:
+			 *   $ /usr/ccs/bin/ld -bsvr4 -bE:xx.exp -bnoentry xx.o
+			 *   ld: 0706-005 Cannot find or open file: l
+			 *       ld:open(): No such file or directory
+			 * Simplest workaround is to put -bsvr4 last.
+			 */
+			if (strcmp(argv[i], "-bsvr4") == 0) {
+				--j; --k;
+				continue;
+			}
 		}
-#endif
+
 		newargv[j] = argv[i];
-#ifndef TARGET_DARWIN
+
+		if (is_cross(ctarget) || is_darwin(ctarget))
+			continue;
+
 		/* on ELF targets we add runpaths for all found search paths */
 		if (argv[i][0] == '-' && argv[i][1] == 'L') {
 			char *path;
@@ -280,25 +434,27 @@ main(int argc, char *argv[])
 			snprintf(newargv[k], len, "-R%s", path);
 			k++;
 		}
-#endif
 	}
 	/* add the custom paths */
-#ifdef TARGET_DARWIN
-	newargv[k++] = "-L" EPREFIX "/usr/lib";
-	newargv[k++] = "-L" EPREFIX "/lib";
-#else
-	newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib/gcc";
-	newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib/gcc";
-	newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib";
-	newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib";
-	newargv[k++] = "-L" EPREFIX "/usr/lib";
-	newargv[k++] = "-R" EPREFIX "/usr/lib";
-	newargv[k++] = "-L" EPREFIX "/lib";
-	newargv[k++] = "-R" EPREFIX "/lib";
-#endif
-#ifdef TARGET_AIX
-	newargv[k++] = "-bsvr4"; /* last one, see above */
-#endif
+	if (!is_cross(ctarget)) {
+		if (is_darwin(ctarget)) {
+			/* FIXME: no support for cross-compiling *to* Darwin */
+			newargv[k++] = "-L" EPREFIX "/usr/lib";
+			newargv[k++] = "-L" EPREFIX "/lib";
+		} else {
+			newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib/gcc";
+			newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib/gcc";
+			newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib";
+			newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib";
+			newargv[k++] = "-L" EPREFIX "/usr/lib";
+			newargv[k++] = "-R" EPREFIX "/usr/lib";
+			newargv[k++] = "-L" EPREFIX "/lib";
+			newargv[k++] = "-R" EPREFIX "/lib";
+		}
+
+		if (is_aix(ctarget))
+			newargv[k++] = "-bsvr4"; /* last one, see above */
+	}
 	newargv[k] = NULL;
 
 	if (verbose) {


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2017-12-27  9:05 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2017-12-27  9:05 UTC (permalink / raw
  To: gentoo-commits

commit:     e30f557eb73bff37366a44ebbbf4efdc0c616c58
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 27 09:04:46 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Dec 27 09:04:46 2017 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=e30f557e

sys-devel/binutils-config: fix path unraveling, thanks Michael Weiser, bug #583202

Bug: https://bugs.gentoo.org/583202
Package-Manager: Portage-2.3.18-prefix, Repoman-2.3.6

 sys-devel/binutils-config/files/ldwrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index f1d5bef7d4..a8f140be27 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -228,7 +228,7 @@ main(int argc, char *argv[])
 
 		/* see to case 2 first */
 		*p = '\0';
-		if ((q = strrchr(p - 1, '/')) != NULL) {
+		if ((q = strrchr(wrapper, '/')) != NULL) {
 			/* q points to "/<CTARGET>" now */
 			len = strlen("/gcc");
 			if (q - len > wrapper && strncmp(q - len, "/gcc", len) == 0)


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2017-12-29 14:56 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2017-12-29 14:56 UTC (permalink / raw
  To: gentoo-commits

commit:     b93602ba2a0f76a9a85cb36a1740a4522e45ce36
Author:     Michael Weiser <michael.weiser <AT> gmx <DOT> de>
AuthorDate: Wed Dec 27 21:36:35 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Dec 29 14:54:50 2017 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=b93602ba

sys-devel/binutils-config: Use -rpath on Darwin

Extend ldwrapper to inject -rpath options into the linker command line
on darwin as well. Only do so if ld64 would not refuse to accept them.
This can happen if the output type doesn't support it (static, kext,
...) or the deployment target is unspecified or did not support -rpath
yet (< 10.5). The latter is not usually a problem since portage
(MACOSX_DEPLOYMENT_TARGET) and clang (-macosx_version_min) always set
the deployment target explicitly.

Signed-off-by: Michael Weiser <michael.weiser <AT> gmx.de>
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/binutils-config/files/ldwrapper.c | 79 ++++++++++++++++++++++++-----
 1 file changed, 67 insertions(+), 12 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index a8f140be27..1ed11ce42d 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -205,8 +205,10 @@ main(int argc, char *argv[])
 	char ldbuf[ESIZ];
 	char *ld = ldbuf;
 	char ctarget[128];
+	char *darwin_dt = getenv("MACOSX_DEPLOYMENT_TARGET");
 	char is_cross = 0;
 	char is_darwin = 0;
+	char darwin_use_rpath = 1;
 	char is_aix = 0;
 	char *p;
 	size_t len;
@@ -287,18 +289,52 @@ main(int argc, char *argv[])
 				newargc++;
 			if (argv[i][1] == 'v' || argv[i][1] == 'V')
 				verbose = 1;
+			if (strcmp(argv[i], "-macosx_version_min") == 0 && i < argc - 1)
+				darwin_dt = argv[i + 1];
+			/* ld64 will refuse to accept -rpath if any of the
+			 * following options are given */
+			if (strcmp(argv[i], "-static") == 0 ||
+					strcmp(argv[i], "-dylinker") == 0 ||
+					strcmp(argv[i], "-preload") == 0 ||
+					strcmp(argv[i], "-r") == 0 ||
+					strcmp(argv[i], "-kext") == 0)
+				darwin_use_rpath = 0;
 		}
 	}
-	/* account the original arguments */
-	newargc += argc;
-	/* we always add a sentinel */
-	newargc++;
+
+	/* Note: Code below assumes that newargc is the count of -L arguments. */
 
 	/* If a package being cross-compiled injects standard directories, it's
 	 * non-cross-compilable on any platform, prefix or no prefix. So no
 	 * need to add PREFIX- or CTARGET-aware libdirs. */
 	if (!is_cross) {
 		if (is_darwin) {
+			/* check deployment target if nothing prevents us from
+			 * using -rpath as of yet
+			 * # ld64 -rpath foo
+			 * ld: -rpath can only be used when targeting Mac OS X
+			 * 10.5 or later */
+			if (darwin_use_rpath) {
+				/* version format is x.y.z. atoi will stop
+				 * parsing at dots. darwin_dt != NULL isn't
+				 * just for safety: ld64 also refuses -rpath
+				 * when not given a deployment target at all */
+				darwin_use_rpath = darwin_dt != NULL &&
+					(atoi(darwin_dt) > 10 ||
+					 (strncmp(darwin_dt, "10.", 3) == 0 &&
+					  atoi(darwin_dt + 3) >= 5));
+			}
+
+			if (darwin_use_rpath) {
+				/* We need two additional arguments for each:
+				 * -rpath and the path itself */
+				newargc *= 2;
+
+				/* and we will be adding two for the each of
+				 * the two system paths as well */
+				newargc += 4;
+			}
+
 			/* add the 2 prefix paths (-L) and -search_paths_first */
 			newargc += 2 + 1;
 		} else {
@@ -312,6 +348,11 @@ main(int argc, char *argv[])
 		}
 	}
 
+	/* account the original arguments */
+	newargc += argc;
+	/* we always add a sentinel */
+	newargc++;
+
 	/* let's first try to find the real ld */
 	if (find_real_ld(&ld, sizeof(ldbuf), verbose, is_cross,
 				wrapper, ctarget) != 0)
@@ -358,7 +399,7 @@ main(int argc, char *argv[])
 
 		newargv[j] = argv[i];
 
-		if (is_cross || is_darwin)
+		if (is_cross || (is_darwin && !darwin_use_rpath))
 			continue;
 
 		/* on ELF targets we add runpaths for all found search paths */
@@ -390,14 +431,21 @@ main(int argc, char *argv[])
 			if (builddir != NULL && strncmp(builddir, path, len) != 0)
 				continue;
 
-			sze = 2 + strlen(path) + 1;
-			newargv[k] = malloc(sizeof(char) * sze);
-			if (newargv[k] == NULL) {
-				fprintf(stderr, "%s: failed to allocate memory for "
-						"'%s' -R argument\n", wrapper, argv[i]);
-				exit(1);
+			if (is_darwin) {
+				newargv[k] = "-rpath";
+				newargv[++k] = path;
+			} else {
+				sze = 2 + strlen(path) + 1;
+				newargv[k] = malloc(sizeof(char) * sze);
+				if (newargv[k] == NULL) {
+					fprintf(stderr, "%s: failed to allocate memory for "
+							"'%s' -R argument\n", wrapper, argv[i]);
+					exit(1);
+				}
+
+				snprintf(newargv[k], sze, "-R%s", path);
 			}
-			snprintf(newargv[k], sze, "-R%s", path);
+
 			k++;
 		}
 	}
@@ -407,6 +455,13 @@ main(int argc, char *argv[])
 			/* FIXME: no support for cross-compiling *to* Darwin */
 			newargv[k++] = "-L" EPREFIX "/usr/lib";
 			newargv[k++] = "-L" EPREFIX "/lib";
+
+			if (darwin_use_rpath) {
+				newargv[k++] = "-rpath";
+				newargv[k++] = EPREFIX "/usr/lib";
+				newargv[k++] = "-rpath";
+				newargv[k++] = EPREFIX "/lib";
+			}
 		} else {
 			newargv[k++] = "-L" EPREFIX "/usr/" CHOST "/lib/gcc";
 			newargv[k++] = "-R" EPREFIX "/usr/" CHOST "/lib/gcc";


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2018-01-31  9:50 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2018-01-31  9:50 UTC (permalink / raw
  To: gentoo-commits

commit:     edc0d44f70c27daebcc080ac5d08e8e191bccd95
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 31 09:49:10 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jan 31 09:50:06 2018 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=edc0d44f

sys-devel/binutils-config: fix inversed logic

Obviously we should skip turning -L into -R if the path points inside
PORTAGE_BUILDDIR, not the other way around.

Thanks to this, bugs like #642040 surfaced.

Bug: https://bugs.gentoo.org/642040

 sys-devel/binutils-config/files/ldwrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 1ed11ce42d..3ff52acc60 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -428,7 +428,7 @@ main(int argc, char *argv[])
 				continue;
 
 			/* does it refer to the build directory? skip */
-			if (builddir != NULL && strncmp(builddir, path, len) != 0)
+			if (builddir != NULL && strncmp(builddir, path, len) == 0)
 				continue;
 
 			if (is_darwin) {


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2020-11-27 13:39 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2020-11-27 13:39 UTC (permalink / raw
  To: gentoo-commits

commit:     acc649995abf68f60667fd91dce2c47704f4130f
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 13:12:17 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 13:38:56 2020 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=acc64999

sys-devel/binutils-config: drop libmissing support

libmissing is masked and soon to be removed, it never really worked in
the way it was hoped it could

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/binutils-config/files/ldwrapper.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 07dc6ebf2a..216747da5c 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -210,7 +210,6 @@ main(int argc, char *argv[])
 	char is_darwin = 0;
 	char darwin_use_rpath = 1;
 	char is_aix = 0;
-	char has_missing = getenv("BINUTILS_CONFIG_DISABLE_MISSING") == NULL;
 	char *p;
 	size_t len;
 	int i;
@@ -349,14 +348,6 @@ main(int argc, char *argv[])
 			/* AIX ld accepts -R only with -bsvr4 */
 			newargc++; /* -bsvr4 */
 		}
-
-		/* BINUTILS_CONFIG_DISABLE_MISSING overrides this such that we
-		 * can disable this behaviour */
-		if (has_missing && stat(EPREFIX "/usr/lib/libmissing.a", &st) == 0) {
-			newargc++; /* -lmissing */
-		} else {
-			has_missing = 0;
-		}
 	}
 
 	/* account the original arguments */
@@ -408,20 +399,6 @@ main(int argc, char *argv[])
 			}
 		}
 
-		if (!is_cross && is_darwin && has_missing) {
-			if (argv[i][0] == '-' && argv[i][1] == 'l' &&
-					(strcmp(&argv[i][2], "System") == 0 ||
-					 strcmp(&argv[i][2], "SystemStubs") == 0))
-			{
-				/* inject -lmissing before -lSystem or -lSystemStubs */
-				memmove(&newargv[j + 1], &newargv[j],
-						sizeof(newargv[j]) * (k - j));
-				newargv[j++] = "-lmissing";
-				k++;
-				has_missing = 0;  /* avoid duplicate insertion */
-			}
-		}
-
 		newargv[j] = argv[i];
 
 		if (is_cross || (is_darwin && !darwin_use_rpath))
@@ -498,8 +475,6 @@ main(int argc, char *argv[])
 			newargv[k++] = "-R" EPREFIX "/lib";
 		}
 
-		if (has_missing)
-			newargv[k++] = "-lmissing";
 		if (is_aix)
 			newargv[k++] = "-bsvr4"; /* last one, see above */
 	}


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2020-11-27 13:57 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2020-11-27 13:57 UTC (permalink / raw
  To: gentoo-commits

commit:     40f8991efebfd3ddfe46336f0f3019904dcaece7
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 13:56:56 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 13:56:56 2020 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=40f8991e

sys-devel/binutils-config-5.1-r3: fix embarrasing syntax error

Package-Manager: Portage-3.0.8-prefix, Repoman-3.0.2
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/binutils-config/files/ldwrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 75575f31f6..3ff5a0bc3e 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -388,7 +388,7 @@ main(int argc, char *argv[])
 		/* inject this first to make the intention clear */
 #ifdef DARWIN_LD_SYSLIBROOT
 		newargv[j++] = "-syslibroot";
-		newargv[j++] = EPREFIX "/MacOSX.sdk"
+		newargv[j++] = EPREFIX "/MacOSX.sdk";
 #endif
 		newargv[j++] = "-search_paths_first";
 	}


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2023-09-26 19:38 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2023-09-26 19:38 UTC (permalink / raw
  To: gentoo-commits

commit:     753907f35f78864cf66a7bc084b32eb56b31684d
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Sep 26 19:30:33 2023 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Sep 26 19:35:52 2023 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=753907f3

sys-apps/binutils-config: fix ldwrapper for CLT 15

Because -platform_version is actually supported since a while, and we
don't really support older versions (except Darwin 17 and 9 which use
way different versions), just switch to using platform_version when the
target is macos 12 or up.

Closes: https://bugs.gentoo.org/910277
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/binutils-config/files/ldwrapper.c | 60 ++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 10 deletions(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index 1b5fa19ad3..16932af5d6 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -207,6 +207,7 @@ main(int argc, char *argv[])
 	char *ld = ldbuf;
 	char ctarget[128];
 	char *darwin_dt = getenv("MACOSX_DEPLOYMENT_TARGET");
+	int darwin_dt_ver = 0;
 	char is_cross = 0;
 	char is_darwin = 0;
 	char darwin_use_rpath = 1;
@@ -293,8 +294,12 @@ main(int argc, char *argv[])
 				newargc++;
 			if (argv[i][1] == 'v' || argv[i][1] == 'V')
 				verbose = 1;
-			if (strcmp(argv[i], "-macosx_version_min") == 0 && i < argc - 1)
+			if ((strcmp(argv[i], "-macosx_version_min") == 0 ||
+				 strcmp(argv[i], "-macos_version_min") == 0) && i < argc - 1)
 				darwin_dt = argv[i + 1];
+			if (strcmp(argv[i], "-platform_version") == 0 &&
+				i < argc - 3 && strcmp(argv[i + 1], "macos") == 0)
+				darwin_dt = argv[i + 2];
 			/* ld64 will refuse to accept -rpath if any of the
 			 * following options are given */
 			if (strcmp(argv[i], "-static") == 0 ||
@@ -306,6 +311,12 @@ main(int argc, char *argv[])
 		}
 	}
 
+	if (is_darwin && darwin_dt != NULL) {
+		darwin_dt_ver = (int)strtol(darwin_dt, &p, 10) * 100;
+		if (*p == '.')
+			darwin_dt_ver += (int)strtol(p + 1, &p, 10);
+	}
+
 	/* Note: Code below assumes that newargc is the count of -L arguments. */
 
 	/* If a package being cross-compiled injects standard directories, it's
@@ -325,10 +336,7 @@ main(int argc, char *argv[])
 				 * parsing at dots. darwin_dt != NULL isn't
 				 * just for safety: ld64 also refuses -rpath
 				 * when not given a deployment target at all */
-				darwin_use_rpath = darwin_dt != NULL &&
-					(atoi(darwin_dt) > 10 ||
-					 (strncmp(darwin_dt, "10.", 3) == 0 &&
-					  atoi(darwin_dt + 3) >= 5));
+				darwin_use_rpath = darwin_dt_ver >= 1005;
 			}
 
 			if (darwin_use_rpath) {
@@ -345,8 +353,8 @@ main(int argc, char *argv[])
 			newargc += 2 + 1;
 
 #ifdef DARWIN_LD_SYSLIBROOT
-			/* add -syslibroot <path> -sdk_version <ver> */
-			newargc += 4;
+			/* add -syslibroot <path> -platform_version macos <ver> 0.0 */
+			newargc += 6;
 #endif
 		} else {
 			/* add the 4 paths we want (-L + -R) */
@@ -393,8 +401,17 @@ main(int argc, char *argv[])
 		 * version here, for the sdk link can be versionless when set to
 		 * CommandLineTools */
 #ifdef DARWIN_LD_SYSLIBROOT
-		newargv[j++] = "-sdk_version";
-		newargv[j++] = darwin_dt;
+		/* bug #910277: transform into platform_version arg for newer
+		 * targets */
+		if (darwin_dt_ver >= 1200) {
+			newargv[j++] = "-platform_version";
+			newargv[j++] = "macos";
+			newargv[j++] = darwin_dt;
+			newargv[j++] = "0.0";
+		} else {
+			newargv[j++] = "-sdk_version";
+			newargv[j++] = darwin_dt;
+		}
 		newargv[j++] = "-syslibroot";
 		newargv[j++] = EPREFIX "/MacOSX.sdk";
 #endif
@@ -405,6 +422,26 @@ main(int argc, char *argv[])
 	/* position k right after the original arguments */
 	k = j - 1 + argc;
 	for (i = 1; i < argc; i++, j++) {
+#ifdef DARWIN_LD_SYSLIBROOT
+		if (is_darwin) {
+			/* skip platform version stuff, we already pushed it out */
+			if ((strcmp(argv[i], "-macosx_version_min") == 0 ||
+				 strcmp(argv[i], "-macos_version_min") == 0) && i < argc - 1)
+			{
+				i++;
+				j--;
+				continue;
+			}
+			if (strcmp(argv[i], "-platform_version") == 0 &&
+				i < argc - 3 && strcmp(argv[i + 1], "macos") == 0)
+			{
+				i += 3;
+				j--;
+				continue;
+			}
+		}
+#endif
+
 		newargv[j] = argv[i];
 
 		if (is_cross || (is_darwin && !darwin_use_rpath))
@@ -487,7 +524,10 @@ main(int argc, char *argv[])
 	if (verbose) {
 		fprintf(stderr, "%s: invoking %s with arguments:\n", wrapper, ld);
 		for (j = 0; newargv[j] != NULL; j++)
-			fprintf(stderr, "  %s\n", newargv[j]);
+			fprintf(stderr, "  %s%s",
+					newargv[j],
+					newargv[j + 1] != NULL && newargv[j + 1][0] != '-'
+					? "" : "\n");
 	}
 
 	/* finally, execute the real ld */


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
@ 2024-01-13 14:29 Fabian Groffen
  0 siblings, 0 replies; 17+ messages in thread
From: Fabian Groffen @ 2024-01-13 14:29 UTC (permalink / raw
  To: gentoo-commits

commit:     fbcb941fc6fe8c31ceb219dc56127e62906ae520
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 13 14:22:50 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan 13 14:22:50 2024 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=fbcb941f

sys-devel/binutils-config: make ld arguments depending on OS release

This is somewhat shady, because we'd need the target ld's version, but
it's better to use the current platform version rather than the
requested platform version since the latter has nothing to do with which
linker is being used.

Not bumping the version, since existing installs don't have this issue,
and only new installs on Sanoma suffer from this, which never managed to
succeed, so basically don't exist yet.

Bug: https://bugs.gentoo.org/916291
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/binutils-config/files/ldwrapper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
index a1639ca5aa..df29b04c96 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 	char ctarget[128];
 	char *darwin_dt = getenv("MACOSX_DEPLOYMENT_TARGET");
 	int darwin_dt_ver = 0;
+	int darwin_ld_trg_ver = 0;
 	char is_cross = 0;
 	char is_darwin = 0;
 	char darwin_use_rpath = 1;
@@ -222,6 +223,9 @@ main(int argc, char *argv[])
 #ifdef DARWIN_LD_DEFAULT_TARGET
 	if (darwin_dt == NULL)
 		darwin_dt = DARWIN_LD_DEFAULT_TARGET;
+	darwin_ld_trg_ver = (int)strtol(DARWIN_LD_DEFAULT_TARGET, &p, 10) * 100;
+	if (*p == '.')
+		darwin_ld_trg_ver += (int)strtol(p + 1, &p, 10);
 #endif
 
 	/* two ways to determine CTARGET from argv[0]:
@@ -403,7 +407,7 @@ main(int argc, char *argv[])
 #ifdef DARWIN_LD_SYSLIBROOT
 		/* bug #910277: transform into platform_version arg for newer
 		 * targets */
-		if (darwin_dt_ver >= 1200) {
+		if (darwin_ld_trg_ver >= 1200) {
 			newargv[j++] = "-platform_version";
 			newargv[j++] = "macos";
 			newargv[j++] = darwin_dt;


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-01-13 14:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-27  9:05 [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/ Fabian Groffen
  -- strict thread matches above, loose matches on Subject: below --
2024-01-13 14:29 Fabian Groffen
2023-09-26 19:38 Fabian Groffen
2020-11-27 13:57 Fabian Groffen
2020-11-27 13:39 Fabian Groffen
2018-01-31  9:50 Fabian Groffen
2017-12-29 14:56 Fabian Groffen
2017-12-25 19:47 Fabian Groffen
2017-11-29 15:21 Fabian Groffen
2017-11-25 18:33 Fabian Groffen
2016-05-15 16:44 Fabian Groffen
2016-05-13 12:14 Fabian Groffen
2016-05-13 12:14 Fabian Groffen
2016-05-13 12:14 Fabian Groffen
2016-04-18  8:07 Michael Haubenwallner
2016-02-15 14:30 Fabian Groffen
2016-02-14 14:56 Fabian Groffen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox