commit:     f1ad58d7b8db30325c5aa9bc89c130e26fbea594
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 13 18:11:54 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Oct 13 18:11:54 2019 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=f1ad58d7

sys-devel/binutils-config: experimental support for libmissing

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

 sys-devel/binutils-config/Manifest                 |  1 -
 ...5.1-r1.ebuild => binutils-config-5.1-r2.ebuild} |  5 ++-
 sys-devel/binutils-config/files/ldwrapper.c        | 51 +++++++++++++++++-----
 3 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/sys-devel/binutils-config/Manifest 
b/sys-devel/binutils-config/Manifest
deleted file mode 100644
index a28d45bba6..0000000000
--- a/sys-devel/binutils-config/Manifest
+++ /dev/null
@@ -1 +0,0 @@
-DIST binutils-config-ldwrapper-5.3.4.c 13467 BLAKE2B 
132c497c59c1315c4d9e85c842fa5636aac5d96aa2db69e1f677c31cd8a509653589c178058285c4e2e72d5095734f6849969f9ff99edfe1794c69733b60047c
 SHA512 
cd4f33e37b2cd9e66d2e80aec28bec56e3d5383f15018b20c1afccd00e74d5f8ac2c6c2d8dde0de4be36aeec1237e2cc9b07326bceb24b2ca819e54c65ae6478

diff --git a/sys-devel/binutils-config/binutils-config-5.1-r1.ebuild 
b/sys-devel/binutils-config/binutils-config-5.1-r2.ebuild
similarity index 86%
rename from sys-devel/binutils-config/binutils-config-5.1-r1.ebuild
rename to sys-devel/binutils-config/binutils-config-5.1-r2.ebuild
index 5cae4a9223..d104bf4fb7 100644
--- a/sys-devel/binutils-config/binutils-config-5.1-r1.ebuild
+++ b/sys-devel/binutils-config/binutils-config-5.1-r2.ebuild
@@ -9,7 +9,7 @@ DESCRIPTION="Utility to change the binutils version being used"
 HOMEPAGE="https://www.gentoo.org/";
 GIT_REV="edc0d44f70c27daebcc080ac5d08e8e191bccd95"
 WRAPPER_REV="${PV%%.*}.3.4"
-SRC_URI="https://gitweb.gentoo.org/repo/proj/prefix.git/plain/sys-devel/binutils-config/files/ldwrapper.c?id=${GIT_REV}
 -> ${PN}-ldwrapper-${WRAPPER_REV}.c"
+#SRC_URI="https://gitweb.gentoo.org/repo/proj/prefix.git/plain/sys-devel/binutils-config/files/ldwrapper.c?id=${GIT_REV}
 -> ${PN}-ldwrapper-${WRAPPER_REV}.c"
 
 LICENSE="GPL-2"
 SLOT="0"
