flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > MSCOFF and section directive

Author
Thread Post new topic Reply to topic
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
When mixing object code generated by fasm and cl compilers for:
'section ".data" data readable writeable' fasm generate section with characteristics: 0xC03000C0(in exe file -> result is 0xC00000C0)
but characteristics of the 'standart' data section are: 0xC0000040
When linking the object files linker display the warning:
... warning LNK4078: multiple '.data' sections found with different attributes (C03000C0), and in exe file has two '.data' sections.
Is it possible to solve the problem without using methods similar to this:
section ".adata" data readable writeable
...
fasm ...
cl ...
Link ... /MERGE:.adata=.data ...

_________________
regards
Post 18 Jul 2009, 13:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
The value 0xC03000C0 consists of the following flags (check out the PE/COFF format specification):
  • 0x80000000 IMAGE_SCN_MEM_WRITE - generated by keyword "writeable"
  • 0x40000000 IMAGE_SCN_MEM_READ - generated by keyword "readable"
  • 0x00000080 IMAGE_SCN_CNT_UNINITIALIZED_ DATA - generated by fasm automatically when the given section contains no initialized data
  • 0x00000040 IMAGE_SCN_CNT_INITIALIZED_DATA - generated by keyword "data" (you should notice the contradiction that is generated by the fact that you mark the section as containing initialized data, but put the uninitialized data inside)
  • 0x00300000 IMAGE_SCN_ALIGN_4BYTES - the default data alignment generated by fasm when no other alignment is specified (use "align" keyword in section declaration to specify a different alignment)

As you can see, all the flags that are generated can be controlled from the source.
Post 18 Jul 2009, 13:26
View user's profile Send private message Visit poster's website Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
Smile Perfect! So what should follow code after 'section ".data" ' to contain only the following flags:
IMAGE_SCN_MEM_WRITE + IMAGE_SCN_MEM_READ + IMAGE_SCN_CNT_INITIALIZED_DATA

I guess that solve me the problem of two '.data' sections in final executable program.

_________________
regards
Post 18 Jul 2009, 14:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Code:
section ".data" data readable writeable    
..would work if there wasn't a default alignment (IMAGE_SCN_ALIGN_4BYTES), and if initialized data is present.

Does the section name ".data$0" prevent the warning?

The linker merges sections automatically based on the "name$order". If there is no default alignment then sections merge as expected. Whereas the alignment can create a gap between parts of the same section. Ideally, only one section would specify section alignment while others are merged bytewise.

How to support this without breaking the ALIGN directive? Doesn't seem possible.
Post 19 Jul 2009, 00:19
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
bitRAKE wrote:
Ideally, only one section would specify section alignment while others are merged bytewise.

Ideally every fragment of data you create should be aligned appropriately for the given data size. Those "gaps" you're talking about are there for a reason.

Anyway, to get rid of the default alignment, just use "align 1" command in the section directive.
Post 19 Jul 2009, 09:52
View user's profile Send private message Visit poster's website Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
For more clarity on the issue I send a simple example.
p.s.
versions of the microsoft compilers:
Microsoft (R) Macro Assembler Version 7.10.4035
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.4035 for 80x86 - Window DDK package


Description: ftest.exe is mixing cl+fasm - file has two '.data' sections
mtest.exe is mixing cl+ml
compile.bat is compile script
result.txt is result from executing compile.bat

Download
Filename: example.zip
Filesize: 3.63 KB
Downloaded: 166 Time(s)


_________________
regards
Post 19 Jul 2009, 11:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
So either use a right kind of section for uninitialized data (.bss), or put some initialized data into the .data section to stop fasm from generating the uninitialized data flag.
Post 19 Jul 2009, 11:33
View user's profile Send private message Visit poster's website Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
Flat assembler has many advantages over Microsoft assembler. That's why is preferred by me in the case of mixing 'c' and 'asm' code.
In my practice I solve the 'problem' by defining the variables in 'c' file, merge the sections with diffrent names(is not very correct) and in other ways depending on the specifically, but
Quote:
So either use a right kind of section for uninitialized data (.bss)
is a elegant solution.
Thanks.
Post 19 Jul 2009, 13:35
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 YouTube, Twitter.

Website powered by rwasa.