Subject: Re: want to reference ___progname under SunOS
To: None <port-sparc@sun-lamp.cs.berkeley.edu>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: port-sparc
Date: 09/11/1994 08:46:24
>> I've been using a customized crt0.o on SunOS for quite a while.
>> What I did was to copy Sun's crt0.o and bash the string table to
>> change the external _main symbol to Xmain, then assemble the
>> following file and use ld -x -r to merge it with the modified
>> crt0.o.  The result is then installed in /local/mouse/lib/crt0.o.
>> [....]

> Erm, not to get away from NetBSD/SPARC-related topics, but couldn't
> you do this (on SunOS) using LD_PRELOAD to pre-load your custom .o
> file instead?

Sure, that would get it loaded - but I can't see how to ensure it gets
called at the correct time.  If the preloaded file defines _main, I
would expect to get a multiply defined error, and even if that doesn't
happen and Sun's crt0 calls my _main instead (which I can't see
happening because that call doesn't go through the GOT, since it's a
call between two .o files both loaded at ld time), I can't see how to
call the real _main after I've done my work.  It would also mean
link-time errors from any program that uses argcnt or argvec, because
there's no way to tell ld that such-and-such .o file will be loaded in
via LD_PRELOAD at run time.

It also means that other people can't run binaries I've linked without
taking special action.  With my solution, the resulting a.out is
runnable by anyone, since all the changes are already loaded in.

It also hijacks LD_PRELOAD, rendering it unusable for any other
purpose.  This would not be critical, since I've never seriously used
LD_PRELOAD for anything else....

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu