<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56468>56468</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            const volatile variables are placed in the wrong section
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jemarch
      </td>
    </tr>
</table>

<pre>
    Hello.

clang version 15.0.0 (https://github.com/llvm/llvm-project.git d3dd6e57fe84e90cadcdc78fa71d632f6573f156) places  `const volatile' variables like:

  const volatile int foo = 0;

in the .rodata section.  According to the C18 specification[1]:

  6.7.3 Type qualifiers / 5 The properties associated with qualified
  types are meaningful only for expressions that are lval-values [note
  135]

  135)The implementation may place a const object **that is not
  volatile** in a read-only region of storage. Moreover, the
  implementation need not allocate storage for such an object if its 
  address is never used.

Accordingly, GCC places such variables in the .data section.

Note that this is causing practical difficulties: the kernel's bpftool is generating different skeleton headers for BPF code compiled from LLVM and GCC, because the names of the containing sections get reflected.  For details on this please see [2].

Thanks!

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf
[2] https://lore.kernel.org/bpf/87fsj8vjcy.fsf@oracle.com/T/#me726127e166f97fd50f09b647a604f176f809c63
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE1z4jgQ_TXm0hWXLWMbDhzyUZk9zGztIbV3WWqBEmF5JAHLv98nE5Iwc5oqsC27-_Xr108avD5v_mLnfFlUT0V1f7kqJ8ctHTlE60eq27IqKyrEapfSFIvmvhDP-G1t2h2GUvk9Fs4dr7e7KfhXVqlEAOlG647b3vBqyetKSa206ldG9rXuGmG6tm9M3XaFWNPkpOJIVHSV8mNMdPROJuu4ED0dZbBycPju7BtnEl8IE90mkB0TGe-paJ6oKpqHr8F2pLRjKoPXMkmKoIo2S6J7pXzQFq0nP4c81iuKEytrrJI5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