Skip to content

Commit 82b01e0

Browse files
committed
[llvm-objcopy] Replace the size() helper with SectionTableRef::size
Summary: BTW, STLExtras.h provides llvm::size() which is similar to std::size() for random access iterators. However, if we prefer qualified llvm::size(), the member function .size() will be more convenient. Reviewers: jhenderson, jakehehrlich, rupprecht, grimar, alexshap, espindola Reviewed By: grimar Subscribers: emaste, arichardson, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60028 llvm-svn: 357347
1 parent cfdf09b commit 82b01e0

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

llvm/tools/llvm-objcopy/ELF/Object.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,6 @@ template <class ELFT> void ELFBuilder<ELFT>::build() {
12211221
" in elf header " + " is not a string table");
12221222
}
12231223

1224-
// A generic size function which computes sizes of any random access range.
1225-
template <class R> size_t size(R &&Range) {
1226-
return static_cast<size_t>(std::end(Range) - std::begin(Range));
1227-
}
1228-
12291224
Writer::~Writer() {}
12301225

12311226
Reader::~Reader() {}
@@ -1282,7 +1277,7 @@ template <class ELFT> void ELFWriter<ELFT>::writeEhdr() {
12821277
Ehdr.e_phentsize = (Ehdr.e_phnum != 0) ? sizeof(Elf_Phdr) : 0;
12831278
Ehdr.e_flags = Obj.Flags;
12841279
Ehdr.e_ehsize = sizeof(Elf_Ehdr);
1285-
if (WriteSectionHeaders && size(Obj.sections()) != 0) {
1280+
if (WriteSectionHeaders && Obj.sections().size() != 0) {
12861281
Ehdr.e_shentsize = sizeof(Elf_Shdr);
12871282
Ehdr.e_shoff = Obj.SHOffset;
12881283
// """
@@ -1291,7 +1286,7 @@ template <class ELFT> void ELFWriter<ELFT>::writeEhdr() {
12911286
// number of section header table entries is contained in the sh_size field
12921287
// of the section header at index 0.
12931288
// """
1294-
auto Shnum = size(Obj.sections()) + 1;
1289+
auto Shnum = Obj.sections().size() + 1;
12951290
if (Shnum >= SHN_LORESERVE)
12961291
Ehdr.e_shnum = 0;
12971292
else
@@ -1330,7 +1325,7 @@ template <class ELFT> void ELFWriter<ELFT>::writeShdrs() {
13301325
Shdr.sh_addr = 0;
13311326
Shdr.sh_offset = 0;
13321327
// See writeEhdr for why we do this.
1333-
uint64_t Shnum = size(Obj.sections()) + 1;
1328+
uint64_t Shnum = Obj.sections().size() + 1;
13341329
if (Shnum >= SHN_LORESERVE)
13351330
Shdr.sh_size = Shnum;
13361331
else
@@ -1564,7 +1559,7 @@ template <class ELFT> size_t ELFWriter<ELFT>::totalSize() const {
15641559
// We already have the section header offset so we can calculate the total
15651560
// size by just adding up the size of each section header.
15661561
auto NullSectionSize = WriteSectionHeaders ? sizeof(Elf_Shdr) : 0;
1567-
return Obj.SHOffset + size(Obj.sections()) * sizeof(Elf_Shdr) +
1562+
return Obj.SHOffset + Obj.sections().size() * sizeof(Elf_Shdr) +
15681563
NullSectionSize;
15691564
}
15701565

@@ -1595,7 +1590,7 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
15951590
// if we need large indexes or not. We can assign indexes first and check as
15961591
// we go to see if we will actully need large indexes.
15971592
bool NeedsLargeIndexes = false;
1598-
if (size(Obj.sections()) >= SHN_LORESERVE) {
1593+
if (Obj.sections().size() >= SHN_LORESERVE) {
15991594
auto Sections = Obj.sections();
16001595
NeedsLargeIndexes =
16011596
std::any_of(Sections.begin() + SHN_LORESERVE, Sections.end(),

llvm/tools/llvm-objcopy/ELF/Object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class SectionTableRef {
5959

6060
iterator begin() { return iterator(Sections.data()); }
6161
iterator end() { return iterator(Sections.data() + Sections.size()); }
62+
size_t size() const { return Sections.size(); }
6263

6364
SectionBase *getSection(uint32_t Index, Twine ErrMsg);
6465

0 commit comments

Comments
 (0)