Skip to content

Commit e603df0

Browse files
committed
[NvlinkWrapper] Add relocatable link support to LTO pass
Summary: We need `-r` to work so we can preserve symbols.
1 parent 599de13 commit e603df0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,11 @@ Expected<SmallVector<StringRef>> getInput(const ArgList &Args) {
598598
Res.Prevailing = !Sym.isUndefined() && ObjSym.File == *BitcodeFile;
599599

600600
// We need LTO to preseve the following global symbols:
601-
// 1) Symbols used in regular objects.
602-
// 2) Prevailing symbols that are needed visible to the gpu runtime.
601+
// 1) All symbols during a relocatable link.
602+
// 2) Symbols used in regular objects.
603+
// 3) Prevailing symbols that are needed visible to the gpu runtime.
603604
Res.VisibleToRegularObj =
604-
ObjSym.UsedInRegularObj ||
605+
Args.hasArg(OPT_relocatable) || ObjSym.UsedInRegularObj ||
605606
(Res.Prevailing &&
606607
(Sym.getVisibility() != GlobalValue::HiddenVisibility &&
607608
!Sym.canBeOmittedFromSymbolTable()));

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def plugin_opt : Joined<["--", "-"], "plugin-opt=">, Flags<[WrapperOnlyOption]>,
7373
def save_temps : Flag<["--", "-"], "save-temps">,
7474
Flags<[WrapperOnlyOption]>, HelpText<"Save intermediate results">;
7575

76+
def relocatable : Flag<["--", "-"], "relocatable">,
77+
Flags<[WrapperOnlyOption]>, HelpText<"Perform a relocatable link (LTO only)">;
78+
def r : Flag<["-"], "r">, Flags<[WrapperOnlyOption]>, Alias<relocatable>;
79+
7680
def whole_archive : Flag<["--", "-"], "whole-archive">,
7781
Flags<[WrapperOnlyOption, HelpHidden]>;
7882
def no_whole_archive : Flag<["--", "-"], "no-whole-archive">,
@@ -83,8 +87,7 @@ def mllvm : Separate<["-"], "mllvm">, Flags<[WrapperOnlyOption]>,
8387
HelpText<"Arguments passed to LLVM, including Clang invocations, for which "
8488
"the '-mllvm' prefix is preserved. Use '-mllvm --help' for a list "
8589
"of options.">;
86-
def mllvm_EQ : Joined<["-"], "mllvm=">, Flags<[HelpHidden]>,
87-
Alias<mllvm>;
90+
def mllvm_EQ : Joined<["-"], "mllvm=">, Flags<[HelpHidden]>, Alias<mllvm>;
8891

8992
def dry_run : Flag<["--", "-"], "dry-run">, Flags<[WrapperOnlyOption]>,
9093
HelpText<"Print generated commands without running.">;

0 commit comments

Comments
 (0)