[PATCH] D13621: [ELF2] Sort PPC64 special sections
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 10 11:00:31 PDT 2015
ruiu added inline comments.
================
Comment at: ELF/Writer.cpp:356-382
@@ -343,3 +355,29 @@
// nobits sections.
- return A->getType() != SHT_NOBITS && B->getType() == SHT_NOBITS;
+ if (A->getType() != SHT_NOBITS && B->getType() == SHT_NOBITS)
+ return true;
+
+ // Check for the special ordering of special PPC64 section names.
+ auto PPC64NA =
+ std::find(PPC64SpecialNames, PPC64SpecialNamesEnd, A->getName());
+ auto PPC64NB =
+ std::find(PPC64SpecialNames, PPC64SpecialNamesEnd, B->getName());
+ // First, enforce the relative order in the PPC64SpecialNamesEnd array.
+ if (PPC64NA != PPC64SpecialNamesEnd &&
+ PPC64NB != PPC64SpecialNamesEnd &&
+ PPC64NA < PPC64NB)
+ return true;
+ // Second, any of the special PPC64 sections should come after other
+ // sections of the same type.
+ else if (PPC64NB != PPC64SpecialNames && /* not .got */
+ PPC64NB != PPC64SpecialNamesEnd &&
+ PPC64NA == PPC64SpecialNamesEnd)
+ return true;
+
+ // Conversely, the special .tocbss section should be first among all
+ // SHT_NOBITS sections. This will put it next to the loaded special
+ // PPC64 sections (and, thus, within reach of the TOC base pointer).
+ if (A->getName() == ".tocbss")
+ return true;
+
+ return false;
}
----------------
You can simplify this by defining a function, say getPPCRank(StringRef), which returns an integer value according to this table.
0 .tocbss
1 any other name
2 .toc
3 .branch_lt
4 .toc
5 .toc1
6 .opd
Then you can use that function in this function like this
return getPPCRank(A) < getPPCRank(B);
http://reviews.llvm.org/D13621
More information about the llvm-commits
mailing list