Remove bogus std::error_code returns form SectionRef.

There are two methods in SectionRef that can fail:

* getName: The index into the string table can be invalid.
* getContents: The section might point to invalid contents.

Every other method will always succeed and returning and std::error_code just
complicates the code. For example, a section can have an invalid alignment,
but if we are able to get to the section structure at all and create a
SectionRef, we will always be able to read that invalid alignment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219314 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-10-08 15:28:58 +00:00
parent 1a98f792a5
commit 8175be535a
22 changed files with 252 additions and 470 deletions

View File

@ -307,25 +307,17 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
}
for (const SectionRef &Section : Obj->sections()) {
bool Text;
if (error(Section.isText(Text)))
break;
bool Text = Section.isText();
if (!Text)
continue;
uint64_t SectionAddr;
if (error(Section.getAddress(SectionAddr)))
break;
uint64_t SectSize;
if (error(Section.getSize(SectSize)))
break;
uint64_t SectionAddr = Section.getAddress();
uint64_t SectSize = Section.getSize();
// Make a list of all the symbols in this section.
std::vector<std::pair<uint64_t, StringRef>> Symbols;
for (const SymbolRef &Symbol : Obj->symbols()) {
bool contains;
if (!error(Section.containsSymbol(Symbol, contains)) && contains) {
if (Section.containsSymbol(Symbol)) {
uint64_t Address;
if (error(Symbol.getAddress(Address)))
break;
@ -501,19 +493,11 @@ static void PrintSectionHeaders(const ObjectFile *Obj) {
StringRef Name;
if (error(Section.getName(Name)))
return;
uint64_t Address;
if (error(Section.getAddress(Address)))
return;
uint64_t Size;
if (error(Section.getSize(Size)))
return;
bool Text, Data, BSS;
if (error(Section.isText(Text)))
return;
if (error(Section.isData(Data)))
return;
if (error(Section.isBSS(BSS)))
return;
uint64_t Address = Section.getAddress();
uint64_t Size = Section.getSize();
bool Text = Section.isText();
bool Data = Section.isData();
bool BSS = Section.isBSS();
std::string Type = (std::string(Text ? "TEXT " : "") +
(Data ? "DATA " : "") + (BSS ? "BSS" : ""));
outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n", i,
@ -527,20 +511,14 @@ static void PrintSectionContents(const ObjectFile *Obj) {
for (const SectionRef &Section : Obj->sections()) {
StringRef Name;
StringRef Contents;
uint64_t BaseAddr;
bool BSS;
if (error(Section.getName(Name)))
continue;
if (error(Section.getAddress(BaseAddr)))
continue;
if (error(Section.isBSS(BSS)))
continue;
uint64_t BaseAddr = Section.getAddress();
bool BSS = Section.isBSS();
outs() << "Contents of section " << Name << ":\n";
if (BSS) {
uint64_t Size;
if (error(Section.getSize(Size)))
continue;
uint64_t Size = Section.getSize();
outs() << format("<skipping contents of bss section at [%04" PRIx64
", %04" PRIx64 ")>\n",
BaseAddr, BaseAddr + Size);