Re: need help resolving symbols using twolevel hints table
Re: need help resolving symbols using twolevel hints table
- Subject: Re: need help resolving symbols using twolevel hints table
- From: "Mike Garey" <email@hidden>
- Date: Tue, 14 Sep 2004 00:29:19 -0400
Thanks for the reply Bob, however, I'm still confused as to how you arrived
at symbol number 4347 from printf having an itoc of 1854. I was thinking
that perhaps the tocoff of libSystem + 1854 should equal 4347, but that's
not the case. I've been reading the dyld sources, and it looks like they
simply use the itoc as an initial starting position from which to begin a
binary search. Although I'm unsure of how they perform a binary search on
what seems like an unsorted list of symbols (because the symbol tables for
mach-o images are not sorted), and if dyld was to sort its internal symbol
list, I can't see how having the itoc would help, as it seems that the itoc
is an index into the unsorted symbol table as it appears in the original
mach-o image.
So anyways, is this itoc value, 1854, simply a suggesting starting point,
and the value 4347 was found by performing a linear search from this index
value?
Also, another strange thing I noticed.. When using otool -Hv on a few
different binaries, some show the itoc for printf to be 1854, while some
others show the itoc to be 1855.. Any idea why this would happen? I guess
maybe it depends on when the binary was built?
Thanks for your help,
Mike
From: Bob Campbell <email@hidden>
To: email@hidden
Subject: Re: Darwin-dev Digest, Vol 1, Issue 4
Date: Mon, 13 Sep 2004 14:48:07 -0700
At 12:07 PM -0700 9/13/04, <email@hidden> wrote:
Message: 6
Date: Mon, 13 Sep 2004 14:33:49 -0400
From: "Mike Garey" <email@hidden>
Subject: need help resolving symbols using twolevel hints table
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; format=flowed
I'm having difficulty understanding how to use the twolevel hints table to
resolve undefined symbols.Ý I'm not sure what exactly the itoc member of
the
twolevel hints structure represents.
itoc is an index to the symbol in the TOC (which is a component of the
DYSYMTAB loader command), of the dylib where the symbol is to be found.
For example, if I have an executable image, which has an undefined symbol
such as _printf, after I determine which library image it's located in
(from
the n_desc value of the nlist struct), do I then obtain the tocoff value
from the dysymtab_command of this library, and add the itoc to this value,
then read the memory found at this location into a dylib_table_of_contents
struct, and then obtain the symbol_index member, which will indicate the
index of the _printf symbol within the symbol table of the shared
library?Ý
Or is this completely wrong?
Looking for a symbol requires looking in several places, first the SYMTAB
from the referring program:
We will find _printf in the SYMTAB as an undefined symbol (from nm):
9002abe0 (prebound undefined [lazy bound]) external _printf (from
libSystem)
Looking at the fields we see n_type == N_PBUD, n_desc =
REFERENCE_FLAG_UNDEFINED_LAZY, and also the id of the loading framework (in
this case libSystem).
Then we look at the TOC table from the DYSYMTAB, and find that __printf has
isub=0 and itoc=1854,
If isub is 0 then we just look at the framework/library from the SYMTAB (in
this case libSystem) and at entry 4347 of it's SYMTAB should be printf.
If isub is not zero it is a bit more complex, as it indicates a framework
so you have to walk the dylib load commands (from the framework/library and
find the nth one (where n == isub) and then itoc is the index into that
nested frameworks TOC.
This is at least partly explained in the header,
/usr/include/mach-o/loader.h but I also have done a bit of disassembly over
the past 7 years to track what "ld" was doing.
If anyone has any advice or suggestions, please let me know.Ý Thanks!
Mike
P.S. Sorry if this question has been answered in the lists before, but I
can't seem to find the search option on lists.apple.com.
--
Message Classification
[x] General Business Information
___________________________________________________________________
Bob Campbell email@hidden 408.991.7490
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden