9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: 9fans@9fans.net
Subject: Re: [9fans] _tos puzzle
Date: Thu,  8 May 2008 16:33:39 -0400	[thread overview]
Message-ID: <20080508203726.3AD111E8C5C@holo.morphisms.net> (raw)
In-Reply-To: <70DCC09F-5B5A-4801-AA60-728D86E3CCEC@kix.in>

> I set EAX before starting the executable, but still no luck :(
> On Plan 9, for /bin/mk:
>
> acid: symbols("_tos")
> _tos		D	0x00016084
> acid: mem(0x00016084, "X")
> 0xdfffefc8
>
> I'm probing address 0x16084 on linux after every instruction (using
> ptrace's singlestep), and it consistently returns 0. EIP at the
> beginning of the program is 0x9fe4, and sure enough:
>
> acid: asm(0x9fe4)
> _main		SUBL	$0x48, SP
> _main+0x3	MOVL	AX, _tos(SB)
> ...
>
> So (MOVL, _tos(SB)) is definitely executed, but for some reason, the
> value of AX is not stored in 0x16084.

You should print AX after every instruction too, to see if
you've actually set it up the way you think you did.

> That brings me to the question
> of how 8a decides what address to put values like that in? Is the
> address the same everytime, i.e. hardcoded into the binary? (certainly
> seems to be)

_tos is no different than any other global variable.
8a doesn't use any address at all - it leaves a slot for 8l to fill in.
The eventual address of _tos depends on what other data
is in the binary.  I don't know why you say the address is
the same every time:

cpu% nm /bin/cat |grep _tos
    600c D _tos
cpu% nm /bin/ls |grep _tos
    d060 D _tos
cpu% nm /bin/echo |grep _tos
    9008 D _tos
cpu%

> I strip the symbol table from plan 9 executables and store only data,
> text and initialize bss in memory - maybe that has something to do
> with it. Does the symbol table need to be in memory too for
> instructions like (MOVL AX, _tos(SB)) to work?

No, the symbol table is only for debuggers and the like.
Plan 9 doesn't load it into memory either.

The good news is that you've identified the program
behaving incorrectly after executing only *two* instructions.
That should narrow things down considerably.

Russ



  reply	other threads:[~2008-05-08 20:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08 16:18 Anant Narayanan
2008-05-08 16:41 ` Russ Cox
2008-05-08 17:13   ` Anant Narayanan
2008-05-08 17:24     ` Russ Cox
2008-05-08 17:40       ` Steven Vormwald
2008-05-08 19:19       ` Anant Narayanan
2008-05-08 20:33         ` Russ Cox [this message]
2008-05-09  5:30           ` Anant Narayanan
2008-05-09 13:08             ` Russ Cox
2008-05-08 17:50     ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080508203726.3AD111E8C5C@holo.morphisms.net \
    --to=rsc@swtch.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).