Re: Darwin-dev Digest, Vol 1, Issue 4
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Message: 6 Date: Mon, 13 Sep 2004 14:33:49 -0400 From: "Mike Garey" <random50k@hotmail.com> Subject: need help resolving symbols using twolevel hints table To: darwin-dev@lists.apple.com Message-ID: <BAY18-F34ByrbwjN5Rp0003ac65@hotmail.com> 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. 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? We will find _printf in the SYMTAB as an undefined symbol (from nm): 9002abe0 (prebound undefined [lazy bound]) external _printf (from libSystem) 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 bobc@metrowerks.com 408.991.7490 _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... At 12:07 PM -0700 9/13/04, <darwin-dev-request@lists.apple.com> wrote: 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. Looking for a symbol requires looking in several places, first the SYMTAB from the referring program: 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. This email sent to site_archiver@lists.apple.com
participants (1)
-
Bob Campbell