<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 - .dynsym reference in linked DSO should not bring in STV_HIDDEN symbol from archive"
   href="https://bugs.llvm.org/show_bug.cgi?id=45797">45797</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>.dynsym reference in linked DSO should not bring in STV_HIDDEN symbol from archive
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>roland@hack.frob.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```
echo > libimpl.c 'void impl_symbol() {}'                                        
echo > libapi.c 'void impl_symbol(); void api_symbol() { impl_symbol(); }'      
echo > plugin.c 'void api_symbol(); void plugin_symbol() { api_symbol(); }'     

clang -fPIC -shared -o libimpl.so -Wl,-soname,libimpl.so libimpl.c              
clang -fPIC -shared -o libapi.so -Wl,-soname,libapi.so libapi.c libimpl.so      

clang -fPIC -c -o libimpl-public.o libimpl.c                                    
ar cq libimpl-public.a                                                          

clang -fPIC -c -fvisibility=hidden -o libimpl-hermetic.o libimpl.c              
ar cq libimpl-hermetic.a                                                        

clang -fPIC -c plugin.c                                                         

for linker in lld gold bfd; do                                                  
  ld.$linker -o plugin-preempts.$linker -shared plugin.o --start-group
libimpl-public.a libapi.so --end-group                                          
  ld.$linker -o plugin-hermetic.$linker -shared plugin.o --start-group
libimpl-hermetic.a libapi.so --end-group                                        
done                                                                            

readelf -Ws plugin-preempts.lld                                                 
#    3: 0000000000001370     6 FUNC    GLOBAL DEFAULT    7 impl_symbol          
# as expected: impl_symbol is public and libapi.so has UND impl_symbol so       
# it preempts libimpl.so.  GNU linkers behave the same.                         

readelf -Ws plugin-hermetic.lld                                                 
#    3: 0000000000001340     6 FUNC    LOCAL  HIDDEN     7 impl_symbol          
# should not be there, it's pure dead code!                                     
# BFD behaves the same (buggy), but Gold does not (correct).                    
#                                                                               
# An STV_HIDDEN symbol can never satisfy a DSO's reference, so it should        
# not be brought into the link from an archive (nor preserved from GC if        
# brought in otherwise) because of such a reference.                            

```</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>