
SUMMARY: For the llvm-objdump -D, the symbol name is used as a label in the disassembly for the specific address (when a symbol address is equal to the virtual address in the dump). In XCOFF, multiple symbols may have the same name, being differentiated by their storage mapping class. It is helpful to print the QualName and not just the name when forming the output label for a csect symbol. The symbol index further removes any ambiguity caused by duplicate names. To maintain compatibility with the binutils objdump, the XCOFF-specific --symbol-description option is added to enable the enhanced format. Reviewers: hubert.reinterpretcast, James Henderson, Jason Liu ,daltenty Subscribers: wuzish, nemanjai, hiraditya Differential Revision: https://reviews.llvm.org/D72973
75 lines
2.5 KiB
C++
75 lines
2.5 KiB
C++
//===-- XCOFFDump.cpp - XCOFF-specific dumper -----------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file implements the XCOFF-specific dumper for llvm-objdump.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "XCOFFDump.h"
|
|
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::object;
|
|
|
|
Error objdump::getXCOFFRelocationValueString(const XCOFFObjectFile *Obj,
|
|
const RelocationRef &Rel,
|
|
SmallVectorImpl<char> &Result) {
|
|
symbol_iterator SymI = Rel.getSymbol();
|
|
if (SymI == Obj->symbol_end())
|
|
return make_error<GenericBinaryError>(
|
|
"invalid symbol reference in relocation entry",
|
|
object_error::parse_failed);
|
|
|
|
Expected<StringRef> SymNameOrErr = SymI->getName();
|
|
if (!SymNameOrErr)
|
|
return SymNameOrErr.takeError();
|
|
StringRef SymName = *SymNameOrErr;
|
|
Result.append(SymName.begin(), SymName.end());
|
|
return Error::success();
|
|
}
|
|
|
|
Optional<XCOFF::StorageMappingClass>
|
|
objdump::getXCOFFSymbolCsectSMC(const XCOFFObjectFile *Obj,
|
|
const SymbolRef &Sym) {
|
|
XCOFFSymbolRef SymRef(Sym.getRawDataRefImpl(), Obj);
|
|
|
|
if (SymRef.hasCsectAuxEnt())
|
|
return SymRef.getXCOFFCsectAuxEnt32()->StorageMappingClass;
|
|
|
|
return None;
|
|
}
|
|
|
|
bool objdump::isLabel(const XCOFFObjectFile *Obj, const SymbolRef &Sym) {
|
|
|
|
XCOFFSymbolRef SymRef(Sym.getRawDataRefImpl(), Obj);
|
|
|
|
if (SymRef.hasCsectAuxEnt())
|
|
return SymRef.getXCOFFCsectAuxEnt32()->isLabel();
|
|
|
|
return false;
|
|
}
|
|
|
|
void objdump::printXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
|
|
StringRef SymbolName) {
|
|
assert(SymbolInfo.isXCOFF() && "Must be a XCOFFSymInfo.");
|
|
|
|
// Dummy symbols have no symbol index.
|
|
if (SymbolInfo.XCOFFSymInfo.Index)
|
|
outs() << "(idx: " << SymbolInfo.XCOFFSymInfo.Index.getValue() << ") ";
|
|
|
|
outs() << SymbolName;
|
|
|
|
if (SymbolInfo.XCOFFSymInfo.StorageMappingClass &&
|
|
!SymbolInfo.XCOFFSymInfo.IsLabel) {
|
|
const XCOFF::StorageMappingClass Smc =
|
|
SymbolInfo.XCOFFSymInfo.StorageMappingClass.getValue();
|
|
outs() << "[" << XCOFF::getMappingClassString(Smc) << "]";
|
|
}
|
|
}
|