title: When are GAS ELF the directives .type, .thumb, .size and .section needed?
body: <p>I'm working on an assembly program for an ARM Cortex-M3 based microcontroller (Thumb 2 instruction set), using GNU as.</p>
  <p>In some example code I find directives like <code>.size</code>, <code>.section</code> and <code>.type</code> which I understand are ELF directives. As an example:</p>
  <pre><code>    .section    .text.Reset_Handler
      .weak       Reset_Handler
      .type       Reset_Handler, %function  
  Reset_Handler:
      bl      main
      b       Infinite_Loop    
      .size   Reset_Handler, .-Reset_Handler
  </code></pre>
  <hr /><br />
  <p>The <code>.type</code> directive is said to set the type of a symbol - usually either to <code>%object</code> (meaning data?) or <code>%function</code>. I do not know what difference it makes. It is not always included, so I am unsure when it needs to be used.</p>
  <p>Also related to this is the <code>.thumb_func</code> directive. From what I have read it seems like it <em>might</em> be equivalent to:</p>
  <pre><code>.thumb 
  .type Symbol_Name, %function
  </code></pre>
  <p>Or is it something completely different?</p>
  <hr /><br />
  <p><code>.size</code> supposedly sets the size associated with a symbol. When this is needed, I have no idea. Is this calculated by default, but overrideable with this directive? If so - when would you want to override?</p>
  <hr /><br />
  <p><code>.section</code> is easier to find docs on, and I think I have a fair idea of what it <em>does</em>, but I am still a little bit unsure about the usage. The way I understand it, it switches between different ELF sections (<code>text</code> for code, <code>data</code> for writable data, <code>bss</code> for uninitialized data, <code>rodata</code> for constants, and others), and defines new ones when desired. I guess you would switch between these depending on whether you define code, data, uninitialized data, etc. But why would you create a subsection for a function, as in the example above?</p>
  <hr />Any help with this is appreciated. If you can find links to tutorials or docs that explain this in greater detail - preferably understandable for a novice - I would be very grateful. 
  <p>So far, the <a href="https://sourceware.org/binutils/docs/as/" rel="nofollow noreferrer">Using as</a> manual has been of some help - maybe you can get more out of it than me, with more knowledge.</p>