<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 - RTLD_LAZY does not work if compiled with clang"
   href="https://bugs.llvm.org/show_bug.cgi?id=37779">37779</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RTLD_LAZY does not work if compiled with clang
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </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>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>tom.ty89@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20421" name="attach_20421" title="Example">attachment 20421</a> <a href="attachment.cgi?id=20421&action=edit" title="Example">[details]</a></span>
Example

Supposedly with RTLD_LAZY, symbols will only be resolved as the code references
them are executed. However, when compiled with clang, undefined symbols are
being resolved before dlopen() returns, as if RTLD_NOW is used.

Here's the difference when the attached example is compiled with gcc and clang
respectively:

$ make
cc -shared libshared.c -o libshared.so                                         
   cc -shared libplugin.c -o libplugin.so
cc main.c -ldl -o executable
$ ./executable
plugin: value = 42
$ make clean
rm -f executable libshared.so libplugin.so
$ make CC=clang
clang -shared libshared.c -o libshared.so
clang -shared libplugin.c -o libplugin.so
clang main.c -ldl -o executable
$ ./executable
dlopen failed: ./libplugin.so: undefined symbol: libshared_get_value
$</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>