Skip to content

Commit

Permalink
Fix data races found by ThreadSanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Apr 3, 2022
1 parent ceed69f commit e1e4e9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions elf/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ElfShdr<E> *InputFile<E>::find_section(i64 type) {
template <typename E>
void InputFile<E>::clear_symbols() {
for (Symbol<E> *sym : get_global_syms()) {
std::scoped_lock lock(sym->mu);
if (sym->file == this) {
sym->file = nullptr;
sym->shndx = 0;
Expand Down Expand Up @@ -1008,6 +1009,8 @@ void ObjectFile<E>::convert_common_symbols(Context<E> &ctx) {
continue;

Symbol<E> &sym = *this->symbols[i];
std::scoped_lock lock(sym.mu);

if (sym.file != this) {
if (ctx.arg.warn_common)
Warn(ctx) << *this << ": multiple common symbols: " << sym;
Expand Down
2 changes: 2 additions & 0 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,11 +1128,13 @@ void compute_import_export(Context<E> &ctx) {
continue;

if (sym->file != file && sym->file->is_dso) {
std::scoped_lock lock(sym->mu);
sym->is_imported = true;
continue;
}

if (sym->file == file) {
std::scoped_lock lock(sym->mu);
sym->is_exported = true;

if (ctx.arg.shared && sym->visibility != STV_PROTECTED &&
Expand Down

0 comments on commit e1e4e9f

Please sign in to comment.