Merge pull request #6578 from yandex/disable-elf-on-macos

Disable ELF on Mac OS
This commit is contained in:
alexey-milovidov 2019-08-21 06:01:49 +03:00 committed by GitHub
commit 0e896fb341
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 31 deletions

View File

@ -1,3 +1,5 @@
#ifdef __ELF__
/*
* Copyright 2012-present Facebook, Inc.
*
@ -1031,3 +1033,5 @@ bool Dwarf::LineNumberVM::findAddress(uintptr_t target, Path & file, uint64_t &
}
}
#endif

View File

@ -1,5 +1,7 @@
#pragma once
#ifdef __ELF__
/*
* Copyright 2012-present Facebook, Inc.
*
@ -285,3 +287,5 @@ private:
};
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef __ELF__
#include <Common/Elf.h>
#include <Common/Exception.h>
@ -128,3 +130,5 @@ size_t Elf::Section::size() const
}
}
#endif

View File

@ -1,45 +1,16 @@
#pragma once
#ifdef __ELF__
#include <IO/MMapReadBufferFromFile.h>
#include <string>
#include <optional>
#include <functional>
#ifdef __APPLE__
#include <libelf/gelf.h>
typedef Elf64_Addr GElf_Addr;
typedef Elf64_Half GElf_Half;
typedef Elf64_Off GElf_Off;
typedef Elf64_Sword GElf_Sword;
typedef Elf64_Word GElf_Word;
typedef Elf64_Sxword GElf_Sxword;
typedef Elf64_Xword GElf_Xword;
typedef Elf64_Ehdr GElf_Ehdr;
typedef Elf64_Phdr GElf_Phdr;
typedef Elf64_Shdr GElf_Shdr;
typedef Elf64_Dyn GElf_Dyn;
typedef Elf64_Rel GElf_Rel;
typedef Elf64_Rela GElf_Rela;
typedef Elf64_Sym GElf_Sym;
#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */
#define __ELF_NATIVE_CLASS __WORDSIZE
#define ElfW(type) _ElfW(Elf, __ELF_NATIVE_CLASS, type)
#define _ElfW(e, w, t) _ElfW_1(e, w, _##t)
#define _ElfW_1(e, w, t) e##w##t
#else
#include <elf.h>
#include <link.h>
#endif
using ElfAddr = ElfW(Addr);
using ElfEhdr = ElfW(Ehdr);
@ -92,3 +63,5 @@ private:
};
}
#endif

View File

@ -250,6 +250,7 @@ static void toStringEveryLineImpl(const StackTrace::Frames & frames, size_t offs
if (size == 0)
return callback("<Empty trace>");
#ifdef __ELF__
const DB::SymbolIndex & symbol_index = DB::SymbolIndex::instance();
std::unordered_map<std::string, DB::Dwarf> dwarfs;
@ -290,6 +291,18 @@ static void toStringEveryLineImpl(const StackTrace::Frames & frames, size_t offs
callback(out.str());
out.str({});
}
#else
std::stringstream out;
for (size_t i = offset; i < size; ++i)
{
const void * addr = frames[i];
out << i << ". " << addr;
callback(out.str());
out.str({});
}
#endif
}
static std::string toStringImpl(const StackTrace::Frames & frames, size_t offset, size_t size)

View File

@ -1,3 +1,5 @@
#ifdef __ELF__
#include <Common/SymbolIndex.h>
#include <algorithm>
@ -316,3 +318,5 @@ const SymbolIndex::Object * SymbolIndex::findObject(const void * address) const
}
}
#endif

View File

@ -1,5 +1,7 @@
#pragma once
#ifdef __ELF__
#include <vector>
#include <string>
#include <ext/singleton.h>
@ -53,3 +55,5 @@ private:
};
}
#endif

View File

@ -16,6 +16,7 @@ using namespace DB;
int main(int argc, char ** argv)
{
#ifdef __ELF__
if (argc < 2)
{
std::cerr << "Usage: ./symbol_index address\n";
@ -53,6 +54,12 @@ int main(int argc, char ** argv)
std::cerr << "\n";
std::cerr << StackTrace().toString() << "\n";
#else
(void)argc;
(void)argv;
std::cerr << "This test does not make sense for non-ELF objects.\n";
#endif
return 0;
}

View File

@ -1,3 +1,5 @@
#ifdef __ELF__
#include <Common/Elf.h>
#include <Common/Dwarf.h>
#include <Common/SymbolIndex.h>
@ -149,3 +151,5 @@ void registerFunctionAddressToLine(FunctionFactory & factory)
}
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef __ELF__
#include <Common/SymbolIndex.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
@ -92,3 +94,5 @@ void registerFunctionAddressToSymbol(FunctionFactory & factory)
}
}
#endif