[PATCH] D150220: [lld]: Fix RISC-V relaxation bug

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 08:08:37 PDT 2023


reames added inline comments.


================
Comment at: lld/ELF/Arch/RISCV.cpp:506
   SmallVector<SymbolAnchor, 0> anchors;
+  llvm::DenseMap<Symbol *, int> symMap;
   // For relocations[i], the actual offset is r_offset - (i ? relocDeltas[i-1] :
----------------
It looks like you're only using existance in the map, so this can be a DenseSet<Symbol *>


================
Comment at: lld/ELF/Arch/RISCV.cpp:532
   // sections.
   for (InputFile *file : ctx.objectFiles)
     for (Symbol *sym : file->getSymbols()) {
----------------
It looks like symMap is only used in the scope of this loop, so you can declare it locally here.


================
Comment at: lld/ELF/Arch/RISCV.cpp:539
         if (sec->flags & SHF_EXECINSTR && sec->relaxAux) {
-          // If sec is discarded, relaxAux will be nullptr.
-          sec->relaxAux->anchors.push_back({d->value, d, false});
-          sec->relaxAux->anchors.push_back({d->value + d->size, d, true});
+          bool found =
+              sec->relaxAux->symMap.find(sym) != sec->relaxAux->symMap.end();
----------------
I suspect we should really be checking for some property of the symbol here, but am not sufficiently knowledgeable of ELF minutia to know which one.  Maybe @maskray or @jrtc27 might have a suggestion here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150220/new/

https://reviews.llvm.org/D150220



More information about the llvm-commits mailing list