[PATCH] D35832: [ELF] - Store PhdrEntry values by pointers instead of storing by value.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 03:14:42 PDT 2017


grimar added a comment.

In https://reviews.llvm.org/D35832#820468, @ruiu wrote:

>   I looked at your two other patches, but I cannot find why they need this change.


For example in https://reviews.llvm.org/D35680 I am storing pointer to PT_LOAD segment instead of pointer to output section.
When we have vector of PhdrEntry (by value) it is hard to work with pointers on elements, because resize/remove operations
applied to vector may/will break the pointer value. If we have vector of pointers instead, it solves this problem easily.



================
Comment at: ELF/LinkerScript.cpp:802-805
   auto FirstPTLoad = llvm::find_if(
-      Phdrs, [](const PhdrEntry &E) { return E.p_type == PT_LOAD; });
+      Phdrs, [](const PhdrEntry *E) { return E->p_type == PT_LOAD; });
   if (FirstPTLoad == Phdrs.end())
     return;
----------------
ruiu wrote:
> FirstPTLoad is not a type that you can handle easily as it needs to dereference twice. You can do this.
> 
>   auto It = llvm::find_if(...);
>   if (It == Phdrs.end())
>     return;
>   PhdrEntry *FirstPTLoad = *It;
Yes, this looks better.


https://reviews.llvm.org/D35832





More information about the llvm-commits mailing list