1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 18:40:59 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-23 00:34:46 +09:00
parent 3621497407
commit c81ab20e97
2 changed files with 34 additions and 0 deletions

View File

@ -73,6 +73,12 @@ void ObjectFile::initialize_sections() {
case SHT_NULL:
break;
default: {
if ((shdr.sh_flags & SHF_STRINGS) && (shdr.sh_flags & SHF_ALLOC) &&
!(shdr.sh_flags & SHF_WRITE) && shdr.sh_entsize == 1) {
read_string_pieces(shdr);
break;
}
StringRef name = CHECK(obj.getSectionName(shdr, section_strtab), this);
this->sections[i] = new InputSection(this, &shdr, name);
break;
@ -111,6 +117,24 @@ void ObjectFile::initialize_symbols() {
}
}
void ObjectFile::read_string_pieces(const ELF64LE::Shdr &shdr) {
static ConcurrentMap<StringPiece> map;
ArrayRef<uint8_t> arr = CHECK(obj.getSectionContents(shdr), this);
StringRef data((const char *)&arr[0], arr.size());
while (!data.empty()) {
size_t end = data.find('\0');
if (end == StringRef::npos)
error(toString(this) + ": string is not null terminated");
StringRef substr = data.substr(0, end + 1);
StringPiece *piece = map.insert(substr, StringPiece(substr));
merged_strings.push_back(piece);
data = data.substr(end + 1);
}
}
void ObjectFile::parse() {
num_files++;

10
mold.h
View File

@ -349,6 +349,14 @@ extern StringTableSection *shstrtab;
// input_files.cc
//
class StringPiece {
public:
StringPiece(StringRef data) : data(data) {}
StringPiece(const StringPiece &other) : data(other.data) {}
StringRef data;
std::atomic_flag flag = ATOMIC_FLAG_INIT;
};
class ObjectFile {
public:
ObjectFile(MemoryBufferRef mb, StringRef archive_name);
@ -369,10 +377,12 @@ public:
private:
void initialize_sections();
void initialize_symbols();
void read_string_pieces(const ELF64LE::Shdr &shdr);
MemoryBufferRef mb;
std::vector<Symbol *> symbols;
std::vector<std::pair<bool *, ArrayRef<ELF64LE::Word>>> comdat_groups;
std::vector<StringPiece *> merged_strings;
ArrayRef<ELF64LE::Shdr> elf_sections;
ArrayRef<ELF64LE::Sym> elf_syms;