Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: Hunk symbols  (Read 183 times)

0 Members and 1 Guest are viewing this topic.

magorium

  • Full Member
  • ***
  • Posts: 198
  • Programming is an art form that fights back
    • View Profile
Hunk symbols
« on: March 22, 2017, 01:50:18 AM »

Hi,

How can i map symbols located in the symbol hunk to my (runtime) program ?

Or perhaps the better question would be (?): how do i figure out at runtime at what memory address my executable (hunk) was loaded so that i can map the relative symbol offsets to absolute offsets.

It might be i'm doing things wrong here but (available online) information seems very scarce or non existent.

Initially i was looking at pr_SegList but that seems to be a dead end or maybe i'm missing something.

Perhaps someone is able to recommend a link and/or good book title on the subject on hunks and how they relate to actual practice ?

The only usable links i was able to find/use so far is inside the OS4 wiki and this page.

The latter link does mention a function named get_hunk_address() but i fail to locate an actual implementation and also fail to come up with something of my own that works.

Regards,
Ron.
Logged

SamuraiCrow

  • Administrator
  • Sr. Member
  • *****
  • Gender: Male
  • Posts: 374
  • Coolness is compiled
    • View Profile
Re: Hunk symbols
« Reply #1 on: March 22, 2017, 12:19:46 PM »

Hunk is a graphical editor by ThoR for Hunk executables.  http://aminet.net/package/dev/misc/Exemine is another hunk dumper.  There is another that comes with AmigaE called ShowHunk, I think.

Overlay is some documentation by ThoR about Overlay hunks that are seldom used but may contain other info as well.

Sorry if this is irrelevant drivel, but what you seem to be looking for is a RELOC hunk to insert absolute addresses into your code.
« Last Edit: March 22, 2017, 01:42:11 PM by SamuraiCrow »
Logged

magorium

  • Full Member
  • ***
  • Posts: 198
  • Programming is an art form that fights back
    • View Profile
Re: Hunk symbols
« Reply #2 on: March 23, 2017, 02:25:30 AM »

Hi SamuraiCrow,

Thank you very much for the links, especially the one on the overlays.

The overlay hunk was also something that raised a load of questions. Most (if not all) of those questions are now answered thanks to that document.

So, also thank you to Thor !

I would settle for grasping the more simple things in life though  :D

fwiw: I'm not creating a debugger or disassembler or the like. I'm simply trying to get a more informative backtrace from the compiler...

At least some victory as i had a look at the sources of scout which answered some of the hows for me.

I still do not fully grasp (all) the why's though and i am still unable to locate any decent documentation other then a few hints here and there (most of which i was able to find in my stock old amigados reference manual).

At least current progress allows me to get rid of the ugly parts in my code that obtains the address of a function that is known to be part of the symbol table, then look for its name in there to end up calculating the base address using the offset of that symbol.

So far, the results (note that the hunk loading is done before main program entry is invoked. The dumps you see are from the executable itself):
Code: [Select]
>hunkdumper
Processing HUNK_HEADER
Processing HUNK_CODE
Size = 570228
Processing HUNK_RELOC32
Processing HUNK_SYMBOL
reading symbol table (1)
finished symbol table reading
Processing HUNK_END
Processing HUNK_DATA
Size = 161272
Processing HUNK_RELOC32
Processing HUNK_SYMBOL
reading symbol table (2)
finished symbol table reading
Processing HUNK_END
Processing HUNK_BSS
Size = 10128
Processing HUNK_SYMBOL
reading symbol table (3)
finished symbol table reading
Processing HUNK_END
EenyMeenyMinyMoe @ $104342A0
match #0 at index #1664 = AMIGA.HUNK_$$_EENYMEENYMINYMOE @offset: $00054508
Base calculation succeeded
Pre-Initialization finished

HunkDumper 0.07 by MAG (2017)
function AmigaPlay1() @ : $103E034C
...GetSymbolName($103E034C)
...base Address    = $103DFD98
...OffsetToLookFor = $000005B4
symbol = P$HUNKDUMPER_$$_AMIGAPLAY1

TaskName = Shell Process

 #    size     bottom        top
---------------------------------
 0  570236  $103DFD98  $1046B10C
 1  161280  $1046B118  $10492710
 2   10136  $103CBCF8  $103CE488

