Skip to content

Commit

Permalink
Optional power-user treatment to reduce syscalls during startup
Browse files Browse the repository at this point in the history
This commit provides the possibility to pass system library search
paths as well as some compiler include paths to ROOT as environment
variables.
This has the advantage that ROOT will not spawn sub-processes
and we can do the setup only once, instead of doing it for every
single executable that is linked to ROOT.
  • Loading branch information
sawenzel committed Jun 13, 2022
1 parent 82fc2dc commit 492a133
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/unix/src/TUnixSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4603,6 +4603,20 @@ static const char *DynamicPath(const char *newpath = 0, Bool_t reset = kFALSE)
dynpath += "/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
dynpath += "/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
#else
// ALICE: Let's see if an outside entity gave us the system path.
// This is a power-user feature with the goal to prevent repeated sys-calls (popen + sh) and to
// having to search repeatetly through potentially long strings (when the LD_LIBRARY_PATH of the software stack
// is very large).
// The power-user might define this during build or during setup of the software stack.
auto ldsyspath = getenv("ROOT_LDSYSPATH");
if (ldsyspath != nullptr) {
dynpath += ldsyspath;
// some code duplication here in order to keep patch
// minimal and easily applicable
dynpath.ReplaceAll("::", ":");
return dynpath;
}

// trick to get the system search path
std::string cmd("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
FILE *pf = popen(cmd.c_str (), "r");
Expand Down
16 changes: 16 additions & 0 deletions interpreter/cling/lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ namespace {
llvm::SmallVectorImpl<char>& Buf,
AdditionalArgList& Args,
bool Verbose) {
// ALICE: let's see if the path is available as a predefined env variable
// to save repeated system calls when ROOT is initialized for each process
// in a many process system
auto PrefCppSystemIncl = getenv("ROOT_CPPSYSINCL");
if (PrefCppSystemIncl != nullptr) {
llvm::StringRef PathsString(PrefCppSystemIncl);
llvm::SmallVector<StringRef, 10> Paths;
PathsString.split(Paths, ":");
for (auto& P : Paths) {
P = P.trim();
Args.addArgument("-cxx-isystem", P.str());
}
return;
}

// execute default dynamic search
std::string CppInclQuery("LC_ALL=C ");
CppInclQuery.append(Compiler);

Expand Down
13 changes: 13 additions & 0 deletions interpreter/cling/lib/Utils/PlatformPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ bool GetSystemLibraryPaths(llvm::SmallVectorImpl<std::string>& Paths) {
Paths.push_back("/lib64/");
#endif
#else
// see if the result if this query is cached/provided in env variable
// power-user mode to avoid sys-calls and spawning processes
auto ldsyspath = getenv("ROOT_LDSYSPATH");
if (ldsyspath != nullptr) {
std::string SysPath(ldsyspath);
llvm::SmallVector<llvm::StringRef, 10> CurPaths;
SplitPaths(SysPath, CurPaths);
for (const auto& Path : CurPaths) {
Paths.push_back(Path.str());
}
return true;
}

llvm::SmallString<1024> Buf;
platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true);
const llvm::StringRef Result = Buf.str();
Expand Down

0 comments on commit 492a133

Please sign in to comment.