[lld] [lld][COFF] Fix: Merge `.drectve` sections in ObjFile::readSections (PR #86380)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 01:55:16 PDT 2024


================
@@ -89,16 +89,16 @@ class InputFile {
   // An archive file name if this file is created from an archive.
   StringRef parentName;
 
-  // Returns .drectve section contents if exist.
-  StringRef getDirectives() { return directives; }
+  // Returns .drectve section(s) content if exist.
+  std::vector<StringRef> getDrectves() { return directives; }
 
   COFFLinkerContext &ctx;
 
 protected:
   InputFile(COFFLinkerContext &c, Kind k, MemoryBufferRef m, bool lazy = false)
       : mb(m), ctx(c), fileKind(k), lazy(lazy) {}
 
-  StringRef directives;
+  std::vector<StringRef> directives;
----------------
mstorsjo wrote:

What does this do for the memory usage of the linker? (A significant amount of effort has been spent on minimizing the memory usage of the linker.) If most input object files have 0 or 1 directive string, we don't want to allocate too much extra space here as a reserve. I'm not sure how good/bad `std::vector` is at this - but we do have `llvm::SmallVector<>` as well, where one can set the size of an inline allocation. Then we could use that with a default 1-element allocation, so it doesn't need to do any extra allocations as long as each object file has one individual string.

https://github.com/llvm/llvm-project/pull/86380


More information about the llvm-commits mailing list