The constructed symbtab which then can be saved to disk. A small excerpt:
Code: [Select]
[1]    0  $000649F4  CLASSES$_$TSTRINGS_$__$$_GETVALUE$ANSISTRING$$ANSISTRING
[1]    1  $0005C6A8  CLASSES$_$TCUSTOMMEMORYSTREAM_$__$$_READ$formal$LONGINT$$LONGINT
[1]    2  $00054C74  AMIGA.HUNK$_$THUNKSYMTABLE_$__$$_LOADFROMFILE$ANSISTRING
[1]    3  $00011950  SYSTEM_$$_ROUND$INT64$$INT64
[1]    4  $00024420  fpc_finalize_array
[1]    5  $0001CC58  SYSTEM_$$_UPCASE$WIDECHAR$$WIDECHAR
[1]    6  $0001F834  fpc_intf_incr_ref
[1]    7  $00087174  STRUTILS_$$_TRIMSET$ANSISTRING$TSYSCHARSET$$ANSISTRING
[1]    8  $0007A658  CLASSES$_$TBINARYOBJECTWRITER_$__$$_WRITEUINT64$QWORD
[1]    9  $0007D8CC  CLASSES$_$TABSTRACTOBJECTREADER_$__$$_READINT16$$SMALLINT
[1]   10  $00053DB0  SYSUTILS$_$TENCODING_$__$$_GETBYTES$PUNICODECHAR$LONGINT$PBYTE$LONGINT$$LONGINT
snip
[2] 3098  $0001BB84  _$RTLCONSTS$_Ld306
[2] 3099  $00010EB4  _$SYSCONST$_Ld255
[2] 3100  $00010964  _$SYSCONST$_Ld214
[2] 3101  $00022988  RESSTR_$RTLCONSTS_$$_SACRESDESCRIPTION
[2] 3102  $00018C1C  _$RTLCONSTS$_Ld22
[2] 3103  $000077C8  _$SYSUTILS$_Ld242
[2] 3104  $000131D0  VMT_$CLASSES_$$_TSTRINGLIST
[2] 3105  $00022298  RESSTR_$RTLCONSTS_$$_SRANGEERROR
[2] 3106  $00021618  RESSTR_$RTLCONSTS_$$_SCANNOTCREATEDIR
[2] 3107  $00015FD0  RTTI_$CLASSES_$$_DEF1451
snip
[3] 7398  $0000233C  U_$DOS_$$_DOSERROR
[3] 7399  $00001114  U_$SYSTEM_$$_SOFTFLOAT_ROUNDING_MODE
[3] 7400  $00000034  U_$SYSTEM_$$_ERROUTPUT
[3] 7401  $0000269C  U_$CLASSES_$$_REMOVEDATAMODULE
[3] 7402  $0000000C  stackSwap
[3] 7403  $000011B0  U_$SYSTEM_$$_AOS_CONHANDLE
[3] 7404  $00000008  stackPtr
[3] 7405  $000011BC  U_$SYSTEM_$$_ENVP
[3] 7406  $000026BC  U_$CLASSES_$$_GLOBALNAMESPACE
[3] 7407  $00001190  _DOSBase

So, i'm fairly confident with regards to the hunk parser (even though i am aware i still need to add proper support for libraries... and overlays of course  ;) Although the latter might be a bit redundant for currently used compiler/linker).

Regards,
Ron.
Logged

magorium

  • Full Member
  • ***
  • Posts: 198
  • Programming is an art form that fights back
    • View Profile
Re: Hunk symbols
« Reply #3 on: March 23, 2017, 07:04:57 PM »

Ok, i've found my initial culprit.

To summarize what i've done wrong, which led me to post my initial question, is actually quite simple.

Initially i treated pr_SegList and cli_Module as pointing to a "list of segments"   :-[

I over read the part from pr_SegList where it reads: "Array of seg lists used by this process" and interpreted it as "SegList of..." which of course turned up some undesired results at first  ;D

For now that leaves me with one 'why' and/or 'explanation' unanswered which is why the fourth entry in the array of seglist items ? Is that documented anywhere ? Is there any documentation for what each entry in that array points to (or is suppose to point to) ?

I am however (from results found so far) assuming that the "list of segments" itself has a 1 on 1 relation with the hunks as organized in the executable ?
(and with that i meant those hunks from the executable that are actually loaded into memory).

Regards,
Ron.
Logged