Subject: Re: libsa/loadfile.c
To: None <nigel@ind.tansu.com.au>
From: Jason R Thorpe <thorpej@zembu.com>
List: tech-kern
Date: 07/13/2001 10:55:42
On Fri, Jul 13, 2001 at 03:37:51PM +1000, nigel@ind.tansu.com.au wrote:

 > 	Before I list the problems I had, what code calls loadfile?
 > It it used very much? (in particular with loading a.out binaries)
 > I only ask because I find it hard to believe that no-one else has
 > had the same problem that I had with it.

It is used by the i386, alpha, sparc, hp300, pmax boot programs,
at least.  The a.out, ECOFF, and ELF support is all known to work.

 > 	These were my problems with loadfile.c, revision 1.10:
 > 
 > 1) aout_exec() seems to load files non-zero entry point at the wrong
 >    address. A kernel with a_entry of 0x2e00 loads at address 0x2e00,
 >    with its entry point at 0x5c00 !

If this were true, the i386 port wouldn't work.  But I'd need to look
at the code again and get my head wrapped around it to figure out how
to make your booter work.

 >    Looking at the code, aout_exec() inits minp and maxp to a_entry.
 >    coff_exec() and elf_exec() do the correct thing, initialising them
 >    to ~0 and 0 respectively.
 > 
 > 2) The symbol space marker returned by elf_exec(), marks[MARK_SYM],
 >    is set to elfp, which is only set if the LOAD_HDR flag is set.
 > 
 >    Shouldn't MARK_SYM should point to the start of the symbol space?
 >    It does in aout_exec().

I wrote the ELF symbol handling stuff in elf_exec() and in DDB.  There is
a very specific reason that elf_exec() sets MARK_SYM to the ELF header:

	Chasing the ELF headers from the beginning is the only way
	to get to the string table, and to handle the multiple symbol
	and string talbes that ELF images may have.

If you need to get at the symbol table, you chase it down.  It's very
simple.  Take a look at sys/ddb/db_elf.c.  Take note of the comment
that describes the format that the kernel is expecting:

        /*
         * The format of the symbols loaded by the boot program is:
         *
         *      Elf exec header
         *      first section header
         *      . . .
         *      . . .
         *      last section header
         *      first symbol or string table section
         *      . . .
         *      . . .
         *      last symbol or string table section
         */

 > 3) Similarly, elf_exec() does not count symbols loaded:
 >    marks[MARK_NSYM] = 1;	/* XXX: Kernel needs >= 0 */

That's because the count is sort of meaningless -- you get all the
information from the ELF headers.

 > 	Now, the last two are obviously not _essential_ for users
 > who are just executing a binary, but I need some way to locate the
 > symbol and string tables (so the Booter can modify kernel variables).
 > I am not proposing a full suite of elf manip. code (like Solaris),
 > just changing these two broken return values.

Use the same techniques that sys/ddb/db_elf.c uses.  The current ELF
load format is sufficiently general for you to do what you want.

-- 
        -- Jason R. Thorpe <thorpej@zembu.com>