From patchwork Fri Feb 15 11:22:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Beresford X-Patchwork-Id: 220720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id D77362C0079 for ; Fri, 15 Feb 2013 22:28:59 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 09D3E10B87D; Fri, 15 Feb 2013 11:28:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7SKTit+sN-uH; Fri, 15 Feb 2013 11:28:40 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id D12E810B861; Fri, 15 Feb 2013 11:28:39 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id C09138F7A3 for ; Fri, 15 Feb 2013 11:28:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 810D38CA39 for ; Fri, 15 Feb 2013 11:28:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x8l1Z561F6OU for ; Fri, 15 Feb 2013 11:28:49 +0000 (UTC) X-Greylist: delayed 00:06:57 by SQLgrey-1.7.6 Received: from mail1.bemta5.messagelabs.com (mail1.bemta5.messagelabs.com [195.245.231.130]) by whitealder.osuosl.org (Postfix) with ESMTPS id 810958BDE2 for ; Fri, 15 Feb 2013 11:28:48 +0000 (UTC) Received: from [85.158.139.3:9254] by server-1.bemta-5.messagelabs.com id ED/C7-29263-D4A1E115; Fri, 15 Feb 2013 11:21:49 +0000 X-Env-Sender: greg.beresford@zbdsolutions.com X-Msg-Ref: server-13.tower-90.messagelabs.com!1360927309!32031031!2 X-Originating-IP: [217.28.130.38] X-StarScan-Received: X-StarScan-Version: 6.7; banners=zbdsolutions.com,-,- X-VirusChecked: Checked Received: (qmail 10146 invoked from network); 15 Feb 2013 11:21:49 -0000 Received: from hostedexchange.hostedservice.com (HELO outlook.hostedservice2.net) (217.28.130.38) by server-13.tower-90.messagelabs.com with AES128-SHA encrypted SMTP; 15 Feb 2013 11:21:49 -0000 Received: from THHS2E12BE9X.hostedservice2.net ([fe80::d954:f60d:24ea:35f]) by THHS2E12HT08.hostedservice2.net ([::1]) with mapi; Fri, 15 Feb 2013 11:21:49 +0000 From: Greg Beresford To: "buildroot@busybox.net" Content-Class: urn:content-classes:message Date: Fri, 15 Feb 2013 11:22:00 +0000 Thread-Topic: Using external toolchain wrapper outside of buildroot Thread-Index: Ac4Lbn2O0dk9xhLKTWqSb89rfMB88Q== Message-ID: Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, en-GB MIME-Version: 1.0 Subject: [Buildroot] Using external toolchain wrapper outside of buildroot X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net Hi all, It looks like making the external toolchain wrapper relocatable may have broken it for use outside of buildroot. If you add the wrapper directory to your path and invoke the wrapper as arm-linux-gcc (for example), execution will enter the 'else' on line 76 of ext-toolchain-wrapper.c. This sets basename to arm-linux-gcc, which is fine, but it also sets absbasedir to whatever $(pwd)/../.. resolves to which then gets used when calculating the sysroot directory, resulting in gcc not having the real sysroot in its search paths. The above all works fine if the wrapper is invoked with an absolute path. (I've not tried with a relative path with slashes in.) I've attached a patch with a fix below which calculates absbasedir from /proc/self/exe. (I don't know of any other way of reliably getting the path to the current executable.) My C is rusty though, so it might need to be fixed up before it's applied. (Was there a reason for avoiding the basename and dirname functions from libgen.h?) Cheers Greg zbd d +44 (0) 1344 292 123 t +44 (0)1344 292 110 w www.zbdsolutions.com ZBD Displays Ltd | Building 3 | Kingswood | Kings Ride | Ascot | Berkshire | SL5 8AD | UK From 9f0a2566bc15e2f7115dce58db9dec84d98b844b Mon Sep 17 00:00:00 2001 From: Greg Beresford Date: Thu, 14 Feb 2013 18:25:43 +0000 Subject: [PATCH] Fix toolchain wrapper when used outside of buildroot Acked-by: Daniel Nyström --- .../toolchain-external/ext-toolchain-wrapper.c | 50 ++++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) -- 1.8.0 Disclaimer: This email contains proprietary information some or all of which may be legally privileged and/or is confidential. It is for the intended recipient only. If an addressing or transmission error has misdirected this email, please notify the author by replying to this email. If you are not the intended recipient, you must not use, disclose, distribute, copy or print this email. Any views expressed in this message are those of the individual sender, except where the message states otherwise. ZBD Displays accepts no responsibility for any computer virus which might be transferred by way of this email. We may monitor all email communication through our networks. If you contact us by email, we may store your name and address to facilitate communication. ZBD Displays Ltd is registered in England and Wales, company registration number: 03929602. Registered Office: Malvern Hills Science Park, Geraldine Road, Malvern, Worcestershire, WR14 3SZ, UK diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c index a92bada..f570554 100644 --- a/toolchain/toolchain-external/ext-toolchain-wrapper.c +++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c @@ -19,6 +19,7 @@ #include #include #include +#include static char path[PATH_MAX]; static char sysroot[PATH_MAX]; @@ -56,26 +57,37 @@ int main(int argc, char **argv) { char **args, **cur; char *relbasedir, *absbasedir; - char *progpath = argv[0]; - char *basename; + char exepath[PATH_MAX + 1] = {0}; + char *dupbase, *base, *dir; int ret; + ssize_t ret_size; + + ret_size = readlink("/proc/self/exe", exepath, sizeof(exepath) - 1); + if (ret_size < 0) + { + perror(__FILE__ ": readlink"); + return 2; + } + else if (ret_size >= sizeof(exepath)) + { + perror(__FILE__ ": readlink return value out of bounds"); + return 2; + } + exepath[ret_size] = '\0'; /* Calculate the relative paths */ - basename = strrchr(progpath, '/'); - if (basename) { - *basename = '\0'; - basename++; - relbasedir = malloc(strlen(progpath) + 7); - if (relbasedir == NULL) { - perror(__FILE__ ": malloc"); - return 2; - } - sprintf(relbasedir, "%s/../..", argv[0]); - absbasedir = realpath(relbasedir, NULL); - } else { - basename = progpath; - absbasedir = realpath("../..", NULL); + dupbase = strdup(argv[0]); + base = basename(dupbase); + dir = dirname(exepath); + + relbasedir = malloc(strlen(dir) + 7); + if (relbasedir == NULL) { + perror(__FILE__ ": malloc"); + return 2; } + sprintf(relbasedir, "%s/../..", dir); + absbasedir = realpath(relbasedir, NULL); + if (absbasedir == NULL) { perror(__FILE__ ": realpath"); return 2; @@ -83,10 +95,12 @@ int main(int argc, char **argv) /* Fill in the relative paths */ #ifdef BR_CROSS_PATH_REL - ret = snprintf(path, sizeof(path), "%s/" BR_CROSS_PATH_REL "/%s", absbasedir, basename); + ret = snprintf(path, sizeof(path), "%s/" BR_CROSS_PATH_REL "/%s", absbasedir, base); #else /* BR_CROSS_PATH_ABS */ - ret = snprintf(path, sizeof(path), BR_CROSS_PATH_ABS "/%s", basename); + ret = snprintf(path, sizeof(path), BR_CROSS_PATH_ABS "/%s", base); #endif + free(dupbase); + if (ret >= sizeof(path)) { perror(__FILE__ ": overflow"); return 3;