llvm / llvm/llvm-project

clang-nvlink-wrapper: -u/--undefined is forwarded to nvlink, which fails on it

Open Beginner friendly
#216,891 0 comments 2 reactions 0 assignees View on GitHub
clang-tools-extra
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

clang/tools/clang-nvlink-wrapper (NVLinkOpts.td)

In NVLinkOpts.td the -u/--undefined option carries no WrapperOnlyOption flag:

def u : JoinedOrSeparate<["-"], "u">, HelpText<"Force undefined symbol during linking">;
def undefined : JoinedOrSeparate<["--"], "undefined">, Alias;

so besides being used for symbol resolution it is also forwarded to the real nvlink, which doesn't
know the flag and errors out. Compare plugin-opt=O a few lines below, which has
Flags<[WrapperOnlyOption]> and is consumed by the wrapper as intended. Still the case at main as of
today.

-u is the natural way to pin an LTO liveness root for a device symbol. The case where we hit this:
host-launched kernels declared with hidden visibility get no VisibleToRegularObj liveness root,
device LTO internalizes and dead-strips them (583 CUB kernels in PyTorch's libtorch_cuda.so in our
build), and the failure only surfaces at runtime as cudaErrorSymbolNotFound. -u would be
the obvious workaround, but the leak kills the link instead.

The fix is one line: add Flags<[WrapperOnlyOption]> to the u def (undefined inherits it through the
alias), plus a lit test asserting the constructed nvlink command line no longer carries -u.

Contributor guide

Open the contributing guide

Research direction

Start in clang/tools/clang-nvlink-wrapper/NVLinkOpts.td and compare the -u definition with the plugin-opt=O option mentioned in the issue. Locate the relevant lit coverage for the constructed nvlink command line, then verify that the test passes and the generated command no longer includes -u.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
87/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.