How is the program segmented?

I apologize in advance if this question is considered too trivial, but I spent a lot of time trying to find a direct answer online and could not.

Recently I read in the programming class an intro on program segmentation and how usually programs are divided into "segments" that are individually loaded into memory (or partially loaded into memory, via paging ... I think) when necessary. In our book, it was mentioned that programs are often divided into segments based on logical divisions, for example. segment for stack, for heap, for global constants, etc.

I wonder what exactly determines how this segmentation works. Is this done by the compiler at compile time? Or does the OS somehow handle this? Does each subroutine always get its own segment, no matter how small it is?

I know that information related to segmentation, such as segment descriptors, etc., is processed at the architecture level using registers and is specifically designed to work with segmentation. But I just have a lot of problems when I see where / how the actual segmentation of the program occurs, and how this information falls into these registers. How do addresses translate into segment identifiers and offsets? Can anyone enlighten me? Thank you so much for any help you can give and I'm sorry if I included any concepts in it.

+3
source share
3 answers

This is a good question, and I can provide only a little information that could guide you in the right direction. I believe that the segmentation of programs is determined by the format of the executable file, so if you want to get specific information, find a specification of your own format (for example, any of the various ELF options). It may be interesting to read older formats such as a.out or the old DOS “MZ” binaries, if only for perspective and to view simpler specifications. [EDITED: for clarity]

, , , toolchain ( , : , C , , ) . .

, .

+1

; , .

OS X file /bin/ls /bin/ls: Mach-O universal binary with 2 architectures

. , , , , .

:

Mach-O Mach-O, , , 0 255 . Mach-O REL . Mach-O , " /", , .

- , , Accent. Accent , , Spice Lisp.

:

+1

.

, - . , . : , . : .

, - . ( ) . .

( ) (/​​, , ), //, , , . . (- , ), .

- (, DLL). ( , ) , , .

, , ( ).

, , . 16- x86. , 1 ( 8086) 16 ( 16- ), CPU 16- , . 65536 . , , . MSDOS (= ) (= ) , , 65536 .

+1
source

All Articles