<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - GlobalMerge optimization drops visibility attributes"
   href="https://bugs.llvm.org/show_bug.cgi?id=39413">39413</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GlobalMerge optimization drops visibility attributes
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rprichard@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The GlobalMerge optimization enabled with -Oz or -O3 appears to discard
visibility attributes from variables. The merged variables have default
visibility when they were declared as hidden or protected.

int somevar1 __attribute__((visibility("hidden"))) = 1;
int somevar2 __attribute__((visibility("hidden"))) = 2;
int somevar3 __attribute__((visibility("protected"))) = 1;
int somevar4 __attribute__((visibility("protected"))) = 2;
int get12() {
  return somevar1 + somevar2;
}
int get34() {
  return somevar3 + somevar4;
}

$ clang -target arm -Oz test.c -c && readelf -s test.o | grep somevar
    11: 00000000     4 OBJECT  GLOBAL DEFAULT    6 somevar1
    12: 00000004     4 OBJECT  GLOBAL DEFAULT    6 somevar2
    13: 00000008     4 OBJECT  GLOBAL DEFAULT    6 somevar3
    14: 0000000c     4 OBJECT  GLOBAL DEFAULT    6 somevar4

$ clang -target arm -Oz test.c -c -mno-global-merge && readelf -s test.o | grep
somevar
     9: 00000000     4 OBJECT  GLOBAL HIDDEN     6 somevar1
    10: 00000004     4 OBJECT  GLOBAL HIDDEN     6 somevar2
    11: 00000008     4 OBJECT  GLOBAL PROTECTED    6 somevar3
    12: 0000000c     4 OBJECT  GLOBAL PROTECTED    6 somevar4

This was originally reported against the Android NDK
(<a href="https://github.com/android-ndk/ndk/issues/829">https://github.com/android-ndk/ndk/issues/829</a>).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>