flat assembler
Message board for the users of flat assembler.

Index > Windows > what are the right flags for polink and ms link?

Author
Thread Post new topic Reply to topic
lunada



Joined: 17 Apr 2016
Posts: 2
Location: Mexico
lunada 06 Oct 2025, 05:56
yes what are the right flags for a mscoff un-initialized section?
I'm using :
Code:
     section '.bss' readable writeable
_data :  
   db  307200 dup(?)

    

but polink and ms link create a 300 kb executable
Post 06 Oct 2025, 05:56
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4288
Location: vpcmpistri
bitRAKE 06 Oct 2025, 07:21
The linker builds an executable - it does not set the IMAGE_SCN_CNT_UNINITIALIZED_DATA flag - which is needed.

MASM supports a verbose syntax:
Code:
_BSS SEGMENT READ WRITE 'BSS'
    ; Reserve space for an uninitialized variable
    some_var DWORD ?

    ; Reserve a buffer
    some_buffer BYTE 256 DUP(?)
_BSS ENDS    
Or, the more terse, ".DATA?"

fasm[g|2]uses "udata":
Code:
section '.bss$t' udata readable writeable align 64    
... but it also support automatically flagging a section with no literal data, or trailing uninitialized data.

Searching the source code for the IMAGE_SCN_CNT_UNINITIALIZED_DATA flag will discover all support.

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 06 Oct 2025, 07:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8454
Location: Kraków, Poland
Tomasz Grysztar 06 Oct 2025, 07:37
bitRAKE wrote:
fasm[g|2]uses "udata":
Code:
section '.bss$t' udata readable writeable align 64    
... but it also support automatically flagging a section with no literal data, or trailing uninitialized data.
You are referring the PE format implementation, which uses such keyword. "format MS COFF" and "format MS64 COFF" do not.

With object output the section that contains only uninitialized data is marked with IMAGE_SCN_CNT_UNINITIALIZED_DATA automatically, because of the format limitations (you do not have a separate raw and virtual size like in PE, if section data is in the file, it must of the length of the whole section, otherwise it must not be present at all).

In case of PE you don't really need this flag to have section size in memory be larger than in file, that's why its optional and set manually with PE formatter. In fact, this flag matters more for linking than the runtime.

When a section has no initialized data in the object file but ends up contributing to the size of the linked executable, it is usually because it has been combined with another section that is initialized and came later during the linking process.
Post 06 Oct 2025, 07:37
View user's profile Send private message Visit poster's website Reply with quote
lunada



Joined: 17 Apr 2016
Posts: 2
Location: Mexico
lunada 06 Oct 2025, 15:45
thanks for the reply...
I've try different combinations of flags, nothing seems to work
change the name of the section so it does'nt get combined with other
but same result.

Code:
_BSS SEGMENT   'BSS'

;som_var DWORD ?
_data  BYTE 307200 DUP(?)

_BSS ENDS
public _data
END
    


with masm doesn't work either.(well it gives me a
warning LNK4078: multiple ".bss" sections found with different attributes (C0520080))
although there is no other .bss section (or I have'nt found it yet)
Iknow that Borland compiler/linker can handle this,
I'll check MS compiler to see what flags sets in its
obj files or how does handle uninitialize data.
Thank you.
Post 06 Oct 2025, 15:45
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4288
Location: vpcmpistri
bitRAKE 06 Oct 2025, 20:28
Tomasz Grysztar wrote:
With object output the section that contains only uninitialized data is marked with IMAGE_SCN_CNT_UNINITIALIZED_DATA automatically
This means that:
Code:
format MS COFF ; or MS64
section ".bss" data readable writeable
public _data ; if access is needed in other modules
_data db 307200 DUP(?)    
... is sufficient to create the needed section.

We can verify with "dumpbin /ALL _data.obj":
Code:
SECTION HEADER #1
    .bss name
       0 physical address
       0 virtual address
   4B000 size of raw data
       0 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
C03000C0 flags
         Initialized Data
         Uninitialized Data
         4 byte align
         Read Write    

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.


Last edited by bitRAKE on 06 Oct 2025, 20:39; edited 2 times in total
Post 06 Oct 2025, 20:28
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4288
Location: vpcmpistri
bitRAKE 06 Oct 2025, 20:33
lunada wrote:
with masm doesn't work either.(well it gives me a
warning LNK4078: multiple ".bss" sections found with different attributes (C0520080))
although there is no other .bss section (or I have'nt found it yet)
MASM's [default] model directive creates default sections - you'll need to mirror the default attributes to combine explicit sections (i.e. add the read/write attributes, iirc).

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 06 Oct 2025, 20:33
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.