From c3e2a4b006b50a048aefb75ece29e589f6727fcc Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 21 Apr 2016 20:30:00 +0000 Subject: [PATCH] ELF: Change the return type of getSectionOrder. Also changed the function name and added comments. llvm-svn: 267044 --- lld/ELF/LinkerScript.cpp | 16 ++++++++++------ lld/ELF/LinkerScript.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 966acf3eb6f4..d16559f1a10a 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -204,7 +204,7 @@ void LinkerScript::assignAddresses( // https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections. for (OutputSectionBase *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 LinkerScript::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 -uint32_t LinkerScript::getSectionOrder(StringRef Name) { +int LinkerScript::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 int LinkerScript::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; } diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index d5195bc4a95f..d076f357b7cb 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -85,7 +85,7 @@ public: int compareSections(StringRef A, StringRef B); private: - uint32_t getSectionOrder(StringRef Name); + int getSectionIndex(StringRef Name); SectionRule *find(InputSectionBase *S); ScriptConfiguration &Opt = *ScriptConfig;