Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Sep 2012 21:42:22 -0700
From:      Artem Belevich <art@freebsd.org>
To:        asp imho <asp654@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: start of text section in the ELF executable and in the Virtual Memory
Message-ID:  <CAFqOu6j=cyVjCoLzm2FBBuq0Hx0SMtMFVAYmfsRDDqH3zBoCcw@mail.gmail.com>
In-Reply-To: <CALGwOvK74qKQBCf4eoMcv%2Bj4obOg0u5X1ML3b88PnLW_NjJ8JQ@mail.gmail.com>
References:  <CALGwOvK74qKQBCf4eoMcv%2Bj4obOg0u5X1ML3b88PnLW_NjJ8JQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Sep 1, 2012 at 7:44 PM, asp imho <asp654@gmail.com> wrote:
> Hi all,
>
> I've a generic question about how the program looks before and after it is
> loaded into the memory.
>
> I see that the TEXT_START_ADDR = 0x08048000 (found this in
> ~src/contrib/binutils/ld/emulparams/elf_i386.sh)
>
> when I do a procstat -v <PID>, I see some thing like this
>
> PID            START                END                       PRT .........
> PATH
> 2126          0x8048000          0x0804a000           r-x    .........
> /bin/cat
>
>
> I see that the VM address is same as that of the TEXT_START_ADDR. Does this
> mean that the actual begining of the program statement, `cat` in this case,
> has a VM address of 0x8048000.
>
> Looking at the Permission Flags (PRT = r-x) I assumed this is the text
> section.

this section be loaded from the file into memory at 0x8048000. .text
section is probably part of that, but it's not necessarily the only
thing.
readelf command is quite handy when you need to see details of an ELF file.

>
> But when I do a objdump of /bin/cat (cmd: `objdump -D /bin/cat`), I see
> that there is a section named `.interp` starting at 0x8048134 and not
> 0x8048000. And the .text section starts from 0x8048b40 and there is no
> instruction at address 0x8048000. Can someone please tell me why is this
> so?  and what exactly will be present in the memory from 0x8048000 and
> 0x8048134.

.interp section tells kernel what it needs to run in order to launch
the executable. In case of dynamic executable this section contains
path to dynamic linker. In this case kernel loads and runs the
*runtime linker*. It's the linke which then looks at the ELF file,
parses dynamic headers in the ELF file, finds and loads required
shared objects and then jumps to the entry point specified in the ELF
header of the original executable.

--Artem



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