[PATCH] D46145: Use a buffer when allocating relocations

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 27 11:45:19 PDT 2018


grimar added a comment.

Few more ideas about that one.



================
Comment at: ELF/Writer.cpp:861
 template <class ELFT>
 void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) {
+  std::vector<Relocation> Buffer;
----------------
Less tricky way probably could be to pass `std::vector<Relocation>` Buffer to `Fn`, so it could populate it.
That would need to add this argument to few functions. Though also seem would remove argument from some of them,
for example `handleMipsTlsRelocation` uses ` InputSectionBase &C` to access to ` C.Relocations`. It could take the buffer instead
of the section.

And code would be something like next then:

```
  auto WithBuffer = [&](InputSectionBase &Sec) {
    Fn(Sec, Buffer);
    Sec.Relocations.insert(Sec.Relocations.end(), Buffer.begin(), Buffer.end());
    Buffer.clear();
  };
```


================
Comment at: ELF/Writer.cpp:866
+  // all sections we ensure that the final vector in each section has
+  // the exact size.
+  auto WithBuffer = [&](InputSectionBase &Sec) {
----------------
I would probably add that we do that to decrease total memory consumption.
Maybe "the exact **internal buffer** size" would make comment more understandable.


https://reviews.llvm.org/D46145





More information about the llvm-commits mailing list