flat assembler
Message board for the users of flat assembler.
Index
> Linux > section vs. segment notations |
Author |
|
Ali.Z 24 Jul 2018, 19:08
i do understand sections segments paging virtual memory.
but i cant explain them well enough, because i didnt go deep in these subjects. sections are programmer defined, use section to specify this section of code is related to code segment. section data related to data segment in physical memory. you can set permissions for each section, for example if you mark code section as writeable readable exectuable then it will be treated as an executable data. (this is good for self modifying code) segments are used to indecate each block of byte an their uses in ram, segments also have access rights, base address, and limit. by default any executing code will go to CS, data in DS, stack SS etc. each process have it own segment in memory, and according to intel each segment have privilege level. paging also related to segments and the virtual memory. by default and usually programs have 2 pages at least, 4kb for code and 4kb for data. if you are storing more data in your program then another page with 4kb allocated for you. sure paging and virtual memory can be OS dependent, OS can specifiy and modify processor mode via CR0 register. (note i said mode, because you cant enable PG bit without enabling PE bit in CR0) also segments where mainly used in real-mode years ago. but now most of them are useless except GS FS the OS use them for it own purpose. (again it can be OS specific) _________________ Asm For Wise Humans Last edited by Ali.Z on 25 Jul 2018, 03:59; edited 1 time in total |
|||
24 Jul 2018, 19:08 |
|
Tomasz Grysztar 24 Jul 2018, 20:39
This section/segment distinctions comes directly from the ELF specification.
When ELF is executable, segment definitions (in so-called Program Header Table) are required. When ELF is an object, the Section Table is required. But an ELF file may contain both tables at the same time. A single segment may then correspond to multiple sections, but not the other way around. The segments define areas in memory with different attributes (like executable, writable, etc.) and are important for program loader. The sections are more important for the symbolic value, like their names, and they do not need to be present in the final executable. But the linker requires them, as it is usually the linker that constructs the Program Header Table and defines segments by combining sections with a similar attributes. After the segments are constructed, the section table can be safely discarded, though it usually isn't. But if you use fasm to produce ELF executable directly, it contains only Program Header Table and no section definitions at all. That's why you define segments directly then. |
|||
24 Jul 2018, 20:39 |
|
moveax41h 24 Jul 2018, 23:37
Ahhh thank you for the great thorough explanation, I get it now!
I hadn't dug into the ELF format specs yet enough to know about the PHT... Though I find executable file formats fascinating and have published some research involving the Windows PE file format a while back. Fascinating stuff, I'm going to do some deep-diving on ELF format soon just to learn it like I did with PE. |
|||
24 Jul 2018, 23:37 |
|
Tomasz Grysztar 25 Jul 2018, 09:40
I'm currently writing the first chapter of my new tutorial series, though I have started with PE. BTW, if you are interested in trivia about executable formats, please take a look at various off-shoots of that writing that I posted on Twitter.
And when I finish with PE (although this may take some time, there are many things to cover), I'm planning to start writing about ELF. |
|||
25 Jul 2018, 09:40 |
|
Gyver 26 Jul 2018, 09:25
See here if y want to understand the ELF format
https://github.com/corkami/pics/tree/master/binary/elf101 Have a nice day! |
|||
26 Jul 2018, 09:25 |
|
moveax41h 26 Jul 2018, 11:38
That's a good one - thanks Gyver.
Tomasz I look forward to your tutorial. I found that 010 Editor with the binary templates for EXE and ELF were helpful to me when working with PEs. |
|||
26 Jul 2018, 11:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.