Subject: poor error reporting when ld.so is missing
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-kern
Date: 04/16/2001 00:36:53
I just had to deal with two problem report on Linux compatibility. The
problem was that running any Linux dynamically linked program caused
this error:

./arg.dyn: 1: Syntax error: "(" unexpected

The cause was that /emul/linux was missing (the pkg system installs
stuff in /usr/pkg/emul/linux, and don't make any link). It have been
quite difficult to track down. I don't expect any average user to
understand that Linux emulation doesn't work because
/emul/linux/lib/ld.so is not there.

Of course the obvious fix is to make more documentation available. But I
think it would also be good to have a better error reporting here.

The problems lies in /sys/compat/linux/common/linux_exec_elf32.c
In this file, in the linux_probe() fucntion, we try a few signatures
functions. If we get up to this test:

   if (itp[0]) {
      if ((error = emul_find(p, NULL, epp->ep_esch->es_emul->e_path,
          itp, &bp, 0)))
         return error;

it means that we know the binary is a Linux executable. But if there is
an error here (because lib/ld.so was not found in /emul/linux),
linux_probe() will return an error, and the executable will not be
matched as a Linux binary, whereas we know it is a Linux binary. The
kernel will the try to run it as bourne shell script, hence the stange
error. This is bad. It would be better to report that we have a Linux
binary but there is no ld.so, or something like that.

We have exactly the same problem for native NetBSD dynamic binaries. Try
moving /usr/libexec/ld.elf_so, and run a dynamically linked program (gcc
for instance). The error you get does not tell you what is wrong.

There is nothing in errno.h such as "can't find ld.so". Should we use an
existing error code (and which one is revelant here), or should we add a
new one? I beleive adding an errno is not a good ifdea for portability
reason. Is there any other way of doing it?

-- 
Emmanuel Dreyfus
p99dreyf@criens.u-psud.fr