[lld] r267044 - ELF: Change the return type of getSectionOrder.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 13:30:00 PDT 2016
Author: ruiu
Date: Thu Apr 21 15:30:00 2016
New Revision: 267044
URL: http://llvm.org/viewvc/llvm-project?rev=267044&view=rev
Log:
ELF: Change the return type of getSectionOrder.
Also changed the function name and added comments.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=267044&r1=267043&r2=267044&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Apr 21 15:30:00 2016
@@ -204,7 +204,7 @@ void LinkerScript<ELFT>::assignAddresses
// https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections.
for (OutputSectionBase<ELFT> *Sec : Sections) {
StringRef Name = Sec->getName();
- if (getSectionOrder(Name) == (uint32_t)-1)
+ if (getSectionIndex(Name) == INT_MAX)
Opt.Commands.push_back({SectionKind, {}, Name});
}
@@ -248,23 +248,27 @@ ArrayRef<uint8_t> LinkerScript<ELFT>::ge
return I->second;
}
+// Returns the index of the given section name in linker script
+// SECTIONS commands. Sections are laid out as the same order as they
+// were in the script. If a given name did not appear in the script,
+// it returns INT_MAX, so that it will be laid out at end of file.
template <class ELFT>
-uint32_t LinkerScript<ELFT>::getSectionOrder(StringRef Name) {
+int LinkerScript<ELFT>::getSectionIndex(StringRef Name) {
auto Begin = Opt.Commands.begin();
auto End = Opt.Commands.end();
auto I = std::find_if(Begin, End, [&](SectionsCommand &N) {
return N.Kind == SectionKind && N.SectionName == Name;
});
- return I == End ? (uint32_t)-1 : (I - Begin);
+ return I == End ? INT_MAX : (I - Begin);
}
// A compartor to sort output sections. Returns -1 or 1 if
// A or B are mentioned in linker script. Otherwise, returns 0.
template <class ELFT>
int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
- uint32_t I = getSectionOrder(A);
- uint32_t J = getSectionOrder(B);
- if (I == (uint32_t)-1 && J == (uint32_t)-1)
+ int I = getSectionIndex(A);
+ int J = getSectionIndex(B);
+ if (I == INT_MAX && J == INT_MAX)
return 0;
return I < J ? -1 : 1;
}
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=267044&r1=267043&r2=267044&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Apr 21 15:30:00 2016
@@ -85,7 +85,7 @@ public:
int compareSections(StringRef A, StringRef B);
private:
- uint32_t getSectionOrder(StringRef Name);
+ int getSectionIndex(StringRef Name);
SectionRule *find(InputSectionBase<ELFT> *S);
ScriptConfiguration &Opt = *ScriptConfig;
More information about the llvm-commits
mailing list