flat assembler
Message board for the users of flat assembler.

Index > Linux > Segments and sections

Author
Thread Post new topic Reply to topic
jorido



Joined: 23 Jan 2017
Posts: 53
jorido 30 Jan 2017, 05:13
I'm confused: what's the difference between section and segment? What are they for in the first place? I've read the documentation but the matter isn't described clear enough.
Post 30 Jan 2017, 05:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 30 Jan 2017, 05:23
The meanings are not fixed and different authors use different attributions.

So with that in mind we can say this:

A section is a portion of a file (usually a PE or ELF file) that defines some code/data.

A segment is a memory area in an x86 CPU that is accessed with the help of a segment register, like DS or ES etc.

Okay so far so good. Now we get to the tricky part. Some people also use segment to refer to a portion of a file that contains code or data or whatever. And some people use section to refer to an x86 CPU segment.

Now you should be totally confused. Sorry about that. The thing to take away from this is that you have to look at each document and work within the context that the author is describing. I wish there was better way, but unfortunately we appear to be stuck with it.
Post 30 Jan 2017, 05:23
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 30 Jan 2017, 07:51
I would guess that the question is about the difference between SEGMENT and SECTION directives a defined by fasm in context of ELF output format. This is a terminology taken straight from the ELF specification.

A segment is a run-time entity defined in the Program Headers. It has no name, only attributes, and it is used to map an executable file into memory.

A section is defined in the Section Headers, has a name and attributes and is used mainly when linking object files. Linking combines the sections with the same name into a single section.

A linker usually combines multiple sections into a single segment, for example all code sections may be combined into a single segment with "executable" attribute.

When you look at the figure 1-1 in ELF specification, you may notice that Program Headers are mandatory for executable ELF, while Section Headers are only mandatory for the object file. Though linkers usually keep section headers in the executable files they create, mainly for informative purposes (e.g. debugging). But when you use "format ELF executable" in fasm, you create an executable that has no section headers at all and you only define segments.
Post 30 Jan 2017, 07:51
View user's profile Send private message Visit poster's website Reply with quote
jorido



Joined: 23 Jan 2017
Posts: 53
jorido 30 Jan 2017, 08:32
Yes. And what are the mandatory sections or segments for a Linux x32 or 64 application/library which a programmer must define? I've read that for a Linux application there must be no sections defined in an asm file.
Post 30 Jan 2017, 08:32
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.