Linux MIPS Architecture development
 help / color / mirror / Atom feed
* Linux/MIPS and ELF dynamic linker/loader questions...
@ 2002-03-27 21:03 Steven J. Hill
  2002-03-27 21:09 ` Andreas Jaeger
  0 siblings, 1 reply; 2+ messages in thread
From: Steven J. Hill @ 2002-03-27 21:03 UTC (permalink / raw)
  To: binutils, linux-mips, uclibc

Greetings.

I am working on a MIPS dynamic linker/loader for uClibc and
would appreciate some clarification on the finer points of
ELF and the Linux kernel interface. Forgive the cross post.

The first problem I have discovered is that the value of
argc passed back to the userspace process from the Linux
kernel is always zero. The argv, environment and auxillary
vectors come through just fine. I have to loop through the
stack manually to count the number of argument vectors in
order to get argc:

#if defined(__mips__)
    argc = 0;
    aux_dat = sp + 1;
    while (*aux_dat++)
        argc++;
#endif

This code snippet is the first code to execute in the dynamic
linker, so no trashing of argc should have had a chance to
happen. Any insight?

The second question has to do with printing string constants
to stderr like so:

     static inline _syscall3(unsigned long, _dl_write, int, fd,
            const void *, buf, unsigned long, count);
     #define SEND_STDERR(X) _dl_write(2, X, _dl_strlen(X));

     SEND_STDERR("ELF header =");

The problem as I understand it is that string constants for
MIPS are accessed using the GOT (since the dynamic linker is
all PIC code). Since I haven't bootstrapped and relocated the
dynamic linker yet, the above SEND_STDERR call causes a SEGFAULT
as the address is invalid. Also, it appears that the constants
are stored in the .rodata section. Is there a quick hack to get
a hold of the string constants? Flames, help, etc. appreciated.

-Steve

-- 
 Steven J. Hill - Embedded SW Engineer

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Linux/MIPS and ELF dynamic linker/loader questions...
  2002-03-27 21:03 Linux/MIPS and ELF dynamic linker/loader questions Steven J. Hill
@ 2002-03-27 21:09 ` Andreas Jaeger
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Jaeger @ 2002-03-27 21:09 UTC (permalink / raw)
  To: sjhill; +Cc: binutils, linux-mips, uclibc

"Steven J. Hill" <sjhill@cotw.com> writes:

> Greetings.
>
> I am working on a MIPS dynamic linker/loader for uClibc and
> would appreciate some clarification on the finer points of
> ELF and the Linux kernel interface. Forgive the cross post.
>
> The first problem I have discovered is that the value of
> argc passed back to the userspace process from the Linux
> kernel is always zero. The argv, environment and auxillary
> vectors come through just fine. I have to loop through the
> stack manually to count the number of argument vectors in
> order to get argc:

In glibc I had no problems finding argc, check
sysdeps/mips/elf/start.S:

/* This is the canonical entry point, usually the first thing in the text
   segment.  The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
   point runs, most registers' values are unspecified, except for:

   v0 ($2)	Contains a function pointer to be registered with `atexit'.
		This is how the dynamic linker arranges to have DT_FINI
		functions called for shared libraries that have been loaded
		before this code runs.

   sp ($29)	The stack contains the arguments and environment:
		0(%esp)			argc
		4(%esp)			argv[0]
		...
		(4*argc)(%esp)		NULL
		(4*(argc+1))(%esp)	envp[0]
		...
					NULL
   ra ($31)	The return address register is set to zero so that programs
		that search backword through stack frames recognize the last
		stack frame.
*/


Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-03-27 21:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-27 21:03 Linux/MIPS and ELF dynamic linker/loader questions Steven J. Hill
2002-03-27 21:09 ` Andreas Jaeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox