[Object] Teach Object and llvm-objdump about ".hidden"
[oota-llvm.git] / tools / llvm-objdump / llvm-objdump.cpp
index 9e51c19bd7ce9882214b91cd7d7ffa73a485676e..e442ac050fcea2011b020a42142056cb8bf8ebff 100644 (file)
@@ -194,30 +194,17 @@ static const Target *getTarget(const ObjectFile *Obj = nullptr) {
   return TheTarget;
 }
 
-void llvm::DumpBytes(StringRef bytes) {
+void llvm::DumpBytes(ArrayRef<uint8_t> bytes) {
   static const char hex_rep[] = "0123456789abcdef";
-  // FIXME: The real way to do this is to figure out the longest instruction
-  //        and align to that size before printing. I'll fix this when I get
-  //        around to outputting relocations.
-  // 15 is the longest x86 instruction
-  // 3 is for the hex rep of a byte + a space.
-  // 1 is for the null terminator.
-  enum { OutputSize = (15 * 3) + 1 };
-  char output[OutputSize];
-
-  assert(bytes.size() <= 15
-    && "DumpBytes only supports instructions of up to 15 bytes");
-  memset(output, ' ', sizeof(output));
-  unsigned index = 0;
-  for (StringRef::iterator i = bytes.begin(),
-                           e = bytes.end(); i != e; ++i) {
-    output[index] = hex_rep[(*i & 0xF0) >> 4];
-    output[index + 1] = hex_rep[*i & 0xF];
-    index += 3;
+  SmallString<64> output;
+
+  for (char i: bytes) {
+    output.push_back(hex_rep[(i & 0xF0) >> 4]);
+    output.push_back(hex_rep[i & 0xF]);
+    output.push_back(' ');
   }
 
-  output[sizeof(output) - 1] = 0;
-  outs() << output;
+  outs() << output.c_str();
 }
 
 bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
@@ -287,7 +274,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
 
   int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
   std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
-      AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI));
+      Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
   if (!IP) {
     errs() << "error: no instruction printer for target " << TripleName
       << '\n';
@@ -412,10 +399,9 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
           outs() << format("%8" PRIx64 ":", SectionAddr + Index);
           if (!NoShowRawInsn) {
             outs() << "\t";
-            DumpBytes(StringRef(
-                reinterpret_cast<const char *>(Bytes.data()) + Index, Size));
+            DumpBytes(ArrayRef<uint8_t>(Bytes.data() + Index, Size));
           }
-          IP->printInst(&Inst, outs(), "");
+          IP->printInst(&Inst, outs(), "", *STI);
           outs() << CommentStream.str();
           Comments.clear();
           outs() << "\n";
@@ -643,6 +629,7 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
     bool Weak = Flags & SymbolRef::SF_Weak;
     bool Absolute = Flags & SymbolRef::SF_Absolute;
     bool Common = Flags & SymbolRef::SF_Common;
+    bool Hidden = Flags & SymbolRef::SF_Hidden;
 
     if (Common) {
       uint32_t Alignment;
@@ -697,8 +684,11 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
       outs() << SectionName;
     }
     outs() << '\t'
-           << format("%08" PRIx64 " ", Size)
-           << Name
+           << format("%08" PRIx64 " ", Size);
+    if (Hidden) {
+      outs() << ".hidden ";
+    }
+    outs() << Name
            << '\n';
   }
 }
@@ -910,6 +900,7 @@ int main(int argc, char **argv) {
       && !(InfoPlist && MachOOpt)
       && !(DylibsUsed && MachOOpt)
       && !(DylibId && MachOOpt)
+      && !(ObjcMetaData && MachOOpt)
       && !(DumpSections.size() != 0 && MachOOpt)) {
     cl::PrintHelpMessage();
     return 2;