@@ -25,6 +25,7 @@ S=${WORKDIR}
 # NOTE: the ld wrapper is only enabled on rpath versions of prefix.
 src_prepare() {
        cp "${FILESDIR}"/${PN}-${PV} ./${PN} || die
+       cp "${FILESDIR}"/ldwrapper.c ./${PN}-ldwrapper-${WRAPPER_REV}.c || die
        if use prefix-guest; then
                epatch "${FILESDIR}/${PN}-5-ldwrapper.patch"
        fi
@@ -42,7 +43,7 @@ src_compile() {
                $(tc-getCC)
                ${CPPFLAGS}
                ${CFLAGS}
-               -o ldwrapper "${DISTDIR}"/${PN}-ldwrapper-${WRAPPER_REV}.c
+               -o ldwrapper ${PN}-ldwrapper-${WRAPPER_REV}.c
                -DEPREFIX=\"${EPREFIX}\"
                -DCHOST=\"${CHOST}\"
                ${LDFLAGS}

diff --git a/sys-devel/binutils-config/files/ldwrapper.c 
b/sys-devel/binutils-config/files/ldwrapper.c
index 3ff52acc60..07dc6ebf2a 100644
--- a/sys-devel/binutils-config/files/ldwrapper.c
+++ b/sys-devel/binutils-config/files/ldwrapper.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2017 Gentoo Foundation
+ * Copyright 1999-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  * Authors: Fabian Groffen <[email protected]>
  *          Michael Haubenwallner <[email protected]>
@@ -58,13 +58,13 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
        ldoverride = getenv("BINUTILS_CONFIG_LD");
        if (ldoverride != NULL && *ldoverride != '\0') {
                if (verbose)
-                       fprintf(stdout, "%s: using BINUTILS_CONFIG_LD=%s "
+                       fprintf(stderr, "%s: using BINUTILS_CONFIG_LD=%s "
                                        "from environment\n", wrapper, 
ldoverride);
                snprintf(*ld, ldlen, "%s", ldoverride);
                return 0;
        }
        if (verbose)
-               fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in 
environment\n",
+               fprintf(stderr, "%s: BINUTILS_CONFIG_LD not found in 
environment\n",
                                wrapper);
 
        /* Find ld in PATH, allowing easy PATH overrides.
@@ -94,14 +94,14 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
                        /* glue it together */
                        snprintf(*ld, ldlen, "%.*s/%s", (int)(q - p), p, 
wrapper);
                        if (verbose)
-                               fprintf(stdout, "%s: trying from PATH: %s\n",
+                               fprintf(stderr, "%s: trying from PATH: %s\n",
                                                wrapper, *ld);
                        if (stat(*ld, &lde) == 0)
                                return 0;
                }
        }
        if (verbose)
-               fprintf(stdout, "%s: linker not found in PATH\n", wrapper);
+               fprintf(stderr, "%s: linker not found in PATH\n", wrapper);
 
        /* parse EPREFIX/etc/env.d/binutils/config-CTARGET to get CURRENT, then
         * consider $EPREFIX/usr/CTARGET/binutils-bin/CURRENT where we should
@@ -123,7 +123,7 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
 
                        q = p + len;
                        if (verbose)
-                               fprintf(stdout, "%s: %s defines CURRENT=%s\n",
+                               fprintf(stderr, "%s: %s defines CURRENT=%s\n",
                                                wrapper, config, q);
                        if (is_cross) {
                                snprintf(*ld, ldlen,
@@ -138,13 +138,13 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
                }
                fclose(f);
                if (verbose)
-                       fprintf(stdout, "%s: trying from %s: %s\n",
+                       fprintf(stderr, "%s: trying from %s: %s\n",
                                        wrapper, config, *ld);
                if (stat(*ld, &lde) == 0)
                        return 0;
        }
        if (verbose)
-               fprintf(stdout, "%s: linker not found via %s\n", wrapper, 
config);
+               fprintf(stderr, "%s: linker not found via %s\n", wrapper, 
config);
 
        /* last try, shell out to binutils-config to tell us what the linker
         * is supposed to be */
@@ -178,7 +178,7 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
                                }
 
                                if (verbose)
-                                       fprintf(stdout, "%s: trying from %s: 
%s\n",
+                                       fprintf(stderr, "%s: trying from %s: 
%s\n",
                                                        wrapper, config, *ld);
                                if (stat(*ld, &lde) == 0)
                                        return 0;
@@ -186,7 +186,7 @@ find_real_ld(char **ld, size_t ldlen, const char verbose, 
const char is_cross,
                }
        }
        if (verbose)
-               fprintf(stdout, "%s: linker not found via %s\n",
+               fprintf(stderr, "%s: linker not found via %s\n",
                                wrapper, config);
 
        /* we didn't succeed finding the linker */
@@ -210,6 +210,7 @@ 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;
@@ -308,6 +309,8 @@ main(int argc, char *argv[])
         * non-cross-compilable on any platform, prefix or no prefix. So no
         * need to add PREFIX- or CTARGET-aware libdirs. */
        if (!is_cross) {
+               struct stat st;
+
                if (is_darwin) {
                        /* check deployment target if nothing prevents us from
                         * using -rpath as of yet
@@ -346,6 +349,14 @@ 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 */
@@ -397,6 +408,20 @@ 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))
@@ -473,15 +498,17 @@ 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 */
        }
        newargv[k] = NULL;
 
        if (verbose) {
-               fprintf(stdout, "%s: invoking %s with arguments:\n", wrapper, 
ld);
+               fprintf(stderr, "%s: invoking %s with arguments:\n", wrapper, 
ld);
                for (j = 0; newargv[j] != NULL; j++)
-                       fprintf(stdout, "  %s\n", newargv[j]);
+                       fprintf(stderr, "  %s\n", newargv[j]);
        }
 
        /* finally, execute the real ld */

Reply via email to