0
votes

I'm trying to wrap my head around the way program memory is allocated at run-time and the different sections or "segments" of a program (if that is the right word). I'm almost there, but not quite and could use a little help.

I know that the program contains a .data section, with both read only and read-write memory for initialized global variables. I know that the .bss section is used for uninitialized global and static variables and is read-write. I understand the heap and the stack.

The following questions illustrate my confusion:

  1. What is the .rodata section and where does it exist?
  2. How does the .data? section in MASM differ from the .data section?
  3. Does every program have to have the standard .data, .bss, .code sections, or are these conventions just guidelines?
  4. What determines which sections are readable, writable, and executable?

Any help would be greatly appreciated.

1

1 Answers

2
votes
  1. .rodata is for read-only data, aka constants and literals, see this.

  2. according to this, .data? is for uninitialized data, aka .bss sectional data, .data is for initialized data.

  3. According to the Windows PE format, you can never assume that certain sections are present and their order (as they state that it is compiler defined). however, its pretty standard to have .data and .code, but still, you should always check the PE, thats why its there.

  4. This is done via the PE Section headers, as such it is OS specific (or PE specific: win, elf or mach-o), see the paragraph on sections here, specifically the Characteristics field of the section descriptor (again this is for Windows only, you need to use the PE layout for your chosen OS).