From owner-freebsd-bugs@FreeBSD.ORG Fri Oct 28 07:00:30 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5260816A422 for ; Fri, 28 Oct 2005 07:00:30 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6B35443D53 for ; Fri, 28 Oct 2005 07:00:29 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j9S70Tcw072968 for ; Fri, 28 Oct 2005 07:00:29 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j9S70Trs072963; Fri, 28 Oct 2005 07:00:29 GMT (envelope-from gnats) Resent-Date: Fri, 28 Oct 2005 07:00:29 GMT Resent-Message-Id: <200510280700.j9S70Trs072963@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Nakata Maho Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 842E516A41F for ; Fri, 28 Oct 2005 06:56:01 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1693343D45 for ; Fri, 28 Oct 2005 06:56:01 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j9S6u0Y1027133 for ; Fri, 28 Oct 2005 06:56:00 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j9S6u0nt027130; Fri, 28 Oct 2005 06:56:00 GMT (envelope-from nobody) Message-Id: <200510280656.j9S6u0nt027130@www.freebsd.org> Date: Fri, 28 Oct 2005 06:56:00 GMT From: Nakata Maho To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: bin/88117: support of $ORIGIN in rtld-elf. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2005 07:00:30 -0000 >Number: 88117 >Category: bin >Synopsis: support of $ORIGIN in rtld-elf. >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Oct 28 07:00:28 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Nakata Maho >Release: 5.4-RELEASE >Organization: FreeBSD.org >Environment: FreeBSD satie.private.org 5.4-RELEASE-p6 FreeBSD 5.4-RELEASE-p6 #0: Sat Sep 3 09:47:26 JST 2005 maho@satie.private.org:/usr/src/sys/i386/compile/MAHO i386 >Description: if $ORIGIN is passed via -rpath, option of ld, we replace $ORIGIN by full path of current directory where the execultables or shared libs exist. e.g. % pwd /u/l/c gcc -Wl,-rpath,'$ORIGIN' foo.o -ltest1 -ltest2 ldd ./a.out ./a.out libc.so.5 => /lib/libc.so.5 (0x123333) libtest1.so.6 => /u/l/c/libtest1.so.6 (0x12345678) libtest2.so.3 => /u/l/c/libtest2.so.3 (0x90ABCDEF) etc. we also allow such usage as well, like LD_LIBRARY_PATH. gcc -Wl,-rpath,'$ORIGIN/../:$ORIGIN' foo.o -ltest1 -ltest2 >How-To-Repeat: >Fix: --- /usr/src/libexec/rtld-elf/rtld.c.org Sun Oct 23 19:11:26 2005 +++ /usr/src/libexec/rtld-elf/rtld.c Tue Oct 25 14:49:34 2005 @@ -862,6 +862,10 @@ { char *pathname; char *name; + char *rpath; + char *origin_realpath; + char *p, *q, *r; + int i; if (strchr(xname, '/') != NULL) { /* Hard coded pathname */ if (xname[0] != '/' && !trust) { @@ -878,9 +882,31 @@ dbg(" Searching for \"%s\"", name); +/* expand $ORIGIN in refobj->rpath if not NULL */ + rpath=NULL; + if(refobj->rpath!=NULL){ + rpath = xmalloc(PATH_MAX); /* full rpath with $ORIGIN expanded */ + origin_realpath = xmalloc(PATH_MAX); + realpath(refobj->path, origin_realpath); /* expand $ORIGIN by real path */ + i=strlen(origin_realpath); + while(origin_realpath[i]!='/') {origin_realpath[i--]='\0';} origin_realpath[i]='\0';/* basename */ + q=(char *)refobj->rpath; + p=strstr(q,"$ORIGIN"); + r=rpath; + if(p==NULL) {rpath=(char *)refobj->rpath;}else{ + while(p!=NULL){ + for(i=0;q+irpath)) != NULL) || + (pathname = search_library_path(name, rpath)) != NULL) || (pathname = search_library_path(name, gethints())) != NULL || (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL) return pathname; I don't know how to free rpath and origin_realpath... >Release-Note: >Audit-Trail: >Unformatted: