Date: Thu, 13 Jan 2011 10:50:09 GMT From: Dominic Fandrey <kamikaze@bsdforen.de> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/127276: [patch] ldd(1) invokes linux yes Message-ID: <201101131050.p0DAo94I040478@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/127276; it has been noted by GNATS.
From: Dominic Fandrey <kamikaze@bsdforen.de>
To: bug-followup@FreeBSD.org, kamikaze@bsdforen.de
Cc:
Subject: Re: bin/127276: [patch] ldd(1) invokes linux yes
Date: Thu, 13 Jan 2011 11:44:06 +0100
I tested the patch, prior to the test:
> ldd /compat/linux/usr/bin/yes
y
y
y
y
y
y
...
After I applied the patch:
> ldd /compat/linux/usr/bin/yes
/compat/linux/usr/bin/yes:
libc.so.6 => /lib/libc.so.6 (0x28075000)
/lib/ld-linux.so.2 (0x2804f000)
Apparently it returns libraries from the /compat/linux perspective.
> ldd /compat/linux/lib/ld-linux.so.2
ldd: /compat/linux/lib/ld-linux.so.2: not a FreeBSD ELF shared object
The behaviour caused by the patch is comprehensible and a vast
improvement over the old behaviour in my opinion, so I'm all for
it.
At some point the manual page of ldd should be updated to describe
the new behaviour. If the patch is committed, I volunteer to make
the changes.
Because the patch was mangled by Gnats, I resubmit it here. I did
not make any changes apart from the header to trigger the usual
patch detection magic.
Regards
diff -u ldd.c.old ldd.c
--- ldd.c.old 2009-09-19 21:45:17.000000000 +0900
+++ ldd.c 2010-05-04 11:48:42.000000000 +0900
@@ -65,7 +65,7 @@
#endif
static int is_executable(const char *fname, int fd, int *is_shlib,
- int *type);
+ int *osabi, int *type);
static void usage(void);
#define TYPE_UNKNOWN 0
@@ -177,14 +177,14 @@
rval = 0;
for (; argc > 0; argc--, argv++) {
- int fd, status, is_shlib, rv, type;
+ int fd, status, is_shlib, rv, type, osabi;
if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
warn("%s", *argv);
rval |= 1;
continue;
}
- rv = is_executable(*argv, fd, &is_shlib, &type);
+ rv = is_executable(*argv, fd, &is_shlib, &osabi, &type);
close(fd);
if (rv == 0) {
rval |= 1;
@@ -197,6 +197,8 @@
break;
#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
case TYPE_ELF32:
+ if (osabi != ELFOSABI_FREEBSD)
+ break;
rval |= execldd32(*argv, fmt1, fmt2, aflag, vflag);
continue;
#endif
@@ -267,7 +269,7 @@
}
static int
-is_executable(const char *fname, int fd, int *is_shlib, int *type)
+is_executable(const char *fname, int fd, int *is_shlib, int *osabi, int *type)
{
union {
struct exec aout;
@@ -300,6 +302,8 @@
return (1);
}
+ *osabi = hdr.elf.e_ident[EI_OSABI];
+
#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
if ((size_t)n >= sizeof(hdr.elf32) && IS_ELF(hdr.elf32) &&
hdr.elf32.e_ident[EI_CLASS] == ELFCLASS32) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101131050.p0DAo94I040478>
