[PATCH] D18499: [ELF] - Implemented prototype of location counter support.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 02:17:01 PDT 2016


grimar added inline comments.

================
Comment at: ELF/LinkerScript.cpp:109
@@ +108,3 @@
+  uintX_t VA = 0;
+  auto VisitLocations = [&](std::vector<LocationNode> &Loc) {
+    for (LocationNode &Node : Loc) {
----------------
ruiu wrote:
> Does this have to be a lambda?
Please see answer in below comment.

================
Comment at: ELF/LinkerScript.cpp:125
@@ +124,3 @@
+      OutputSectionBase<ELFT> *Sec = *I;
+      S.erase(I);
+
----------------
ruiu wrote:
> Why do you have to remove the element here?
I need to visit all output sections to assign addresses for each.
Script can mention only some of them.
There were 2 choices I saw:

1) Make this lambda and do 2 iterations. First iteration visits everything that was directly mentioned in script. During that it removes the sections if found from global list. After that we will have all unvisited sections in this global list. Then second iteration visits them all.
That gives 2 iterations, but complexity is O(n) in total.

2) In this variant it is possible to insert all sections that were not mentioned in script to Locations list at the begining of method and avoid using lambda. That would be one loop. Problem here that is that if we have OutputSectionBase list and have Locations lists then how to find those sections for which LocationNode was not created to vizit ?
That would be something like (pseudocode):

```
for (OutputSectionBase<ELFT> *Sec : S) {
  if (S NOT IN Locations) {
    Locations.push_back(create location for S);
  }
}
```

That is O(N^2) part of code that can be inserted at the begining of this method, that can help to get rid of labmda and do all in one iteration.


http://reviews.llvm.org/D18499





More information about the llvm-commits mailing list