flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > current_section format?

Author
Thread Post new topic Reply to topic
rhyde



Joined: 03 May 2007
Posts: 21
rhyde
I'm trying to map the fields pointed at by current_section to the fields of the COFF section header record. Is there documentation on this mapping? I see lots of numeric offsets from this base address in the source code, and it's pretty obvious what some of those offsets refer to (e.g., the Characteristics field), but having an actual mapping from offsets like 24h and 18h to actual COFF section field names would be really great.
Thanks,
Randy Hyde
Post 03 May 2007, 21:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
section structure seems to have only 20h bytes, so there is no offset 24h.
Code:
       mov     ebx,[free_additional_memory]
        lea     eax,[ebx+20h]
       cmp     eax,[structures_buffer]
     jae     out_of_memory
       mov     [free_additional_memory],eax
        mov     [current_section],ebx
    


[edit]some bullshit i wrote deleted, i have mistaken 24 with 24h


Last edited by vid on 03 May 2007, 23:08; edited 1 time in total
Post 03 May 2007, 22:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyde



Joined: 03 May 2007
Posts: 21
rhyde
vid wrote:
section structure seems to have only 20h bytes, so there is no offset 24h.
Code:
       mov     ebx,[free_additional_memory]
        lea     eax,[ebx+20h]
       cmp     eax,[structures_buffer]
     jae     out_of_memory
       mov     [free_additional_memory],eax
        mov     [current_section],ebx
    


But offset 14h of section structure seems to be mapped to offset 24h of COFF section header (file pointer to relocations), maybe you have mistaken it with this?


Oh, clearly the structure pointed at by current_section does not match the COFF section header, I'm just wondering which fields in whatever current_section points at correspond to the fields in the COFF header structure.
Cheers,
Randy Hyde
Post 03 May 2007, 22:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
just because i am bored, i tried to make it out of source:
Code:
;00 = low order byte is 0 to denote this is section (not relocation)
;04 = pointer to name of section (in FASM string token format)
;08 = address in generated output
;0C = size of section
;10 = alignment
;14 = bits 0:7 = format flags
;     bits 8:19 = ??? may be also flags, depends on "format_flags" bit 0
;     bits 20:31 = alignment (0 to 13)
;rest seems unused
    
Post 03 May 2007, 23:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyde



Joined: 03 May 2007
Posts: 21
rhyde
vid wrote:
just because i am bored, i tried to make it out of source:
Code:
;00 = low order byte is 0 to denote this is section (not relocation)
;04 = pointer to name of section (in FASM string token format)
;08 = address in generated output
;0C = size of section
;10 = alignment
;14 = bits 0:7 = format flags
;     bits 8:19 = ??? may be also flags, depends on "format_flags" bit 0
;     bits 20:31 = alignment (0 to 13)
;rest seems unused
    


Hmmm...
My reading of the source code led me to believe the following:

08 = COFF optional SizeOfInitializedData field
0C = COFF optional header SizeOfUninitializedData field
14 = COFF section header Characteristics field

I'm looking at the close_coff code section, in particular.

Of course, I've also noticed that current_section points at what appears to be different data types depending on the output format.
Cheers,
Randy Hyde
Post 04 May 2007, 16:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Hmmm...
My reading of the source code led me to believe the following:
08 = COFF optional SizeOfInitializedData field
0C = COFF optional header SizeOfUninitializedData field
14 = COFF section header Characteristics field

yeah, that is most possibly right too, except 08:
Code:
coff_section:
  ;...
  mov [ebx+8], edi  ;where edi is current code pointer
    
and also following wouldn't give sense if 08 was size of initialized data (instead of start of segment)
Code:
close_coff_section:
        mov     ebx,[current_section]
       mov     eax,edi
     mov     edx,[ebx+8]
 sub     eax,edx
     mov     [ebx+0Ch],eax
    

also check code around "find_section", where actual COFF headers are filled.

Quote:
Of course, I've also noticed that current_section points at what appears to be different data types depending on the output format.

yeah, that is true too. It's just using of same variable for 2 different purposes, when they cannot collide.
Post 04 May 2007, 21:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rhyde



Joined: 03 May 2007
Posts: 21
rhyde
vid wrote:

and also following wouldn't give sense if 08 was size of initialized data (instead of start of segment)


Yeah, that makes more sense.


Quote:

also check code around "find_section", where actual COFF headers are filled.

Yeah, that code sequence helps a lot.
Thanks,
Randy Hyde
Post 04 May 2007, 23:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.