summaryrefslogtreecommitdiffstats
path: root/llvm/tools/obj2yaml
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-03-19 04:47:47 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-03-19 04:47:47 +0000
commitddf28f2b7987ecd4e28ba0b5c211ed9601ece986 (patch)
tree2994bcf571a8984ed3a722f5aec87ffbb6d85edd /llvm/tools/obj2yaml
parentf3a2af5371d182254b9a866f4db61537ba8c356d (diff)
downloadbcm5719-llvm-ddf28f2b7987ecd4e28ba0b5c211ed9601ece986.tar.gz
bcm5719-llvm-ddf28f2b7987ecd4e28ba0b5c211ed9601ece986.zip
Object: Provide a richer means of describing auxiliary symbols
The current state of affairs has auxiliary symbols described as a big bag of bytes. This is less than satisfying, it detracts from the YAML file as being human readable. Instead, allow for symbols to optionally contain their auxiliary data. This allows us to have a much higher level way of describing things like weak symbols, function definitions and section definitions. This depends on D3105. Differential Revision: http://llvm-reviews.chandlerc.com/D3092 llvm-svn: 204214
Diffstat (limited to 'llvm/tools/obj2yaml')
-rw-r--r--llvm/tools/obj2yaml/coff2yaml.cpp112
1 files changed, 111 insertions, 1 deletions
diff --git a/llvm/tools/obj2yaml/coff2yaml.cpp b/llvm/tools/obj2yaml/coff2yaml.cpp
index 6cf79aeabc7..b003029407c 100644
--- a/llvm/tools/obj2yaml/coff2yaml.cpp
+++ b/llvm/tools/obj2yaml/coff2yaml.cpp
@@ -78,6 +78,61 @@ void COFFDumper::dumpSections(unsigned NumSections) {
}
}
+static void
+dumpFunctionDefinition(COFFYAML::Symbol *Sym,
+ const object::coff_aux_function_definition *ObjFD) {
+ COFF::AuxiliaryFunctionDefinition YAMLFD;
+ YAMLFD.TagIndex = ObjFD->TagIndex;
+ YAMLFD.TotalSize = ObjFD->TotalSize;
+ YAMLFD.PointerToLinenumber = ObjFD->PointerToLinenumber;
+ YAMLFD.PointerToNextFunction = ObjFD->PointerToNextFunction;
+
+ Sym->FunctionDefinition = YAMLFD;
+}
+
+static void
+dumpbfAndEfLineInfo(COFFYAML::Symbol *Sym,
+ const object::coff_aux_bf_and_ef_symbol *ObjBES) {
+ COFF::AuxiliarybfAndefSymbol YAMLAAS;
+ YAMLAAS.Linenumber = ObjBES->Linenumber;
+ YAMLAAS.PointerToNextFunction = ObjBES->PointerToNextFunction;
+
+ Sym->bfAndefSymbol = YAMLAAS;
+}
+
+static void dumpWeakExternal(COFFYAML::Symbol *Sym,
+ const object::coff_aux_weak_external *ObjWE) {
+ COFF::AuxiliaryWeakExternal YAMLWE;
+ YAMLWE.TagIndex = ObjWE->TagIndex;
+ YAMLWE.Characteristics = ObjWE->Characteristics;
+
+ Sym->WeakExternal = YAMLWE;
+}
+
+static void
+dumpSectionDefinition(COFFYAML::Symbol *Sym,
+ const object::coff_aux_section_definition *ObjSD) {
+ COFF::AuxiliarySectionDefinition YAMLASD;
+ YAMLASD.Length = ObjSD->Length;
+ YAMLASD.NumberOfRelocations = ObjSD->NumberOfRelocations;
+ YAMLASD.NumberOfLinenumbers = ObjSD->NumberOfLinenumbers;
+ YAMLASD.CheckSum = ObjSD->CheckSum;
+ YAMLASD.Number = ObjSD->Number;
+ YAMLASD.Selection = ObjSD->Selection;
+
+ Sym->SectionDefinition = YAMLASD;
+}
+
+static void
+dumpCLRTokenDefinition(COFFYAML::Symbol *Sym,
+ const object::coff_aux_clr_token *ObjCLRToken) {
+ COFF::AuxiliaryCLRToken YAMLCLRToken;
+ YAMLCLRToken.AuxType = ObjCLRToken->AuxType;
+ YAMLCLRToken.SymbolTableIndex = ObjCLRToken->SymbolTableIndex;
+
+ Sym->CLRToken = YAMLCLRToken;
+}
+
void COFFDumper::dumpSymbols(unsigned NumSymbols) {
std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
for (const auto &S : Obj.symbols()) {
@@ -90,7 +145,62 @@ void COFFDumper::dumpSymbols(unsigned NumSymbols) {
Sym.Header.Value = Symbol->Value;
Sym.Header.SectionNumber = Symbol->SectionNumber;
Sym.Header.NumberOfAuxSymbols = Symbol->NumberOfAuxSymbols;
- Sym.AuxiliaryData = object::yaml::BinaryRef(Obj.getSymbolAuxData(Symbol));
+
+ if (Symbol->NumberOfAuxSymbols > 0) {
+ ArrayRef<uint8_t> AuxData = Obj.getSymbolAuxData(Symbol);
+ if (Symbol->isFunctionDefinition()) {
+ // This symbol represents a function definition.
+ assert(Symbol->NumberOfAuxSymbols == 1 &&
+ "Expected a single aux symbol to describe this function!");
+
+ const object::coff_aux_function_definition *ObjFD =
+ reinterpret_cast<const object::coff_aux_function_definition *>(
+ AuxData.data());
+ dumpFunctionDefinition(&Sym, ObjFD);
+ } else if (Symbol->StorageClass == COFF::IMAGE_SYM_CLASS_FUNCTION) {
+ // This symbol describes function line number information.
+ assert(Symbol->NumberOfAuxSymbols == 1 &&
+ "Exepected a single aux symbol to describe this section!");
+
+ const object::coff_aux_bf_and_ef_symbol *ObjBES =
+ reinterpret_cast<const object::coff_aux_bf_and_ef_symbol *>(
+ AuxData.data());
+ dumpbfAndEfLineInfo(&Sym, ObjBES);
+ } else if (Symbol->isWeakExternal()) {
+ // This symbol represents a weak external definition.
+ assert(Symbol->NumberOfAuxSymbols == 1 &&
+ "Exepected a single aux symbol to describe this section!");
+
+ const object::coff_aux_weak_external *ObjWE =
+ reinterpret_cast<const object::coff_aux_weak_external *>(
+ AuxData.data());
+ dumpWeakExternal(&Sym, ObjWE);
+ } else if (Symbol->isFileRecord()) {
+ // This symbol represents a file record.
+ Sym.File = StringRef(reinterpret_cast<const char *>(AuxData.data()),
+ Symbol->NumberOfAuxSymbols * COFF::SymbolSize);
+ } else if (Symbol->isSectionDefinition()) {
+ // This symbol represents a section definition.
+ assert(Symbol->NumberOfAuxSymbols == 1 &&
+ "Expected a single aux symbol to describe this section!");
+
+ const object::coff_aux_section_definition *ObjSD =
+ reinterpret_cast<const object::coff_aux_section_definition *>(
+ AuxData.data());
+ dumpSectionDefinition(&Sym, ObjSD);
+ } else if (Symbol->isCLRToken()) {
+ // This symbol represents a CLR token definition.
+ assert(Symbol->NumberOfAuxSymbols == 1 &&
+ "Expected a single aux symbol to describe this CLR Token");
+
+ const object::coff_aux_clr_token *ObjCLRToken =
+ reinterpret_cast<const object::coff_aux_clr_token *>(
+ AuxData.data());
+ dumpCLRTokenDefinition(&Sym, ObjCLRToken);
+ } else {
+ llvm_unreachable("Unhandled auxiliary symbol!");
+ }
+ }
Symbols.push_back(Sym);
}
}
OpenPOWER on IntegriCloud