@@ -133,6 +133,9 @@ static const char *LinkerExecutable;
133
133
// / Filename of the executable being created.
134
134
static StringRef ExecutableName;
135
135
136
+ // / System root if passed in to the linker via. '--sysroot='.
137
+ static StringRef Sysroot = " " ;
138
+
136
139
// / Binary path for the CUDA installation.
137
140
static std::string CudaBinaryPath;
138
141
@@ -169,8 +172,8 @@ void printCommands(ArrayRef<StringRef> CmdArgs) {
169
172
return ;
170
173
171
174
llvm::errs () << " \" " << CmdArgs.front () << " \" " ;
172
- for (auto IC = CmdArgs.begin () + 1 , IE = CmdArgs.end (); IC != IE; ++IC)
173
- llvm::errs () << *IC << (IC + 1 != IE ? " " : " \n " );
175
+ for (auto IC = std::next ( CmdArgs.begin ()) , IE = CmdArgs.end (); IC != IE; ++IC)
176
+ llvm::errs () << *IC << (std::next (IC) != IE ? " " : " \n " );
174
177
}
175
178
176
179
static StringRef getDeviceFileExtension (StringRef DeviceTriple,
@@ -726,10 +729,10 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple,
726
729
CmdArgs.push_back (Arg);
727
730
else if (Arg.startswith (" -rpath" )) {
728
731
CmdArgs.push_back (Arg);
729
- CmdArgs.push_back (*(AI + 1 ));
732
+ CmdArgs.push_back (*std::next (AI));
730
733
} else if (Arg.startswith (" -dynamic-linker" )) {
731
734
CmdArgs.push_back (Arg);
732
- CmdArgs.push_back (*(AI + 1 ));
735
+ CmdArgs.push_back (*std::next (AI));
733
736
}
734
737
}
735
738
CmdArgs.push_back (" -Bsymbolic" );
@@ -1157,8 +1160,11 @@ Expected<std::string> wrapDeviceImages(ArrayRef<std::string> Images) {
1157
1160
1158
1161
Optional<std::string> findFile (StringRef Dir, const Twine &Name) {
1159
1162
SmallString<128 > Path;
1160
- // TODO: Parse `--sysroot` somewhere and use it here.
1161
- sys::path::append (Path, Dir, Name);
1163
+ if (Dir.startswith (" =" ))
1164
+ sys::path::append (Path, Sysroot, Dir.substr (1 ), Name);
1165
+ else
1166
+ sys::path::append (Path, Dir, Name);
1167
+
1162
1168
if (sys::fs::exists (Path))
1163
1169
return static_cast <std::string>(Path);
1164
1170
return None;
@@ -1229,7 +1235,13 @@ int main(int argc, const char **argv) {
1229
1235
if (!CudaPath.empty ())
1230
1236
CudaBinaryPath = CudaPath + " /bin" ;
1231
1237
1232
- ExecutableName = *(llvm::find (HostLinkerArgs, " -o" ) + 1 );
1238
+ auto RootIt = llvm::find_if (HostLinkerArgs, [](StringRef Arg) {
1239
+ return Arg.startswith (" --sysroot=" );
1240
+ });
1241
+ if (RootIt != HostLinkerArgs.end ())
1242
+ Sysroot = StringRef (*RootIt).split (' =' ).second ;
1243
+
1244
+ ExecutableName = *std::next (llvm::find (HostLinkerArgs, " -o" ));
1233
1245
SmallVector<std::string, 16 > LinkerArgs;
1234
1246
for (const std::string &Arg : HostLinkerArgs)
1235
1247
LinkerArgs.push_back (Arg);
0 commit comments