Date: Wed, 6 Feb 2002 04:03:57 +0100 From: Bjoern Fischer <bfischer@Techfak.Uni-Bielefeld.DE> To: John Polstra <jdp@polstra.com> Cc: hackers@FreeBSD.ORG Subject: [patch] using ldd on shared libraries Message-ID: <20020206030357.GB2162@frolic.no-support.loc> In-Reply-To: <20020202125107.GA481@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>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <stdlib.h> #include <unistd.h> +#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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020206030357.GB2162>