flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
upsurt 12 Dec 2014, 10:03
Hi
I've some questions about sections and best practices. I read on a website that: Quote: The data section is used for declaring initialized data or constants. This data does not change at runtime. You can declare various constant values, file names or buffer size, etc., in this section. and Quote: The bss section is used for declaring variables. By now I used only the data section and defined there constants AND variables. Is this bad and should I change that? On another website they describe even more sections. But I've also seen sections in code sample in the FASM board, that aren't defined there at all. Code: section 'database' data readable writeable ...to define variables Code: section 'code' code executable readable ...used instead of .text Code: section 'executbl' code executable readable ...used instead of .text And I've also seen variables and constants defined outside of any section at all. Can anybody explain the best pratice and which sections someone should really use? |
|||
![]() |
|
upsurt 12 Dec 2014, 12:31
But I guess there a things you should take care off?
Like I would expect, you shouldn't mix up code and data definition inside the same section, or? |
|||
![]() |
|
evk1 12 Dec 2014, 20:46
You can put code and data definitions in a single section if you want. Moreover, if your code and data fits in 4096 bytes, it should be more effective to use only one section. There is only one real reason to separate static data (code, strings, immutable tables, etc) from dynamic data. If your program contains non-writable sections, an OS can apply memory mapping mechanism to them, i.e. when your system has not enough memory, it takes away memory pages which contains some seldom accessed data from your program, and when your program tries to read such data, OS reallocates memory for it and reloads required data from your program file. For this reason executable file cannot be deleted or modified during the program execution. If a section has a write access then its actual content may differs from its original content and this way cannot be applied.
_________________ Sorry for my English |
|||
![]() |
|
evk1 12 Dec 2014, 23:19
I think, uninitialized variables should be placed at the end of data section. I don't know internal structure of PE file format, but for example, in ELF in memory segments can occupy larger space then they occupies in files. Such segments contains all data from their images in the file, but also have some additional uninitialized space. For example:
Code: segment readable writeable
var1 dd 123
var2 dd ?
var3 dd ? This segment will occupy only 4 bytes in file and will contain only var1 variable. var2 and var3 variables are located at the uninitialized part of segment, which occupies no file space. Such additional segment space can be added only to its end, so it is better to put uninitialized variables to the end of segment. I think PE have similar rules for sections. This and my previous remark are related to PE programs and libraries. But then you are writing an object file you should place code, initialized data, uninitialized data, strings, etc at the different sections, because in such situations linker usually uses your file and some over object files to compose the correct program/library, and separating each kind of data helps it to find the best way to place all sections in the output file. However, I think, it is not necessary to use standard names for sections in this situation, but it is necessary to use standard section alignment and standard section access rights. _________________ Sorry for my English |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.