Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Feb 1999 14:24:27 +1100 (EST)
From:      John Birrell <jb@cimlogic.com.au>
To:        grog@lemis.com (Greg Lehey)
Cc:        chuckr@mat.net, eivind@FreeBSD.ORG, hackers@FreeBSD.ORG
Subject:   Re: gdb sucks - and I need to get around it.  help?
Message-ID:  <199902170324.OAA02264@cimlogic.com.au>
In-Reply-To: <19990217132952.Z515@lemis.com> from Greg Lehey at "Feb 17, 1999  1:29:52 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Greg Lehey wrote:
> There's stuff before main in C programs as well.  The entry point of
> all C and C++ programs is start, which is in crt0.o or crt1.o.  In
> a.out files, it used to be directly after the header at 0x1020.  I'm
> not sure where the start address is in an ELF file.  The clue should
> be here somewhere, but I can't see it:
> 
> $ objdump   --section-headers /bin/sh

Look in the elf header, not the sections. The entry address is in
e_entry (grep for that in the elf header files). The elf header starts
at the beginning of the file. You have to read the elf header to know
how many sections you have.

Although the original question wasn't related to the kernel, it's worth
noting that the PT_INTERP section (that occurs due to the need to link
the kernel shareable to allow klds to work) requires e_entry to be offset
by the size of the interpreter section. The GNU tools are somewhat fooled
by what we are doing with our kernel. I found this out trying to decompress
and elf kernel from flash into RAM in an embedded system. If you believe
the e_entry value, BOOM! Offset it by the size of the PT_INTERP section
and jump to the resulting address and the standard FreeBSD kernel runs
embedded (no disk, no NFS).

-- 
John Birrell - jb@cimlogic.com.au; jb@freebsd.org http://www.cimlogic.com.au/
CIMlogic Pty Ltd, GPO Box 117A, Melbourne Vic 3001, Australia +61 418 353 137


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199902170324.OAA02264>