title: How do I sort the symbols of other sections besides the "COMMON" section?
body: <p>The gnu linker &quot;ld&quot; supplies the option &quot;-sort-common&quot; which sorts the uninitialized global parameters, known as the COMMON section symbols, by their size. When the linker aligns the symbols to even addresses, this option helps minimizing the holes in the section.
  For example, if we define:</p>
  <blockquote>
  <p>--main.c</p>
  <p>char a;</p>
  <p>short b;</p>
  <p>char c;</p>
  <p>int main() { return 0; }</p>
  </blockquote>
  <p>and compile it to main.o without &quot;sort-common&quot; we will get a &quot;hole&quot; of one byte between the address of &quot;a&quot; and the address of &quot;b&quot;. If we use &quot;sort-common&quot; the linker will reorder the parameters to &quot;a, c, b&quot;, and since a's size is 1 byte and c's size is 1 byte, there will be no &quot;hole&quot; between their adresses.
  My problem is that my code looks like:</p>
  <blockquote>
  <p>--main.c</p>
  <p>char a = 0;</p>
  <p>short b = 0;</p>
  <p>char c = 0;</p>
  <p>...</p>
  </blockquote>
  <p>In this case a, b, and c are in the BSS section, which means that &quot;sort-common&quot; will not affect them.</p>
  <p><strong>How do I sort the symbols of other sections besides the &quot;COMMON&quot; section?</strong></p>
  <p>I also searched many options in the LD scripts, unsuccessfully.</p>
  <p><strong>Update</strong>: I read something about &quot;Order&quot; value in the segment_flags, and didn't understand how to use it. Any help is appreciable.</p>