'How are segment selectors related to the address?

Let's say I run the following C code and get 0x7ffd385c9588:

#include <stdio.h>

int main() {
  int test = 5;
  
  printf("%p", &test);
  
  return 0;
}

I've heard that the logical address contains the segment selector, so does the value provided by printf contain it?

I thought it was embedded within the segment register part of the instruction, e.g. ds:[0x7ffd385c9588], but it's said that x64 uses 48-bit addresses, which would only fit the offset and not the selector.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source