Revert r360876 "[Object] Change object::SectionRef::getContents() to return Expected<StringRef>"

It broke the Clang build, see llvm-commits thread.

> Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now.
>
> Follow-up of D61781.

llvm-svn: 360878
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 21ceb00..62f2fc5 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -933,7 +933,8 @@
 
 void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
                                             const SectionRef &Section) {
-  StringRef SectionContents = unwrapOrError(Section.getContents());
+  StringRef SectionContents;
+  error(Section.getContents(SectionContents));
   StringRef Data = SectionContents;
 
   SmallVector<StringRef, 10> FunctionNames;
@@ -1217,7 +1218,8 @@
     StringRef SectionName;
     error(S.getName(SectionName));
     if (SectionName == ".debug$T") {
-      StringRef Data = unwrapOrError(S.getContents());
+      StringRef Data;
+      error(S.getContents(Data));
       uint32_t Magic;
       error(consume(Data, Magic));
       if (Magic != 4)
@@ -1253,7 +1255,8 @@
   ListScope D(W, "CodeViewTypes");
   W.printNumber("Section", SectionName, Obj->getSectionID(Section));
 
-  StringRef Data = unwrapOrError(Section.getContents());
+  StringRef Data;
+  error(Section.getContents(Data));
   if (opts::CodeViewSubsectionBytes)
     W.printBinaryBlock("Data", Data);
 
@@ -1313,7 +1316,9 @@
 
     if (opts::SectionData &&
         !(Section->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) {
-      StringRef Data = unwrapOrError(Sec.getContents());
+      StringRef Data;
+      error(Sec.getContents(Data));
+
       W.printBinaryBlock("SectionData", Data);
     }
   }
@@ -1655,13 +1660,15 @@
 
 void COFFDumper::printCOFFDirectives() {
   for (const SectionRef &Section : Obj->sections()) {
+    StringRef Contents;
     StringRef Name;
 
     error(Section.getName(Name));
     if (Name != ".drectve")
       continue;
 
-    StringRef Contents = unwrapOrError(Section.getContents());
+    error(Section.getContents(Contents));
+
     W.printString("Directive(s)", Contents);
   }
 }
@@ -1700,7 +1707,8 @@
     if (!Name.startswith(".rsrc"))
       continue;
 
-    StringRef Ref = unwrapOrError(S.getContents());
+    StringRef Ref;
+    error(S.getContents(Ref));
 
     if ((Name == ".rsrc") || (Name == ".rsrc$01")) {
       ResourceSectionRef RSF(Ref);
@@ -1826,7 +1834,8 @@
   if (StackMapSection == object::SectionRef())
     return;
 
-  StringRef StackMapContents = unwrapOrError(StackMapSection.getContents());
+  StringRef StackMapContents;
+  StackMapSection.getContents(StackMapContents);
   ArrayRef<uint8_t> StackMapContentsArray =
       arrayRefFromStringRef(StackMapContents);
 
@@ -1852,7 +1861,8 @@
   if (AddrsigSection == object::SectionRef())
     return;
 
-  StringRef AddrsigContents = unwrapOrError(AddrsigSection.getContents());
+  StringRef AddrsigContents;
+  AddrsigSection.getContents(AddrsigContents);
   ArrayRef<uint8_t> AddrsigContentsArray(AddrsigContents.bytes_begin(),
                                          AddrsigContents.size());
 
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index 5149f46..5e82f1c 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -483,8 +483,15 @@
       }
     }
 
-    if (opts::SectionData && !Section.isBSS())
-      W.printBinaryBlock("SectionData", unwrapOrError(Section.getContents()));
+    if (opts::SectionData) {
+      bool IsBSS = Section.isBSS();
+      if (!IsBSS) {
+        StringRef Data;
+        error(Section.getContents(Data));
+
+        W.printBinaryBlock("SectionData", Data);
+      }
+    }
   }
 }
 
@@ -653,7 +660,8 @@
   if (StackMapSection == object::SectionRef())
     return;
 
-  StringRef StackMapContents = unwrapOrError(StackMapSection.getContents());
+  StringRef StackMapContents;
+  StackMapSection.getContents(StackMapContents);
   ArrayRef<uint8_t> StackMapContentsArray =
       arrayRefFromStringRef(StackMapContents);
 
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 4f73cbd..15facef 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -73,7 +73,8 @@
     error(E);
   W.startLine() << "String dump of section '" << SectionName << "':\n";
 
-  StringRef SectionContent = unwrapOrError(Section.getContents());
+  StringRef SectionContent;
+  Section.getContents(SectionContent);
 
   const uint8_t *SecContent = SectionContent.bytes_begin();
   const uint8_t *CurrentWord = SecContent;
@@ -106,7 +107,8 @@
     error(E);
   W.startLine() << "Hex dump of section '" << SectionName << "':\n";
 
-  StringRef SectionContent = unwrapOrError(Section.getContents());
+  StringRef SectionContent;
+  Section.getContents(SectionContent);
   const uint8_t *SecContent = SectionContent.bytes_begin();
   const uint8_t *SecEnd = SecContent + SectionContent.size();