[PATCH] D46145: Use a buffer when allocating relocations

Rafael Avila de Espindola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 27 13:45:41 PDT 2018


espindola added inline comments.


================
Comment at: ELF/Writer.cpp:861
 template <class ELFT>
 void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) {
+  std::vector<Relocation> Buffer;
----------------
grimar wrote:
> 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();
>   };
> ```
This would require passing a buffer to a lot of places. For example, RelocationBaseSection::addReloc would need it.

As written the code with swap is a bit more complicated, but it is completely local.


https://reviews.llvm.org/D46145





More information about the llvm-commits mailing list