aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-31 21:22:58 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-31 21:22:58 +0000
commit5ffd83dbcc34f10e07f6d3e968ae6365869615f4 (patch)
tree0e9f5cf729dde39f949698fddef45a34e2bc7f44 /contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp
parent1799696096df87b52968b8996d00c91e0a5de8d9 (diff)
parentcfca06d7963fa0909f90483b42a6d7d194d01e08 (diff)
downloadsrc-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.tar.gz
src-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.zip
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
master 2e10b7a39b9, the last commit before the llvmorg-12-init tag, from which release/11.x was branched. Note that for now, I rolled back all our local changes to make merging easier, and I will reapply the still-relevant ones after updating to 11.0.0-rc1.
Notes
Notes: svn path=/projects/clang1100-import/; revision=363742
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp')
-rw-r--r--contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp b/contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp
index 46ece5a6f0c9..987270e98c48 100644
--- a/contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp
+++ b/contrib/llvm-project/llvm/tools/llvm-size/llvm-size.cpp
@@ -187,20 +187,26 @@ static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
switch (static_cast<ELFSectionRef>(Section).getType()) {
case ELF::SHT_NULL:
case ELF::SHT_SYMTAB:
+ return false;
case ELF::SHT_STRTAB:
case ELF::SHT_REL:
case ELF::SHT_RELA:
- return false;
+ return static_cast<ELFSectionRef>(Section).getFlags() & ELF::SHF_ALLOC;
}
return true;
}
/// Total size of all ELF common symbols
-static uint64_t getCommonSize(ObjectFile *Obj) {
+static Expected<uint64_t> getCommonSize(ObjectFile *Obj) {
uint64_t TotalCommons = 0;
- for (auto &Sym : Obj->symbols())
- if (Obj->getSymbolFlags(Sym.getRawDataRefImpl()) & SymbolRef::SF_Common)
+ for (auto &Sym : Obj->symbols()) {
+ Expected<uint32_t> SymFlagsOrErr =
+ Obj->getSymbolFlags(Sym.getRawDataRefImpl());
+ if (!SymFlagsOrErr)
+ return SymFlagsOrErr.takeError();
+ if (*SymFlagsOrErr & SymbolRef::SF_Common)
TotalCommons += Obj->getCommonSymbolSize(Sym.getRawDataRefImpl());
+ }
return TotalCommons;
}
@@ -435,10 +441,14 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
}
if (ELFCommons) {
- uint64_t CommonSize = getCommonSize(Obj);
- total += CommonSize;
- outs() << format(fmt.str().c_str(), std::string("*COM*").c_str(),
- CommonSize, static_cast<uint64_t>(0));
+ if (Expected<uint64_t> CommonSizeOrErr = getCommonSize(Obj)) {
+ total += *CommonSizeOrErr;
+ outs() << format(fmt.str().c_str(), std::string("*COM*").c_str(),
+ *CommonSizeOrErr, static_cast<uint64_t>(0));
+ } else {
+ error(CommonSizeOrErr.takeError(), Obj->getFileName());
+ return;
+ }
}
// Print total.
@@ -469,8 +479,14 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
total_bss += size;
}
- if (ELFCommons)
- total_bss += getCommonSize(Obj);
+ if (ELFCommons) {
+ if (Expected<uint64_t> CommonSizeOrErr = getCommonSize(Obj))
+ total_bss += *CommonSizeOrErr;
+ else {
+ error(CommonSizeOrErr.takeError(), Obj->getFileName());
+ return;
+ }
+ }
total = total_text + total_data + total_bss;