Skip to content

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

Description

@BwL1289

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<u>;

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions