title: Why do static inline data members not end up in a .bss section on Macos?
body: <p>Trying out <a href="https://github.com/microsoft/snmalloc" rel="noreferrer">snmalloc</a> on Macos I wondered why <a href="https://github.com/microsoft/snmalloc/issues/339" rel="noreferrer">all the created binaries are &gt;256MiB</a>.</p>
  <p>It turns out that zero-initialized <code>static inline</code> data members are lowered in a weird way on Mac OS X, on both ARM64 and x86_64. Even this simple test produces huge binaries:</p>
  <p>container.h</p>
  <pre class="lang-cpp prettyprint-override"><code>#pragma once
  #include &lt;cstdint&gt;
  
  class Container {
      public:
          inline static uint8_t inner[256000000];
  };
  </code></pre>
  <p>main.cc</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;container.h&quot;
  
  int main() {
      return Container::inner[0];
  }
  </code></pre>
  <p>Compiled like this:</p>
  <pre><code>$ ~/clang+llvm-12.0.0-x86_64-apple-darwin/bin/clang -O3 -std=c++17 main.cc --target=x86_64-apple-darwin -c; ls -l main.o
  -rw-r--r--  1 hans  staff  256000744 Jun 21 16:29 main.o
  </code></pre>
  <p>It is the same with open-source clang as with Apple clang. gcc behaves similarly.</p>
  <p>On Linux (compiled with either clang or gcc) it is included in the .bss section, thus not taking up any space.</p>
  <p>Why is this the case on Macos? And is this a bug or expected behavior?</p>