[PATCH] D25325: [ELF] Change way we place non-scripted (orphan) sections

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 09:12:12 PDT 2016


evgeny777 added inline comments.


================
Comment at: ELF/Writer.cpp:772
+    //      In such case there are no sections which can share segment with section N.
+    for (auto I = OutputSections.begin(); I != NonScriptI; ++I) {
+      bool Greater = compareSectionsNonScript<ELFT>(*NonScriptI, *I);
----------------
rafael wrote:
> This is a bit hard to read.  Maybe you can write a lambda that given two candidates decides which one is  better for placing the orphan. That way this would be
> 
> std:: max_element(I, NonScriptI, [&] (OutputSectionBase<ELFT> *A, OutputSectionBase<ELFT> *B) {
> ...
> }
> 
> And if I understand correctly, the logic would be
> 
> * Prefer A/B if one can share a PT_LOAD.
> * Prefer A/B if the element compares less than one.
> * Otherwise prefer the last one.
> 
>  
> 
I don't think max_element makes sense here, because this code is about finding best insertion position, not any kind of maximum.
This newer code implements two passes on OutputSections: first pass is done on subset of sections which can share PT_LOAD with NonScriptI and second pass is done on all sections. Hope it's easier to understand now.


Repository:
  rL LLVM

https://reviews.llvm.org/D25325





More information about the llvm-commits mailing list