[llvm] [XCOFF] Use RLDs to print branches even without -r (PR #74342)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 02:24:40 PST 2023


================
@@ -2160,19 +2198,33 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
                   break;
               }
 
+              // Branch targets are printed just after the instructions.
               // Print the labels corresponding to the target if there's any.
               bool BBAddrMapLabelAvailable = BBAddrMapLabels.count(Target);
               bool LabelAvailable = AllLabels.count(Target);
+
               if (TargetSym != nullptr) {
                 uint64_t TargetAddress = TargetSym->Addr;
                 uint64_t Disp = Target - TargetAddress;
                 std::string TargetName = Demangle ? demangle(TargetSym->Name)
                                                   : TargetSym->Name.str();
 
                 *TargetOS << " <";
-                if (!Disp) {
-                  // Always Print the binary symbol precisely corresponding to
-                  // the target address.
+                // On XCOFF, we use relocations, even without -r, so we
+                // can print the correct name for an extern function call.
+                if (Obj.isXCOFF() && findRel()) {
+                  SmallString<32> Val;
+
+                  // If we have a valid relocation, try to print the
+                  // corresponding symbol name. Multiple relocations on the
+                  // same instruction are not handled.
+                  if (!getRelocationValueString(*RelCur, false, Val))
+                    *TargetOS << Val;
+                  else
+                    *TargetOS << TargetName;
----------------
EsmeYi wrote:

It's better to use consumeError or reportWarning when an error is returned by getRelocationValueString().

https://github.com/llvm/llvm-project/pull/74342


More information about the llvm-commits mailing list