title: Finding the memory location of a compile-time constructed class
body: <p>I'm trying to do some memory-usage analysis of using compile-time constructed classes by looking at the artifacts generated by compilation.  I've marked several class constructors with "constexpr" and made sure they're trivial to ensure compile-time construction.  Viewing the map file, I can see that the constructors and destructor functions are not included in the .text section any more.</p>
  
  <p>Where, though, do these classes appear?  I had assumed that they would be included in the .data section as a static instance of the class, but that doesn't seem to be the case.  The .text section has shrunk but all other sections seem to be the same.  Where is this data going?</p>
  
  <p>(I'm using GCC 5.2.0 and creating a statically-linked ELF.)</p>
  
  <p>Edit: Here's a bit of sample code.</p>
  
  <pre><code>#include &lt;stddef.h&gt;
  #include &lt;stdint.h&gt;
  
  struct AbstractMemoryAccess
  {
      virtual uint32_t read() const = 0;
  
      virtual void write(const uint32_t data) const = 0;
  };
  
  class ConcerteMemoryAccess : public AbstractMemoryAccess
  {
  public:
      constexpr ConcerteMemoryAccess(const size_t baseAddress)
          : _baseAddress(baseAddress)
      {
          // empty
      }
  
      virtual uint32_t read() const
      {
          return *(volatile uint32_t *)(_baseAddress);
      }
  
  
      virtual void write(const uint32_t data) const
      {
          *(volatile uint32_t *)(_baseAddress) = data;
      }
  
  private:
      const size_t _baseAddress;
  };
  
  #define ARBITRARY_PERIPHERAL_ADDRESS 0x40001000
  
  int main(void)
  {
      ConcerteMemoryAccess memoryAccessor(ARBITRARY_PERIPHERAL_ADDRESS);
      AbstractMemoryAccess &amp;rAbsMemoryAccessor = memoryAccessor;
  
      while (1)
      {
          uint32_t readData = rAbsMemoryAccessor.read();
          rAbsMemoryAccessor.write(readData);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Which decompiles to this:</p>
  
  <pre><code>000006a4 &lt;main&gt;:
   6a4:   b0004000    imm 16384
   6a8:   e8601000    lwi r3, r0, 4096
   6ac:   b0004000    imm 16384
   6b0:   f8601000    swi r3, r0, 4096
   6b4:   b800fff0    bri -16 // 6a4 &lt;main&gt;
  </code></pre>
  
  <p>So it looks like it's inlining the memory accesses... but is that true for non-trivial cases?  Are all calls on a constexpr object inlined?</p>