0

Always I refer to x86 (Linux)

  • Are logical addresses created during the generation of a binary?
  • If yes, are their inside the binary?

Thanks

Hadi Brais
  • 22,259
  • 3
  • 54
  • 95
Hack Facilito
  • 71
  • 1
  • 8

2 Answers2

1

In x86, a logical address (also called a far pointer) consists of a 16-bit segment selector and a 16/32/64-bit offset (also called a near pointer). The size of the offset depends on the operating mode, the code segment descriptor, and the address size prefix. Then the segment selector is used to obtain the segment base address (or it's obtained from the segment descriptor cache except when operating in 64-bit mode in which the base address is considered to be zero for all segments except for FS and GS) to be added to the offset to form a virtual address. The x86 ISA offers no way to completely skip that process. So any x86 instruction must specify the two parts that constitute the logical address separately (implicitly or explicitly).

Are logical addresses created during the generation of a binary?

An x86 binary contains x86 instructions. Each instruction specifies which segment register to use and how to calculate the offset (using stuff like base, index, scale, and displacement). At run-time, when an instruction is being executed, the offset is calculated and the segment selector value is determined. So, technically, x86 instructions only tell the CPU where to get the segment selector from and how to calculate the offset, but it is the CPU that generates the logical address. Generally, the compiler and the OS determine the values of offsets, but only the OS controls the values of the segment selectors.

If yes, are their inside the binary?

x86 instructions may specify the offset as an immediate value (constant). The segment part can be either specified as an immediate value (far call or var jump), fetched from a segment register, or fetched from memory (far return). So the value of the offset might be in the binary encoded with the instruction that uses it, but the value of the segment selector might not.

Hadi Brais
  • 22,259
  • 3
  • 54
  • 95
  • I think the OP just means virtual addresses, not x86 linear addresses. Also, they asked about Linux, which uses a flat memory model with base=0. No need to overcomplicate things with x86 segmentation. *So any x86 instruction must specify the two parts that constitute the logical address separately.* is somewhat misleading because the segment part is usually implicit, with basically no overhead compared to ARM or whatever in the instruction format. – Peter Cordes Apr 24 '18 at 01:17
  • Also, the segment selector value in a segment register is only used when it's first written, to update the cached descriptor info. [The selector *value* is not re-checked for every instruction that uses the same segment, not even implicitly.](https://stackoverflow.com/questions/17786357/segment-size-in-x86-real-mode/49445670?noredirect=1#comment86962493_49445670). You have to reload `ds` after updating the GDT / LDT entry it selected. – Peter Cordes Apr 24 '18 at 01:24
  • @PeterCordes I mostly agree. I've interpreted the question literally. The memory model is flat except for FS and GS, which are used for thread-local storage. When I said "x86 instruction must specify..." I really meant explicitly *or* implicitly. I've improved the answer a little. – Hadi Brais Apr 24 '18 at 02:01
1

The LINKER defines the initial layout of the processes user address space. The linker then defines the range of logical addresses and their page attributes (read or read/write, execute or no execute).

The user area of the logical address space gets set up by the program loader when the executable is run.

The answer to your question

Are logical addresses created during the generation of a binary?

then depends upon you mean "created" to be when the logical address space is defined (linker) or whether you mean when it is set up (program loader).

user3344003
  • 20,574
  • 3
  • 26
  • 62