From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 27B9E138010 for ; Mon, 15 Feb 2016 14:30:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A969F21C001; Mon, 15 Feb 2016 14:30:47 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 21F3321C002 for ; Mon, 15 Feb 2016 14:30:47 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D7F7B340BD1 for ; Mon, 15 Feb 2016 14:30:45 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 71522CFF for ; Mon, 15 Feb 2016 14:30:42 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1455546637.8cb9c22e827757a7c5151c53afb2b4d4e0a3d0c6.grobian@gentoo> Subject: [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/ X-VCS-Repository: repo/proj/prefix X-VCS-Files: sys-devel/binutils-config/files/ldwrapper.c X-VCS-Directories: sys-devel/binutils-config/files/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 8cb9c22e827757a7c5151c53afb2b4d4e0a3d0c6 X-VCS-Branch: master Date: Mon, 15 Feb 2016 14:30:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 742447c6-fac8-4764-ad25-ca753ce55600 X-Archives-Hash: 28f67f390ff7e35c875e7af8c4754fa5 commit: 8cb9c22e827757a7c5151c53afb2b4d4e0a3d0c6 Author: Fabian Groffen gentoo org> AuthorDate: Mon Feb 15 14:30:37 2016 +0000 Commit: Fabian Groffen gentoo 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 + * -L (yes, this is accepted) + * -L(whitespace)? + * 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);