<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 - LLD doesn't version linker script symbol aliases"
   href="https://bugs.llvm.org/show_bug.cgi?id=34121">34121</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD doesn't version linker script symbol aliases
          </td>
        </tr>

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

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>grimar@accesssoftek.com, llvm-bugs@lists.llvm.org, rafael.espindola@gmail.com, ruiu@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>% cat sym.c
void f() {}

% cat sym.script
g = f;
VERSION { V1 { global: f; g; local: *; }; }

% clang -fPIC -c sym.c
% ld.lld -shared -o libsym.so sym.o sym.script --no-undefined-version
ld.lld: error: version script assignment of 'V1' to symbol 'g' failed: symbol
not defined

ld.bfd handles this correctly. ld.gold complains about having VERSION in a
linker script, but it works correctly if you pass it a separate version script.

I'll explain my use case, in case it helps with understanding the
motivation/suggesting alternatives. I'm renaming a large number of symbols in a
library (via changing an inline namespace), but I still need to preserve both
the old and new names for a while, for backward compatibility. The old and new
names are both versioned (I'm aware this is a pretty weird way to use symbol
versioning, but there's a long story there). As far as I know, I have three
ways to alias the old names to the new ones:

1. attribute((alias)). This requires the alias to be in the same translation
unit as the symbol being aliased, which isn't practical in my case.
2. Define the aliased functions myself to just call the new names. This works,
but it bloats up the text segment and introduces an extra jump. It also doesn't
work for data symbols.
3. Alias via the linker, using linker scripts or --defsym. This seems like the
ideal solution, but both approaches run into issues.

I have a small and (I think) pretty reasonable patch to make --defsym aliases
work with version scripts, but <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLD doesn't set dynamic symbol names for --defsym correctly"
   href="show_bug.cgi?id=34113">https://bugs.llvm.org/show_bug.cgi?id=34113</a>
makes that patch pretty useless for now. Linker script aliasing gets the symbol
table names correct, but linker script command processing also happens pretty
late, so getting that to play nice with version scripts might be more involved.

One workaround that I think will be good enough for me for now is to just drop
the local: *; from the version script. The source files are already annotated
with correct visibility annotations, so dropping that shouldn't produce any
unwanted exports. It's not super ideal in general though.</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>