ELF: Change the return type of getSectionOrder.

Also changed the function name and added comments.

llvm-svn: 267044
This commit is contained in:
Rui Ueyama 2016-04-21 20:30:00 +00:00
parent 5e55d17ba7
commit c3e2a4b006
2 changed files with 11 additions and 7 deletions

View File

@ -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>::getFiller(StringRef Name) {
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;
}

View File

@ -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;