/// <summary> /// Emit a single ObjectData into the proper section of the output R2R PE executable. /// </summary> /// <param name="data">ObjectData blob to emit</param> /// <param name="name">Textual representation of the ObjecData blob in the map file</param> /// <param name="section">Section to emit the blob into</param> /// <param name="mapFile">Map file output stream</param> private void EmitObjectData(ObjectData data, int nodeIndex, string name, ObjectNodeSection section, TextWriter mapFile) { int targetSectionIndex; switch (section.Type) { case SectionType.Executable: targetSectionIndex = _textSectionIndex; break; case SectionType.Writeable: targetSectionIndex = _dataSectionIndex; break; case SectionType.ReadOnly: targetSectionIndex = _rdataSectionIndex; break; default: throw new NotImplementedException(); } #if DEBUG for (int symbolIndex = 0; symbolIndex < data.DefinedSymbols.Length; symbolIndex++) { ISymbolNode definedSymbol = data.DefinedSymbols[symbolIndex]; NodeInfo alreadyWrittenSymbol; string symbolName = definedSymbol.GetMangledName(_nodeFactory.NameMangler); if (_previouslyWrittenNodeNames.TryGetValue(symbolName, out alreadyWrittenSymbol)) { Console.WriteLine($@"Duplicate symbol - 1st occurrence: [{alreadyWrittenSymbol.NodeIndex}:{alreadyWrittenSymbol.SymbolIndex}], {alreadyWrittenSymbol.Node.GetMangledName(_nodeFactory.NameMangler)}"); Console.WriteLine($@"Duplicate symbol - 2nd occurrence: [{nodeIndex}:{symbolIndex}], {definedSymbol.GetMangledName(_nodeFactory.NameMangler)}"); Debug.Fail("Duplicate node name emitted to file", $"Symbol {definedSymbol.GetMangledName(_nodeFactory.NameMangler)} has already been written to the output object file {_objectFilePath} with symbol {alreadyWrittenSymbol}"); } _previouslyWrittenNodeNames.Add(symbolName, new NodeInfo(definedSymbol, nodeIndex, symbolIndex)); } #endif _sectionBuilder.AddObjectData(data, targetSectionIndex, name, mapFile); }