mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-29 13:10:48 +00:00
get Build ID via Section headers first
This commit is contained in:
parent
121fc6b304
commit
e27ce34cf2
@ -119,6 +119,24 @@ std::optional<Elf::Section> Elf::findSectionByName(const char * name) const
|
||||
|
||||
String Elf::getBuildID() const
|
||||
{
|
||||
/// Section headers are the first choice for a not loaded file
|
||||
if (String build_id; iterateSections([&build_id](const Section & section, size_t)
|
||||
{
|
||||
if (section.header.sh_type == SHT_NOTE)
|
||||
{
|
||||
build_id = Elf::getBuildID(section.begin(), section.size());
|
||||
if (!build_id.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
return build_id;
|
||||
}
|
||||
|
||||
/// fallback to PHDR
|
||||
for (size_t idx = 0; idx < header->e_phnum; ++idx)
|
||||
{
|
||||
const ElfPhdr & phdr = program_headers[idx];
|
||||
@ -126,6 +144,7 @@ String Elf::getBuildID() const
|
||||
if (phdr.p_type == PT_NOTE)
|
||||
return getBuildID(mapped + phdr.p_offset, phdr.p_filesz);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,8 @@ public:
|
||||
const char * end() const { return mapped + elf_size; }
|
||||
size_t size() const { return elf_size; }
|
||||
|
||||
/// Obtain build id from PT_NOTES section of program headers. Return empty string if does not exist.
|
||||
/// Obtain build id from SHT_NOTE of section headers (fallback to PT_NOTES section of program headers).
|
||||
/// Return empty string if does not exist.
|
||||
/// The string is returned in binary. Note that "readelf -n ./clickhouse-server" prints it in hex.
|
||||
String getBuildID() const;
|
||||
static String getBuildID(const char * nhdr_pos, size_t size);
|
||||
|
Loading…
Reference in New Issue
Block a user