Subject: Re: refusal to run static binaries
To: None <rian@thelaststop.cjb.net>
From: Bill Studenmund <wrstuden@netbsd.org>
List: port-macppc
Date: 09/03/2004 10:18:18
--IS0zKkzwUGydFO0o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Aug 30, 2004 at 08:41:18PM -0600, rian@thelaststop.cjb.net wrote:
> > > it is compiled with "gcc -nostdlib write.S". When I compile the progr=
am,
> >=20
> > That's not static compiling. "-static" turns on static compiling.
>=20
> well, implicitly it is a static binary because it isn't linked with any
> dynamic libraries, not even libc.

I don't think that's correct. Dynamic is an attribute of how the binary's
put together. You created a dynamic program with an empty set of libraries
it was linked against. What did file say about the program?

> > > renaming _start as main and linking with the C library the program ru=
ns
> > > fine. Does the NetBSD loader refuse to run executables that are not
> > > dynamically linked with libc? thanks
> >=20
> > No. NetBSD certainly supports static linking.
> >=20
> > I'm not sure what problem you're encountering, but I'd expect that it's
> > that libc also includes the runtime setup code. Or you're building what
> > looks like a dynamic-link program but not including the bits the runtime
> > linker needs.
>=20
> actually, the problem was that recent NetBSD kernels require a
> .note.netbsd.ident section (well after linking it goes in the program
> header) with a binary signature to be loaded and read by the NetBSD
> loader. libc includes this section, but if you don't link with libc it
> won't be included for loading and NetBSD will refuse to run the
> "arbitrary" ELF binary.

Oh that. That reflects a deficiency in the ELF spec. ELF was defined as=20
part of SysVRsomething_or_other (SVR3?), and it included a syscall=20
numbering scheme, which matched the SysV syscall numbering. Since our=20
syscall numbering is different (write is in the same place, but others=20
differ), we require the note section above to recognize the file as a=20
NetBSD binary. Your unmodified program might have run if you had SVR4=20
compat turned on.

Take care,

Bill

--IS0zKkzwUGydFO0o
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQFBOKdaWz+3JHUci9cRApyYAJ9/hGgPUF/3/PHiuPtF735wyKjYPgCdFc2+
Qncq5cjgSIHKnt71b/C3xg0=
=ejJ9
-----END PGP SIGNATURE-----

--IS0zKkzwUGydFO0o--