Skip to content

Commit

Permalink
Remove BitVector and use std::vector<bool>
Browse files Browse the repository at this point in the history
Even though std::vector<bool> is often critisized for being inconsistent
with other std::vector<T> where T != bool, it suffices for our purpose.
  • Loading branch information
rui314 committed Jan 8, 2025
1 parent a01fe17 commit 5d45430
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
17 changes: 0 additions & 17 deletions lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,6 @@ class Timer {
TimerRecord *record;
};

//
// Bit vector
//

class BitVector {
public:
BitVector() = default;
BitVector(u32 size) : vec((size + 7) / 8) {}

void resize(u32 size) { vec.resize((size + 7) / 8); }
bool get(u32 idx) const { return vec[idx / 8] & (1 << (idx % 8)); }
void set(u32 idx) { vec[idx / 8] |= 1 << (idx % 8); }

private:
std::vector<u8> vec;
};

//
// Utility functions
//
Expand Down
2 changes: 1 addition & 1 deletion src/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
if (ver != "@" && ver != "@@") {
if (ver.starts_with("@@"))
key = name;
has_symver.set(i - this->first_global);
has_symver[i - this->first_global] = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ class ObjectFile : public InputFile<E> {
std::vector<ElfShdr<E>> elf_sections2;
std::vector<CieRecord<E>> cies;
std::vector<FdeRecord<E>> fdes;
BitVector has_symver;
std::vector<bool> has_symver;
std::vector<ComdatGroupRef<E>> comdat_groups;
std::vector<InputSection<E> *> eh_frame_sections;
bool exclude_libs = false;
Expand Down
12 changes: 6 additions & 6 deletions src/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ void create_internal_file(Context<E> &ctx) {
add(get_symbol(ctx, ord.name));

obj->elf_syms = ctx.internal_esyms;
obj->has_symver.resize(ctx.internal_esyms.size() - 1);
}

template <typename E>
Expand Down Expand Up @@ -821,8 +820,6 @@ void add_synthetic_symbols(Context<E> &ctx) {
add(label);

obj.elf_syms = ctx.internal_esyms;
obj.has_symver.resize(ctx.internal_esyms.size() - 1);

obj.resolve_symbols(ctx);

// Make all synthetic symbols relative ones by associating them to
Expand Down Expand Up @@ -1375,6 +1372,9 @@ void claim_unresolved_symbols(Context<E> &ctx) {
Timer t(ctx, "claim_unresolved_symbols");

tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
if (file == ctx.internal_obj)
return;

for (i64 i = file->first_global; i < file->elf_syms.size(); i++) {
const ElfSym<E> &esym = file->elf_syms[i];
Symbol<E> &sym = *file->symbols[i];
Expand All @@ -1389,7 +1389,7 @@ void claim_unresolved_symbols(Context<E> &ctx) {

// If a symbol name is in the form of "foo@version", search for
// symbol "foo" and check if the symbol has version "version".
if (file->has_symver.get(i - file->first_global)) {
if (file->has_symver[i - file->first_global]) {
std::string_view str = file->symbol_strtab.data() + esym.st_name;
i64 pos = str.find('@');
assert(pos != str.npos);
Expand Down Expand Up @@ -1874,7 +1874,7 @@ void parse_symbol_version(Context<E> &ctx) {

for (i64 i = file->first_global; i < file->elf_syms.size(); i++) {
// Match VERSION part of symbol foo@VERSION with version definitions.
if (!file->has_symver.get(i - file->first_global))
if (!file->has_symver[i - file->first_global])
continue;

Symbol<E> *sym = file->symbols[i];
Expand Down Expand Up @@ -1907,7 +1907,7 @@ void parse_symbol_version(Context<E> &ctx) {
// defined, the default one takes precedence.
Symbol<E> *sym2 = get_symbol(ctx, sym->name());
if (sym2->file == file &&
!file->has_symver.get(sym2->sym_idx - file->first_global))
!file->has_symver[sym2->sym_idx - file->first_global])
if (sym2->ver_idx == ctx.default_version ||
(sym2->ver_idx & ~VERSYM_HIDDEN) == (sym->ver_idx & ~VERSYM_HIDDEN))
sym2->ver_idx = VER_NDX_LOCAL;
Expand Down

0 comments on commit 5d45430

Please sign in to comment.