From owner-freebsd-hackers@FreeBSD.ORG Sun Sep 2 04:42:24 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 829AA106564A for ; Sun, 2 Sep 2012 04:42:24 +0000 (UTC) (envelope-from artemb@gmail.com) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id 003738FC08 for ; Sun, 2 Sep 2012 04:42:23 +0000 (UTC) Received: by lbbgg13 with SMTP id gg13so2359388lbb.13 for ; Sat, 01 Sep 2012 21:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=toZDALeT5DpPJR5B4iG5eyfeQRE6Fiy+MQ+Ao7vZLGI=; b=MIJi5zm4jPoM43FSynqiu+SJvGJF/HPbXeg48VlNP4vEZv6/xQQwOsVbaxaZ8zkVEk WyLKtrRgOOjc1MB6vDKgnsdB1IwJM4oloMem3L3LgKKxQ4zk+s9bAlTQpk/9lFMOeivN rbIHVPl4CxBhfDjsbeEDaWaHkOdfiYPaQ7SGL8Gck57MMmIVZW+/vmfKM2uq1Hp4PlcD xjZPsvr0e2i7d7lNdi5B75+IYG27nlFpvH6TX/FgfXL4UthudX0SyFLdjwX3IGepKuFF c3QM3EUf7TalmBoOqJQOmWjerLRDqnJorWzmXUn5KlSlrJXHenaCarJjPYt26d6jzgt8 oiDw== MIME-Version: 1.0 Received: by 10.112.88.2 with SMTP id bc2mr2338036lbb.61.1346560942801; Sat, 01 Sep 2012 21:42:22 -0700 (PDT) Sender: artemb@gmail.com Received: by 10.112.43.40 with HTTP; Sat, 1 Sep 2012 21:42:22 -0700 (PDT) In-Reply-To: References: Date: Sat, 1 Sep 2012 21:42:22 -0700 X-Google-Sender-Auth: CkVuquB_eurfM0w7puvSLUpq_28 Message-ID: From: Artem Belevich To: asp imho Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org Subject: Re: start of text section in the ELF executable and in the Virtual Memory X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Sep 2012 04:42:24 -0000 On Sat, Sep 1, 2012 at 7:44 PM, asp imho 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 , 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