Search code examples
linkerldlinker-scripts

Why my system ld script use expression like "dot = dot"?


When dumping my system's linker script with ld -verbose, I noteice that it uses:

  .data1          : { *(.data1) }                                                                                                                                                                                   
  _edata = .; PROVIDE (edata = .);                                                                                                                                                                                  
  . = .;                                                                                                  
  __bss_start = .;                                                                                        
  .bss            :  

why does it assign the current address to the current address?


Solution

  • . = .; serves as a barrier for orphan section placement.

    https://sourceware.org/binutils/docs/ld/Location-Counter.html says "... Instead, it assumes that all assignments or other statements belong to the previous output section, except for the special case of an assignment to ."

    After the linker picks the best output section description, it will skip following non-. symbol assignments. With a . = .;, the linker will stop searching and place the orphan section immediately above the . = .;.