From 7fbad02cd4c753ed513551c6050df438661d9a9f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 10 Oct 2020 12:18:11 +0900 Subject: [PATCH] temporary --- chibild.h | 7 ++++--- input_files.cc | 25 +++++++++++++++++-------- symtab.cc | 14 +++++++------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/chibild.h b/chibild.h index 7b0130e4..3ce14792 100644 --- a/chibild.h +++ b/chibild.h @@ -96,11 +96,11 @@ struct tbb_hash_compare { class SymbolTable { public: - void add(StringRef key, StringRef val); - StringRef get(StringRef key); + void add(StringRef key, Symbol sym); + Symbol *get(StringRef key); private: - typedef tbb::concurrent_hash_map MapType; + typedef tbb::concurrent_hash_map MapType; MapType map; }; @@ -133,6 +133,7 @@ private: std::vector sections; std::vector symbols; std::vector symbol_instances; + int firstGlobal; bool is_alive = false; }; diff --git a/input_files.cc b/input_files.cc index 821b0898..ac51f4c1 100644 --- a/input_files.cc +++ b/input_files.cc @@ -34,28 +34,37 @@ void ObjectFile::parse() { const ELF64LE::Shdr *symtab_sec = findSection(sections, is_dso ? SHT_DYNSYM : SHT_SYMTAB); - int firstGlobal = symtab_sec->sh_info; + firstGlobal = symtab_sec->sh_info; ArrayRef elf_syms = CHECK(obj.symbols(symtab_sec), this); StringRef string_table = CHECK(obj.getStringTableForSymtab(*symtab_sec, sections), this); symbol_instances.reserve(elf_syms.size()); + symbols.reserve(elf_syms.size()); + for (int i = 0; i < elf_syms.size(); i++) { StringRef name; if (firstGlobal <= i) name = CHECK(elf_syms[i].getName(string_table), this); symbol_instances.push_back({name, this}); } - - for (const ELF64LE::Sym &sym : elf_syms.slice(firstGlobal)) { - StringRef name = CHECK(sym.getName(string_table), this); - symbol_table.add(name, name); - llvm::errs() << symbol_table.get(name) << "\n"; - } } -void ObjectFile::register_defined_symbols() {} +void ObjectFile::register_defined_symbols() { + for (int i = 0; i < symbol_instances.size(); i++) { + Symbol &sym = symbol_instances[i]; + + if (i < firstGlobal) { + symbols.push_back(&sym); + continue; + } + + symbol_table.add(sym.name, sym); + llvm::errs() << symbol_table.get(sym.name).name << "\n"; + symbols.push_back(&sym); + } +} StringRef ObjectFile::getFilename() { return mb.getBufferIdentifier(); diff --git a/symtab.cc b/symtab.cc index 286ae5b7..8beea9d6 100644 --- a/symtab.cc +++ b/symtab.cc @@ -1,15 +1,15 @@ #include "chibild.h" -void SymbolTable::add(StringRef key, StringRef val) { +void SymbolTable::add(StringRef name, Symbol sym) { MapType::accessor acc; - map.insert(acc, key); - acc->second = val; + map.insert(acc, name); + acc->second = sym; acc.release(); } -StringRef SymbolTable::get(StringRef key) { +Symbol *SymbolTable::get(StringRef name) { MapType::accessor acc; - if (map.find(acc, key)) - return acc->second; - return ""; + if (map.find(acc, name)) + return &acc->second; + return nullptr; }