Subject: Re: COMPAT_IBCS2, SCO OSR5 executables SEGV on NetBSD 2.0
To: None <flack@cs.purdue.edu>
From: Ben Harris <bjh21@netbsd.org>
List: tech-kern
Date: 12/29/2004 22:45:39
In article <200412292151.iBTLpGUq011152@ector.cs.purdue.edu> you write:
>I found this comment in /usr/src/sys/compat/ibcs2/ibcs2_exec_elf32.c:
>
> * The SCO compiler adds the string "SCO" to the .notes section of all
> * binaries I've seen so far.
>
>It seems to be there:
>
>$ readelf -x 14 wc
>
>Hex dump of section '.note':
> 0x00000000 004f4353 00000001 0000000c 00000004 ............SCO.
> 0x00000010 00010000 00000003 00010001 ............
Hmm. I note that ibcs2_exec_elf32.c contains:
#define SCO_SIGNATURE "\004\0\0\0\014\0\0\0\001\0\0\0SCO\0"
which I don't think matches yours. I think the signature-matching code
needs to be made a little more relaxed, so that it only matches the name and
perhaps the type, but ignores the desc (including its length). It should
also really be looking for PT_NOTE in the program headers rather than
SHT_NOTE in the section headers, but this is less important.
Here's an utterly untested and rather grotty patch that might help:
--- ibcs2_exec_elf32.c.~1.8.~ Wed Nov 5 19:43:34 2003
+++ ibcs2_exec_elf32.c Wed Dec 29 22:40:38 2004
@@ -97,16 +97,20 @@
for (i = 0; i < eh->e_shnum; i++) {
Elf32_Shdr *s = &sh[i];
+ Elf32_Nhdr *np;
+
if (s->sh_type != SHT_NOTE ||
s->sh_flags != 0 ||
- s->sh_size < sizeof(signature) - 1)
+ s->sh_size < sizeof(Elf32_Nhdr) + 4)
continue;
if ((error = exec_read_from(p, epp->ep_vp, s->sh_offset,
buf,
- sizeof(signature) - 1)) != 0)
+ sizeof(Elf32_Nhdr) + 4)) != 0)
goto out;
- if (memcmp(buf, signature, sizeof(signature) - 1) == 0)
+ np = buf;
+ if (np->n_namesz == 4 && np->n_type == 1 &&
+ memcmp((caddr_t)(np + 1), "SCO", 4) == 0)
goto out;
else
break; /* only one .note section so quit */
>Maybe there's a bug in the ibcs2 elf recognition? Hmm - is there any way
>to exec a file and force a specified emulation to be used, just to see if
>it works right that way?
There's an ELF note documented to do this at
<http://www.netbsd.org/Documentation/kernel/elf-notes.html>, but I can't
find any code to support this in the kernel.
--
Ben Harris <bjh21@NetBSD.org>
Portmaster, NetBSD/acorn26 <URL:http://www.NetBSD.org/Ports/acorn26/>