<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Handling weakundef symbol"
   href="https://llvm.org/bugs/show_bug.cgi?id=30609">30609</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Handling weakundef symbol
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LLVM gold plugin set the visibility of weakundef symbol to be default while GCC
lto plugin sets it to hidden.

With LLVM gold plugin and bfd linker, the weak attribute of 'hello' will be
dropped in the final shared object:


 clang  -fuse-ld=bfd -flto=thin -O2 -shared -fPIC -o libt.so test.c


If the program is compiled with -DHIDDEN, linker reports the following error
(for both bfd and Gold linker): (happens with both llvm lto and thinlto)

/usr/bin/ld: /tmp/lto-llvm-e9a305.o: relocation R_X86_64_PC32 against undefined
hidden symbol `hello_world' can not be used when making a shared object

/usr/bin/ld.gold: error: /tmp/lto-llvm-9dad7e.o: requires dynamic R_X86_64_PC32
reloc against 'hello_world' which may overflow at runtime; recompile with -fPIC


GCC LTO is fine (with both linkers)



#ifdef HIDDEN
__attribute__((weak,visibility("hidden"))) int hello_world();
#else
__attribute__((weak)) int hello_world();
#endif

int test() {
  if (hello_world)
      return hello_world();
  return 0;
}</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>