aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/lib/Object/BuildID.cpp
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
committervitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
commit6ffe9e53658409f212834330e13564e4952558f6 (patch)
tree85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/llvm16/lib/Object/BuildID.cpp
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/llvm16/lib/Object/BuildID.cpp')
-rw-r--r--contrib/libs/llvm16/lib/Object/BuildID.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/contrib/libs/llvm16/lib/Object/BuildID.cpp b/contrib/libs/llvm16/lib/Object/BuildID.cpp
new file mode 100644
index 0000000000..795c22e769
--- /dev/null
+++ b/contrib/libs/llvm16/lib/Object/BuildID.cpp
@@ -0,0 +1,93 @@
+//===- llvm/Object/BuildID.cpp - Build ID ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file defines a library for handling Build IDs and using them to find
+/// debug info.
+///
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/BuildID.h"
+
+#include "llvm/Object/ELFObjectFile.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+namespace llvm {
+namespace object {
+
+namespace {
+
+template <typename ELFT>
+std::optional<BuildIDRef> getBuildID(const ELFFile<ELFT> &Obj) {
+ auto PhdrsOrErr = Obj.program_headers();
+ if (!PhdrsOrErr) {
+ consumeError(PhdrsOrErr.takeError());
+ return {};
+ }
+ for (const auto &P : *PhdrsOrErr) {
+ if (P.p_type != ELF::PT_NOTE)
+ continue;
+ Error Err = Error::success();
+ for (auto N : Obj.notes(P, Err))
+ if (N.getType() == ELF::NT_GNU_BUILD_ID &&
+ N.getName() == ELF::ELF_NOTE_GNU)
+ return N.getDesc();
+ consumeError(std::move(Err));
+ }
+ return {};
+}
+
+} // namespace
+
+std::optional<BuildIDRef> getBuildID(const ObjectFile *Obj) {
+ if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(Obj))
+ return getBuildID(O->getELFFile());
+ if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(Obj))
+ return getBuildID(O->getELFFile());
+ if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(Obj))
+ return getBuildID(O->getELFFile());
+ if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(Obj))
+ return getBuildID(O->getELFFile());
+ return std::nullopt;
+}
+
+std::optional<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
+ auto GetDebugPath = [&](StringRef Directory) {
+ SmallString<128> Path{Directory};
+ sys::path::append(Path, ".build-id",
+ llvm::toHex(BuildID[0], /*LowerCase=*/true),
+ llvm::toHex(BuildID.slice(1), /*LowerCase=*/true));
+ Path += ".debug";
+ return Path;
+ };
+ if (DebugFileDirectories.empty()) {
+ SmallString<128> Path = GetDebugPath(
+#if defined(__NetBSD__)
+ // Try /usr/libdata/debug/.build-id/../...
+ "/usr/libdata/debug"
+#else
+ // Try /usr/lib/debug/.build-id/../...
+ "/usr/lib/debug"
+#endif
+ );
+ if (llvm::sys::fs::exists(Path))
+ return std::string(Path);
+ } else {
+ for (const auto &Directory : DebugFileDirectories) {
+ // Try <debug-file-directory>/.build-id/../...
+ SmallString<128> Path = GetDebugPath(Directory);
+ if (llvm::sys::fs::exists(Path))
+ return std::string(Path);
+ }
+ }
+ return std::nullopt;
+}
+
+} // namespace object
+} // namespace llvm