From owner-freebsd-hackers Tue Feb 5 19: 8:54 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mailout01.sul.t-online.com (mailout01.sul.t-online.com [194.25.134.80]) by hub.freebsd.org (Postfix) with ESMTP id 298F837B42B for ; Tue, 5 Feb 2002 19:08:48 -0800 (PST) Received: from fwd03.sul.t-online.de by mailout01.sul.t-online.com with smtp id 16YIRz-0006IB-00; Wed, 06 Feb 2002 04:08:47 +0100 Received: from frolic.no-support.loc (520094253176-0001@[80.130.202.111]) by fmrl03.sul.t-online.com with esmtp id 16YIRy-0bgWZ6C; Wed, 6 Feb 2002 04:08:46 +0100 Received: (from bjoern@localhost) by frolic.no-support.loc (8.11.6/8.9.3) id g1633w103183; Wed, 6 Feb 2002 04:03:58 +0100 (CET) (envelope-from bjoern) From: Bjoern Fischer Date: Wed, 6 Feb 2002 04:03:57 +0100 To: John Polstra Cc: hackers@FreeBSD.ORG Subject: [patch] using ldd on shared libraries Message-ID: <20020206030357.GB2162@frolic.no-support.loc> References: <20020201201018.GB2992@frolic.no-support.loc> <20020201212028.GC2992@frolic.no-support.loc> <200202020424.g124OXD03238@vashon.polstra.com> <20020202125107.GA481@frolic.no-support.loc> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="EeQfGwPcQSOJBaQU" Content-Disposition: inline In-Reply-To: <20020202125107.GA481@frolic.no-support.loc> User-Agent: Mutt/1.3.25i X-Sender: 520094253176-0001@t-dialin.net Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello John, I had to closer look into shared objects wrt self-containedness. Here is a patch for ldd(1), that extends it to be used w/ shared libraries, too. The patch probably needs some cleanup, but it works. ldd-stub should be in /usr/libexec. Is /usr/libexec/elf preferable? Do you have an idea how to generate an ldd-stub without a DT_NEEDED for libc.so (and still working with ldd, of course)? -Bj=F6rn --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ldd-patch.udif" --- ldd.c 2002/02/06 02:17:46 1.1 +++ ldd.c 2002/02/06 02:39:49 @@ -42,6 +42,8 @@ #include #include +#define LDD_STUB "/usr/libexec/ldd-stub" + extern void dump_file __P((const char *)); extern int error_count; @@ -116,6 +118,9 @@ int n; int status; int file_ok; + int shared_object; + + shared_object = 0; if ((fd = open(*argv, O_RDONLY, 0)) < 0) { warn("%s", *argv); @@ -152,6 +157,10 @@ warnx("%s: can't read program header", *argv); file_ok = 0; } else { + if (ehdr.e_type == ET_DYN) { + shared_object = 1; + dynamic = 1; + } else { /* need to fix white spaces */ for (i = 0; i < ehdr.e_phnum; i++) { if (read(fd, &phdr, ehdr.e_phentsize) != sizeof phdr) { @@ -163,6 +172,7 @@ if (phdr.p_type == PT_DYNAMIC) dynamic = 1; } + } } if (!dynamic) { warnx("%s: not a dynamic executable", *argv); @@ -204,7 +214,11 @@ } break; case 0: - rval |= execl(*argv, *argv, NULL) != 0; + if (shared_object) { + setenv("LD_PRELOAD", *argv, 1); + rval |= execl(LDD_STUB, LDD_STUB, NULL) != 0; + } else + rval |= execl(*argv, *argv, NULL) != 0; warn("%s", *argv); _exit(1); } --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ldd-stub.c" int main(int argc, char *argv[]) { } --EeQfGwPcQSOJBaQU-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message