diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 7d01b7f33decad..e4d3e1d50b0f3e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2120,11 +2120,10 @@ static void redirectSymbols(ArrayRef wrapped) { return; // Update pointers in input files. - parallelForEach(objectFiles, [&](InputFile *file) { - MutableArrayRef syms = file->getMutableSymbols(); - for (size_t i = 0, e = syms.size(); i != e; ++i) - if (Symbol *s = map.lookup(syms[i])) - syms[i] = s; + parallelForEach(objectFiles, [&](ELFFileBase *file) { + for (Symbol *&sym : file->getMutableGlobalSymbols()) + if (Symbol *s = map.lookup(sym)) + sym = s; }); // Update pointers in the symbol table. diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index a031ef94c14da8..6111df5218407e 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -91,9 +91,7 @@ class InputFile { // Returns object file symbols. It is a runtime error to call this // function on files of other types. - ArrayRef getSymbols() { return getMutableSymbols(); } - - MutableArrayRef getMutableSymbols() { + ArrayRef getSymbols() const { assert(fileKind == BinaryKind || fileKind == ObjKind || fileKind == BitcodeKind); return symbols; @@ -186,6 +184,10 @@ class ELFFileBase : public InputFile { ArrayRef getGlobalSymbols() { return llvm::makeArrayRef(symbols).slice(firstGlobal); } + MutableArrayRef getMutableGlobalSymbols() { + return llvm::makeMutableArrayRef(symbols.data(), symbols.size()) + .slice(firstGlobal); + } template typename ELFT::SymRange getELFSyms() const { return typename ELFT::SymRange(