summaryrefslogtreecommitdiff
path: root/llvm/lib/Debuginfod
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Debuginfod')
-rw-r--r--llvm/lib/Debuginfod/Debuginfod.cpp37
-rw-r--r--llvm/lib/Debuginfod/HTTPClient.cpp2
-rw-r--r--llvm/lib/Debuginfod/HTTPServer.cpp2
3 files changed, 33 insertions, 8 deletions
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 394f2b29aee6..9df30ab55cba 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -41,13 +41,22 @@
#include "llvm/Support/xxhash.h"
#include <atomic>
+#include <optional>
#include <thread>
namespace llvm {
using llvm::object::BuildIDRef;
-static std::string uniqueKey(llvm::StringRef S) { return utostr(xxHash64(S)); }
+namespace {
+std::optional<SmallVector<StringRef>> DebuginfodUrls;
+// Many Readers/Single Writer lock protecting the global debuginfod URL list.
+llvm::sys::RWMutex UrlsMutex;
+} // namespace
+
+static std::string uniqueKey(llvm::StringRef S) {
+ return utostr(xxh3_64bits(S));
+}
// Returns a binary BuildID as a normalized hex string.
// Uses lowercase for compatibility with common debuginfod servers.
@@ -60,13 +69,27 @@ bool canUseDebuginfod() {
}
SmallVector<StringRef> getDefaultDebuginfodUrls() {
- const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS");
- if (DebuginfodUrlsEnv == nullptr)
- return SmallVector<StringRef>();
+ std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex);
+ if (!DebuginfodUrls) {
+ // Only read from the environment variable if the user hasn't already
+ // set the value
+ ReadGuard.unlock();
+ std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
+ DebuginfodUrls = SmallVector<StringRef>();
+ if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) {
+ StringRef(DebuginfodUrlsEnv)
+ .split(DebuginfodUrls.value(), " ", -1, false);
+ }
+ WriteGuard.unlock();
+ ReadGuard.lock();
+ }
+ return DebuginfodUrls.value();
+}
- SmallVector<StringRef> DebuginfodUrls;
- StringRef(DebuginfodUrlsEnv).split(DebuginfodUrls, " ");
- return DebuginfodUrls;
+// Set the default debuginfod URL list, override the environment variable
+void setDefaultDebuginfodUrls(const SmallVector<StringRef> &URLs) {
+ std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
+ DebuginfodUrls = URLs;
}
/// Finds a default local file caching directory for the debuginfod client,
diff --git a/llvm/lib/Debuginfod/HTTPClient.cpp b/llvm/lib/Debuginfod/HTTPClient.cpp
index f9201e4f9626..4cca250746a5 100644
--- a/llvm/lib/Debuginfod/HTTPClient.cpp
+++ b/llvm/lib/Debuginfod/HTTPClient.cpp
@@ -97,6 +97,8 @@ HTTPClient::HTTPClient() {
assert(Curl && "Curl could not be initialized");
// Set the callback hooks.
curl_easy_setopt(Curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);
+ // Detect supported compressed encodings and accept all.
+ curl_easy_setopt(Curl, CURLOPT_ACCEPT_ENCODING, "");
}
HTTPClient::~HTTPClient() { curl_easy_cleanup(Curl); }
diff --git a/llvm/lib/Debuginfod/HTTPServer.cpp b/llvm/lib/Debuginfod/HTTPServer.cpp
index a5e992254ead..1264353ce4b3 100644
--- a/llvm/lib/Debuginfod/HTTPServer.cpp
+++ b/llvm/lib/Debuginfod/HTTPServer.cpp
@@ -51,7 +51,7 @@ bool llvm::streamFile(HTTPServerRequest &Request, StringRef FilePath) {
Request.setResponse({404u, "text/plain", "Could not memory-map file.\n"});
return false;
}
- // Lambdas are copied on conversion to to std::function, preventing use of
+ // Lambdas are copied on conversion to std::function, preventing use of
// smart pointers.
MemoryBuffer *MB = MBOrErr->release();
Request.setResponse({200u, "application/octet-stream", MB->getBufferSize(),