1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-05 09:07:10 +03:00
mold/mold.h

592 lines
13 KiB
C
Raw Normal View History

2020-10-04 12:00:33 +03:00
#pragma once
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
2020-10-10 06:47:12 +03:00
#include "llvm/Object/Archive.h"
2020-10-09 14:47:45 +03:00
#include "llvm/Object/ELF.h"
2020-10-04 12:00:33 +03:00
#include "llvm/Object/ELFTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
2020-10-10 10:49:02 +03:00
#include "llvm/Support/Timer.h"
2020-10-09 14:47:45 +03:00
#include "tbb/concurrent_hash_map.h"
2020-10-26 13:51:06 +03:00
#include "tbb/global_control.h"
2020-10-10 10:49:02 +03:00
#include "tbb/parallel_for_each.h"
2020-11-06 04:11:19 +03:00
#include "tbb/parallel_invoke.h"
2020-11-06 02:49:41 +03:00
#include "tbb/parallel_reduce.h"
2020-10-28 13:49:58 +03:00
#include "tbb/spin_mutex.h"
2020-10-24 12:58:21 +03:00
#include "tbb/task_group.h"
2020-10-04 12:00:33 +03:00
2020-10-19 17:37:29 +03:00
#include <algorithm>
2020-10-10 13:15:16 +03:00
#include <atomic>
2020-10-04 12:00:33 +03:00
#include <cstdint>
2020-10-21 05:55:03 +03:00
#include <mutex>
2020-10-04 12:00:33 +03:00
#include <string>
2020-11-03 14:45:45 +03:00
#define SECTOR_SIZE 512
#define PAGE_SIZE 4096
2020-11-05 02:36:10 +03:00
#define LIKELY(x) __builtin_expect((x), 1)
#define UNLIKELY(x) __builtin_expect((x), 0)
2020-11-03 14:45:45 +03:00
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
using llvm::ArrayRef;
using llvm::ErrorOr;
using llvm::Error;
using llvm::Expected;
using llvm::MemoryBufferRef;
using llvm::SmallVector;
using llvm::StringRef;
using llvm::Twine;
using llvm::object::ELF64LE;
using llvm::object::ELFFile;
class Symbol;
class InputSection;
class ObjectFile;
2020-11-04 08:03:01 +03:00
class OutputChunk;
2020-11-03 14:45:45 +03:00
class OutputSection;
2020-10-08 11:01:54 +03:00
2020-10-04 12:00:33 +03:00
struct Config {
StringRef output;
2020-10-28 14:49:43 +03:00
bool print_map = false;
2020-11-04 12:47:13 +03:00
bool is_static = false;
2020-10-04 12:00:33 +03:00
};
2020-11-06 15:17:35 +03:00
inline Config config;
2020-10-04 12:00:33 +03:00
[[noreturn]] inline void error(const Twine &msg) {
2020-10-27 09:10:34 +03:00
static std::mutex mu;
2020-10-28 13:51:49 +03:00
std::lock_guard lock(mu);
2020-10-27 09:10:34 +03:00
2020-10-04 12:00:33 +03:00
llvm::errs() << msg << "\n";
exit(1);
}
2020-10-09 14:47:45 +03:00
template <class T> T check(ErrorOr<T> e) {
if (auto ec = e.getError())
error(ec.message());
return std::move(*e);
}
template <class T> T check(Expected<T> e) {
if (!e)
error(llvm::toString(e.takeError()));
return std::move(*e);
}
template <class T>
T check2(ErrorOr<T> e, llvm::function_ref<std::string()> prefix) {
if (auto ec = e.getError())
error(prefix() + ": " + ec.message());
return std::move(*e);
}
template <class T>
T check2(Expected<T> e, llvm::function_ref<std::string()> prefix) {
if (!e)
error(prefix() + ": " + toString(e.takeError()));
return std::move(*e);
}
inline std::string toString(const Twine &s) { return s.str(); }
#define CHECK(E, S) check2((E), [&] { return toString(S); })
2020-10-19 15:32:57 +03:00
std::string toString(ObjectFile *);
2020-10-20 03:20:52 +03:00
template<typename T, typename Callable>
static void for_each(T &arr, Callable callback) {
2020-10-29 09:30:41 +03:00
#if 1
2020-10-20 03:20:52 +03:00
tbb::parallel_for_each(arr.begin(), arr.end(), callback);
2020-10-28 13:27:23 +03:00
#else
std::for_each(arr.begin(), arr.end(), callback);
#endif
2020-10-20 03:20:52 +03:00
}
2020-10-12 07:30:34 +03:00
//
2020-10-19 15:32:57 +03:00
// Interned string
2020-10-12 07:30:34 +03:00
//
2020-10-19 12:13:55 +03:00
namespace tbb {
template<>
struct tbb_hash_compare<StringRef> {
static size_t hash(const StringRef& k) {
return llvm::hash_value(k);
}
static bool equal(const StringRef& k1, const StringRef& k2) {
return k1 == k2;
}
};
}
2020-10-19 15:32:57 +03:00
template<typename ValueT>
class ConcurrentMap {
public:
typedef tbb::concurrent_hash_map<StringRef, ValueT> MapT;
ValueT *insert(StringRef key, const ValueT &val) {
2020-10-28 03:39:31 +03:00
typename MapT::const_accessor acc;
2020-10-19 15:32:57 +03:00
map.insert(acc, std::make_pair(key, val));
2020-10-28 03:39:31 +03:00
return const_cast<ValueT *>(&acc->second);
2020-10-19 15:32:57 +03:00
}
private:
MapT map;
};
//
// Symbol
//
2020-10-12 07:30:34 +03:00
class Symbol {
public:
2020-11-03 16:21:55 +03:00
Symbol(StringRef name, ObjectFile *file = nullptr)
2020-11-06 05:44:27 +03:00
: name(name), file(file), is_placeholder(false), is_dso(false),
is_weak(false), is_undef_weak(false), traced(false) {}
2020-11-03 15:51:40 +03:00
2020-11-03 16:21:55 +03:00
Symbol(const Symbol &other) : Symbol(other.name, other.file) {}
2020-10-12 07:30:34 +03:00
2020-10-25 08:42:44 +03:00
static Symbol *intern(StringRef name) {
static ConcurrentMap<Symbol> map;
return map.insert(name, Symbol(name));
}
2020-11-06 06:50:26 +03:00
inline u64 get_addr() const;
2020-10-18 14:19:57 +03:00
StringRef name;
ObjectFile *file = nullptr;
2020-10-26 16:07:51 +03:00
InputSection *input_section = nullptr;
2020-10-23 06:09:27 +03:00
2020-11-06 06:52:16 +03:00
u64 value = 0;
2020-11-04 08:41:40 +03:00
u32 got_offset = 0;
u32 gotplt_offset = 0;
u32 gottp_offset = 0;
u32 plt_offset = 0;
2020-11-06 06:42:03 +03:00
u32 relplt_offset = 0;
2020-11-04 08:41:40 +03:00
u32 shndx = 0;
2020-10-30 11:59:45 +03:00
2020-11-03 16:24:50 +03:00
tbb::spin_mutex mu;
2020-11-05 07:05:27 +03:00
u8 is_placeholder : 1;
2020-11-04 10:54:53 +03:00
u8 is_dso : 1;
2020-11-03 16:21:55 +03:00
u8 is_weak : 1;
u8 is_undef_weak : 1;
2020-11-05 02:31:32 +03:00
u8 traced : 1;
2020-11-03 15:51:40 +03:00
2020-11-06 05:44:27 +03:00
enum { NEEDS_GOT = 1, NEEDS_GOTTP = 2, NEEDS_PLT = 4 };
std::atomic_uint8_t flags = ATOMIC_VAR_INIT(0);
2020-10-29 16:32:55 +03:00
u8 visibility = 0;
2020-11-01 09:27:04 +03:00
u8 type = llvm::ELF::STT_NOTYPE;
2020-10-12 07:30:34 +03:00
};
2020-10-19 15:32:57 +03:00
inline std::string toString(Symbol sym) {
return (StringRef(sym.name) + "(" + toString(sym.file) + ")").str();
}
2020-10-18 13:00:39 +03:00
2020-10-12 07:30:34 +03:00
//
2020-11-06 02:49:41 +03:00
// input_sections.cc
2020-10-12 07:30:34 +03:00
//
2020-10-25 03:26:51 +03:00
class InputSection {
2020-10-08 11:01:54 +03:00
public:
2020-10-25 07:17:10 +03:00
InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name);
2020-10-23 03:21:40 +03:00
void copy_to(u8 *buf);
2020-11-06 06:01:52 +03:00
void scan_relocations();
2020-10-23 03:21:40 +03:00
2020-10-19 17:37:29 +03:00
ObjectFile *file;
2020-10-22 12:29:35 +03:00
OutputSection *output_section;
2020-10-20 04:32:32 +03:00
ArrayRef<ELF64LE::Rela> rels;
2020-10-25 07:17:10 +03:00
const ELF64LE::Shdr &shdr;
2020-10-25 03:26:51 +03:00
StringRef name;
u64 offset;
2020-10-08 11:01:54 +03:00
};
2020-10-19 17:37:29 +03:00
std::string toString(InputSection *isec);
inline u64 align_to(u64 val, u64 align) {
2020-10-19 17:37:29 +03:00
assert(__builtin_popcount(align) == 1);
return (val + align - 1) & ~(align - 1);
}
2020-10-12 08:17:34 +03:00
//
2020-10-20 09:33:40 +03:00
// output_chunks.cc
2020-10-12 08:17:34 +03:00
//
2020-10-15 12:30:06 +03:00
class OutputChunk {
2020-10-15 11:06:01 +03:00
public:
2020-10-25 08:17:05 +03:00
OutputChunk() { shdr.sh_addralign = 1; }
virtual void copy_to(u8 *buf) {}
2020-10-25 09:17:43 +03:00
2020-10-22 13:35:16 +03:00
StringRef name;
2020-10-29 09:30:41 +03:00
int shndx = 0;
2020-10-26 04:03:17 +03:00
bool starts_new_ptload = false;
2020-10-25 07:17:10 +03:00
ELF64LE::Shdr shdr = {};
2020-10-29 12:31:06 +03:00
std::vector<InputSection *> sections;
2020-10-12 08:17:34 +03:00
};
2020-10-16 10:38:03 +03:00
// ELF header
2020-10-15 12:30:06 +03:00
class OutputEhdr : public OutputChunk {
2020-10-15 11:06:01 +03:00
public:
2020-11-03 14:05:42 +03:00
OutputEhdr() {
shdr.sh_flags = llvm::ELF::SHF_ALLOC;
shdr.sh_size = sizeof(ELF64LE::Ehdr);
}
void copy_to(u8 *buf) override;
2020-10-15 11:06:01 +03:00
};
2020-10-16 10:38:03 +03:00
// Section header
2020-10-15 12:30:06 +03:00
class OutputShdr : public OutputChunk {
2020-10-15 11:06:01 +03:00
public:
2020-10-25 07:17:10 +03:00
OutputShdr() { shdr.sh_flags = llvm::ELF::SHF_ALLOC; }
2020-10-25 06:41:31 +03:00
void copy_to(u8 *buf) override {
2020-10-26 06:09:37 +03:00
auto *p = (ELF64LE::Shdr *)(buf + shdr.sh_offset);
2020-10-25 06:41:31 +03:00
for (ELF64LE::Shdr *ent : entries)
*p++ = *ent;
2020-10-16 10:38:03 +03:00
}
2020-11-03 14:11:18 +03:00
void set_entries(std::vector<ELF64LE::Shdr *> vec) {
shdr.sh_size = vec.size() * sizeof(ELF64LE::Shdr);
entries = std::move(vec);
2020-11-03 14:05:42 +03:00
}
2020-10-25 06:41:31 +03:00
std::vector<ELF64LE::Shdr *> entries;
2020-10-15 11:06:01 +03:00
};
2020-10-16 10:38:03 +03:00
// Program header
2020-10-15 12:30:06 +03:00
class OutputPhdr : public OutputChunk {
2020-10-15 11:06:01 +03:00
public:
2020-11-03 14:26:22 +03:00
struct Entry {
2020-10-25 04:47:57 +03:00
ELF64LE::Phdr phdr;
2020-10-25 06:30:30 +03:00
std::vector<OutputChunk *> members;
2020-10-25 04:47:57 +03:00
};
2020-11-03 14:26:22 +03:00
OutputPhdr() { shdr.sh_flags = llvm::ELF::SHF_ALLOC; }
void copy_to(u8 *buf) override;
2020-11-03 14:26:22 +03:00
void set_entries(std::vector<Entry> vec) {
shdr.sh_size = vec.size() * sizeof(ELF64LE::Phdr);
entries = std::move(vec);
}
std::vector<Entry> entries;
2020-10-15 11:06:01 +03:00
};
2020-10-16 10:38:03 +03:00
// Sections
2020-10-15 12:30:06 +03:00
class OutputSection : public OutputChunk {
public:
static OutputSection *get_instance(StringRef name, u64 flags, u32 type);
2020-10-22 10:35:17 +03:00
OutputSection(StringRef name, u64 flags, u32 type) {
2020-10-22 13:35:16 +03:00
this->name = name;
2020-10-25 07:17:10 +03:00
shdr.sh_flags = flags;
shdr.sh_type = type;
2020-10-28 08:06:35 +03:00
idx = instances.size();
instances.push_back(this);
2020-10-21 05:28:43 +03:00
}
void copy_to(u8 *buf) override {
2020-11-03 14:37:27 +03:00
if (shdr.sh_type != llvm::ELF::SHT_NOBITS)
for_each(sections, [&](InputSection *isec) { isec->copy_to(buf); });
2020-10-16 10:38:03 +03:00
}
2020-10-29 12:31:06 +03:00
bool empty() const {
if (!sections.empty())
for (InputSection *isec : sections)
if (isec->shdr.sh_size)
return false;
return true;
}
2020-10-26 07:34:15 +03:00
2020-11-06 15:17:35 +03:00
static inline std::vector<OutputSection *> instances;
2020-10-29 12:31:06 +03:00
u32 idx;
2020-10-15 12:30:06 +03:00
};
2020-10-22 13:35:16 +03:00
class InterpSection : public OutputChunk {
public:
InterpSection() {
name = ".interp";
2020-10-25 07:17:10 +03:00
shdr.sh_flags = llvm::ELF::SHF_ALLOC;
shdr.sh_type = llvm::ELF::SHT_PROGBITS;
2020-11-03 14:07:07 +03:00
shdr.sh_size = sizeof(path);
2020-10-22 13:35:16 +03:00
}
void copy_to(u8 *buf) override {
2020-10-26 06:09:37 +03:00
memcpy(buf + shdr.sh_offset, path, sizeof(path));
2020-10-22 13:35:16 +03:00
}
private:
static constexpr char path[] = "/lib64/ld-linux-x86-64.so.2";
};
2020-10-29 11:54:21 +03:00
class GotSection : public OutputChunk {
public:
2020-11-01 09:12:17 +03:00
GotSection(StringRef name) {
2020-11-01 11:55:17 +03:00
this->name = name;
2020-10-29 14:19:41 +03:00
shdr.sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE;
2020-10-29 11:54:21 +03:00
shdr.sh_type = llvm::ELF::SHT_PROGBITS;
2020-10-29 12:42:54 +03:00
shdr.sh_addralign = 8;
2020-10-29 11:54:21 +03:00
}
};
2020-11-01 11:46:08 +03:00
class PltSection : public OutputChunk {
public:
PltSection() {
this->name = ".plt";
shdr.sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR;
shdr.sh_type = llvm::ELF::SHT_PROGBITS;
shdr.sh_addralign = 8;
}
2020-11-04 14:11:32 +03:00
void write_entry(u8 *buf, u32 value) {
buf[0] = 0xff;
buf[1] = 0x25;
*(u32 *)(buf + 2) = value;
}
2020-11-01 11:46:08 +03:00
};
2020-11-01 10:22:47 +03:00
class RelPltSection : public OutputChunk {
2020-11-01 02:55:13 +03:00
public:
2020-11-01 10:22:47 +03:00
RelPltSection() {
this->name = ".rela.plt";
2020-11-01 02:55:13 +03:00
shdr.sh_flags = llvm::ELF::SHF_ALLOC;
shdr.sh_type = llvm::ELF::SHT_RELA;
2020-11-01 11:53:57 +03:00
shdr.sh_entsize = sizeof(ELF64LE::Rela);
2020-11-01 02:55:13 +03:00
shdr.sh_addralign = 8;
}
};
2020-10-27 11:53:08 +03:00
class ShstrtabSection : public OutputChunk {
2020-10-22 13:36:57 +03:00
public:
2020-10-27 11:53:08 +03:00
ShstrtabSection() {
this->name = ".shstrtab";
2020-10-22 14:06:45 +03:00
contents = '\0';
2020-10-25 07:17:10 +03:00
shdr.sh_flags = 0;
shdr.sh_type = llvm::ELF::SHT_STRTAB;
2020-11-03 13:59:05 +03:00
shdr.sh_size = 1;
2020-10-22 13:36:57 +03:00
}
u64 add_string(StringRef s) {
u64 ret = contents.size();
2020-10-22 14:06:45 +03:00
contents += s.str();
contents += '\0';
2020-11-03 13:59:05 +03:00
shdr.sh_size = contents.size();
2020-10-22 14:06:45 +03:00
return ret;
}
void copy_to(u8 *buf) override {
2020-10-26 06:09:37 +03:00
memcpy(buf + shdr.sh_offset, &contents[0], contents.size());
2020-10-22 14:06:45 +03:00
}
2020-10-22 13:36:57 +03:00
private:
2020-10-22 14:06:45 +03:00
std::string contents;
2020-10-22 13:36:57 +03:00
};
2020-10-27 12:59:56 +03:00
class SymtabSection : public OutputChunk {
public:
SymtabSection() {
this->name = ".symtab";
shdr.sh_flags = 0;
shdr.sh_type = llvm::ELF::SHT_SYMTAB;
shdr.sh_entsize = sizeof(ELF64LE::Sym);
shdr.sh_addralign = 8;
2020-11-04 01:14:49 +03:00
shdr.sh_size = sizeof(ELF64LE::Sym);
contents.push_back({});
2020-10-27 12:59:56 +03:00
}
private:
std::vector<ELF64LE::Sym> contents;
};
2020-10-27 11:53:08 +03:00
class StrtabSection : public OutputChunk {
public:
StrtabSection() {
this->name = ".strtab";
shdr.sh_flags = 0;
shdr.sh_type = llvm::ELF::SHT_STRTAB;
2020-11-03 14:03:05 +03:00
shdr.sh_size = 1;
2020-10-27 11:53:08 +03:00
}
};
2020-11-04 04:43:05 +03:00
bool is_c_identifier(StringRef name);
2020-10-17 07:24:48 +03:00
namespace out {
2020-11-06 15:17:35 +03:00
inline OutputEhdr *ehdr;
inline OutputShdr *shdr;
inline OutputPhdr *phdr;
inline InterpSection *interp;
inline GotSection *got;
inline GotSection *gotplt;
inline PltSection *plt;
inline RelPltSection *relplt;
inline ShstrtabSection *shstrtab;
inline SymtabSection *symtab;
inline StrtabSection *strtab;
inline u64 tls_end;
inline Symbol *__bss_start;
inline Symbol *__ehdr_start;
inline Symbol *__rela_iplt_start;
inline Symbol *__rela_iplt_end;
inline Symbol *__init_array_start;
inline Symbol *__init_array_end;
inline Symbol *__fini_array_start;
inline Symbol *__fini_array_end;
inline Symbol *__preinit_array_start;
inline Symbol *__preinit_array_end;
inline Symbol *end;
inline Symbol *_end;
inline Symbol *etext;
inline Symbol *_etext;
inline Symbol *edata;
inline Symbol *_edata;
2020-10-17 07:24:48 +03:00
}
2020-11-06 15:01:35 +03:00
inline u64 Symbol::get_addr() const {
2020-11-06 06:50:26 +03:00
if (input_section)
return input_section->output_section->shdr.sh_addr +
2020-11-06 06:52:16 +03:00
input_section->offset + value;
return value;
2020-11-06 06:50:26 +03:00
}
2020-10-12 07:30:34 +03:00
//
2020-11-03 04:54:10 +03:00
// object_file.cc
2020-10-12 07:30:34 +03:00
//
struct ComdatGroup {
ComdatGroup(ObjectFile *file, u32 i)
: file(file), section_idx(i) {}
ComdatGroup(const ComdatGroup &other)
2020-10-23 06:43:22 +03:00
: file(other.file.load()), section_idx(other.section_idx) {}
2020-10-28 13:51:49 +03:00
tbb::spin_mutex mu;
2020-10-23 06:43:22 +03:00
std::atomic<ObjectFile *> file;
u32 section_idx;
};
2020-10-22 14:01:10 +03:00
class ObjectFile {
2020-10-04 12:00:33 +03:00
public:
2020-10-14 12:42:54 +03:00
ObjectFile(MemoryBufferRef mb, StringRef archive_name);
2020-10-04 12:00:33 +03:00
2020-10-09 14:47:45 +03:00
void parse();
2020-11-05 06:20:16 +03:00
void resolve_symbols();
void mark_live_archive_members(tbb::parallel_do_feeder<ObjectFile *> &feeder);
2020-10-30 09:38:13 +03:00
void hanlde_undefined_weak_symbols();
2020-10-19 15:50:33 +03:00
void eliminate_duplicate_comdat_groups();
2020-10-27 06:50:25 +03:00
void convert_common_symbols();
2020-11-06 06:01:52 +03:00
void scan_relocations();
2020-10-27 14:58:28 +03:00
void compute_symtab();
2020-10-27 15:45:19 +03:00
2020-10-29 16:32:55 +03:00
void write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
void write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
2020-10-27 13:03:57 +03:00
2020-11-04 04:39:17 +03:00
static ObjectFile *create_internal_file(ArrayRef<OutputChunk *> output_chunks);
2020-11-03 13:33:46 +03:00
2020-10-13 14:35:35 +03:00
std::vector<InputSection *> sections;
2020-10-14 12:42:54 +03:00
StringRef archive_name;
2020-10-16 10:38:03 +03:00
ELFFile<ELF64LE> obj;
2020-10-29 06:24:54 +03:00
std::vector<Symbol *> symbols;
2020-11-01 06:41:09 +03:00
ArrayRef<ELF64LE::Sym> elf_syms;
u32 priority;
2020-10-29 10:48:17 +03:00
std::atomic_bool is_alive = ATOMIC_VAR_INIT(false);
2020-11-03 15:27:14 +03:00
bool is_dso;
2020-11-05 06:34:59 +03:00
const bool is_in_archive;
2020-11-01 07:54:56 +03:00
std::string name;
2020-10-09 17:26:26 +03:00
u64 local_symtab_size = 0;
u64 local_strtab_size = 0;
u64 global_symtab_size = 0;
u64 global_strtab_size = 0;
2020-10-27 14:58:28 +03:00
2020-11-06 06:04:40 +03:00
std::atomic_uint32_t num_plt = ATOMIC_VAR_INIT(0);
std::atomic_uint32_t num_got = ATOMIC_VAR_INIT(0);
std::atomic_uint32_t num_gotplt = ATOMIC_VAR_INIT(0);
std::atomic_uint32_t num_relplt = ATOMIC_VAR_INIT(0);
2020-11-06 06:32:38 +03:00
u32 got_offset = 0;
u32 gotplt_offset = 0;
u32 plt_offset = 0;
u32 relplt_offset = 0;
2020-10-09 14:47:45 +03:00
private:
2020-10-19 14:05:34 +03:00
void initialize_sections();
void initialize_symbols();
2020-11-05 07:16:33 +03:00
void maybe_override_symbol(const ELF64LE::Sym &esym, Symbol &sym);
void remove_comdat_members(u32 section_idx);
2020-11-03 10:01:14 +03:00
void write_symtab(u8 *buf, u64 symtab_off, u64 strtab_off, u32 start, u32 end);
2020-10-19 14:05:34 +03:00
2020-10-09 14:47:45 +03:00
MemoryBufferRef mb;
std::vector<std::pair<ComdatGroup *, u32>> comdat_groups;
2020-10-19 14:05:34 +03:00
2020-11-03 08:53:32 +03:00
std::vector<Symbol> local_symbols;
2020-10-26 08:52:55 +03:00
int first_global = 0;
2020-10-27 02:45:20 +03:00
bool has_common_symbol;
2020-10-26 08:52:55 +03:00
2020-10-19 14:05:34 +03:00
ArrayRef<ELF64LE::Shdr> elf_sections;
2020-10-26 15:44:08 +03:00
StringRef symbol_strtab;
2020-10-19 14:17:32 +03:00
const ELF64LE::Shdr *symtab_sec;
2020-10-04 12:00:33 +03:00
};
2020-11-03 11:26:42 +03:00
//
// perf.cc
//
class Counter {
2020-11-03 11:28:06 +03:00
public:
2020-11-03 11:42:41 +03:00
Counter(StringRef name, u32 value = 0) : name(name), value(value) {
2020-11-03 11:26:42 +03:00
static std::mutex mu;
std::lock_guard lock(mu);
instances.push_back(this);
}
void inc() {
if (enabled)
value++;
}
2020-11-03 11:36:43 +03:00
void inc(u32 delta) {
if (enabled)
value += delta;
}
void set(u32 value) {
this->value = value;
}
2020-11-03 11:28:06 +03:00
static void print();
2020-11-03 11:26:42 +03:00
2020-11-03 11:54:02 +03:00
static bool enabled;
2020-11-03 11:28:06 +03:00
private:
2020-11-03 11:26:42 +03:00
StringRef name;
std::atomic_uint32_t value;
static std::vector<Counter *> instances;
};
2020-10-29 06:24:54 +03:00
//
// mapfile.cc
//
2020-10-29 12:31:06 +03:00
void print_map(ArrayRef<ObjectFile *> files, ArrayRef<OutputChunk *> output_sections);