public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory); // These need to be aligned the same as methods because they show up in same contexts builder.RequireAlignment(factory.Target.MinimumFunctionAlignment); builder.DefinedSymbols.Add(this); MethodDesc canonMethod = Method.GetCanonMethodTarget(CanonicalFormKind.Specific); // Pointer to the canonical body of the method builder.EmitPointerReloc(factory.MethodEntrypoint(canonMethod)); // Find out what's the context to use GenericDictionaryNode dictionary; if (canonMethod.RequiresInstMethodDescArg()) { dictionary = factory.MethodGenericDictionary(Method); } else { Debug.Assert(canonMethod.RequiresInstMethodTableArg()); dictionary = factory.TypeGenericDictionary(Method.OwningType); } // The next entry is a pointer to the pointer to the context to be used for the canonical method // TODO: in multi-module, this points to the import cell, and is no longer this weird pointer builder.EmitPointerReloc(factory.Indirection(dictionary)); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); // The interface dispatch cell has an alignment requirement of 2 * [Pointer size] as part of the // synchronization mechanism of the two values in the runtime. objData.Alignment = _targetMethod.Context.Target.PointerSize * 2; objData.DefinedSymbols.Add(this); objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch")); // The second cell field uses the two lower-order bits to communicate the contents. // We add 1 to signal IDC_CachePointerIsInterfacePointer. See src\Native\Runtime\inc\rhbinder.h. objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), 1); // End the run of dispatch cells objData.EmitZeroPointer(); int interfaceMethodSlot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod); if (factory.Target.PointerSize == 8) { objData.EmitLong(interfaceMethodSlot); } else { throw new NotImplementedException(); } return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = 16; objData.DefinedSymbols.Add(this); ComputeOptionalEETypeFields(factory); if (null == _optionalFieldsNode) { _optionalFieldsNode = factory.EETypeOptionalFields(_optionalFieldsBuilder); } OutputComponentSize(ref objData); OutputFlags(factory, ref objData); OutputBaseSize(ref objData); OutputRelatedType(factory, ref objData); OutputVirtualSlotAndInterfaceCount(factory, ref objData); objData.EmitInt(_type.GetHashCode()); if (_constructed) { OutputVirtualSlots(factory, ref objData, _type, _type); OutputFinalizerMethod(factory, ref objData); OutputOptionalFields(factory, ref objData); OutputNullableTypeParameter(factory, ref objData); } return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); if (factory.Target.Abi == TargetAbi.CoreRT) { int delta = GCStaticRegionConstants.Uninitialized; // Set the flag that indicates next pointer following EEType is the preinit data if (_preInitFieldInfos != null) { delta |= GCStaticRegionConstants.HasPreInitializedData; } builder.EmitPointerReloc(GetGCStaticEETypeNode(factory), delta); if (_preInitFieldInfos != null) { builder.EmitPointerReloc(factory.GCStaticsPreInitDataNode(_type)); } } else { builder.RequireInitialAlignment(_type.GCStaticFieldAlignment.AsInt); // @TODO - emit the frozen array node reloc builder.EmitZeros(_type.GCStaticFieldSize.AsInt); } builder.AddSymbol(this); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); // If the type has a class constructor, it's non-GC statics section is prefixed // by System.Runtime.CompilerServices.StaticClassConstructionContext struct. if (HasClassConstructorContext) { int alignmentRequired = Math.Max(_type.NonGCStaticFieldAlignment, ClassConstructorContextAlignment); builder.RequireAlignment(alignmentRequired); Debug.Assert(((ISymbolNode)this).Offset >= ClassConstructorContextSize); // Add padding before the context if alignment forces us to do so builder.EmitZeros(((ISymbolNode)this).Offset - ClassConstructorContextSize); // Emit the actual StaticClassConstructionContext var cctorMethod = _type.GetStaticConstructor(); builder.EmitPointerReloc(factory.MethodEntrypoint(cctorMethod)); builder.EmitZeroPointer(); builder.DefinedSymbols.Add(_classConstructorContext); } else { builder.RequireAlignment(_type.NonGCStaticFieldAlignment); } builder.EmitZeros(_type.NonGCStaticFieldSize); builder.DefinedSymbols.Add(this); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialAlignment(4); objData.AddSymbol(this); if (BuildSealedVTableSlots(factory, relocsOnly)) { for (int i = 0; i < _sealedVTableEntries.Count; i++) { IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, _type); if (factory.Target.SupportsRelativePointers) { objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32); } else { objData.EmitPointerReloc(relocTarget); } } } return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); // // Emit a MethodFixupCell struct // // Address (to be fixed up at runtime) builder.EmitZeroPointer(); // Entry point name if (factory.Target.IsWindows && _entryPointName.StartsWith("#", StringComparison.OrdinalIgnoreCase)) { // Windows-specific ordinal import // CLR-compatible behavior: Strings that can't be parsed as a signed integer are treated as zero. int entrypointOrdinal; if (!int.TryParse(_entryPointName.Substring(1), out entrypointOrdinal)) entrypointOrdinal = 0; // CLR-compatible behavior: Ordinal imports are 16-bit on Windows. Discard rest of the bits. builder.EmitNaturalInt((ushort)entrypointOrdinal); } else { // Import by name builder.EmitPointerReloc(factory.ConstantUtf8String(_entryPointName)); } // Module fixup cell builder.EmitPointerReloc(factory.PInvokeModuleFixup(_moduleName)); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // The dependency tracking of this node currently does nothing because the data emission relies // the set of compiled methods which has an incomplete state during dependency tracking. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolDefinitionNode[] { this })); } ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialPointerAlignment(); objData.AddSymbol(this); objData.AddSymbol(_endSymbol); RelocType reloc = factory.Target.Abi == TargetAbi.CoreRT ? RelocType.IMAGE_REL_BASED_RELPTR32 : RelocType.IMAGE_REL_BASED_ADDR32NB; foreach (var mappingEntry in factory.MetadataManager.GetStackTraceMapping(factory)) { objData.EmitReloc(factory.MethodEntrypoint(mappingEntry.Entity), reloc); objData.EmitInt(mappingEntry.MetadataHandle); } _endSymbol.SetSymbolOffset(objData.CountBytes); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); // The interface dispatch cell has an alignment requirement of 2 * [Pointer size] as part of the // synchronization mechanism of the two values in the runtime. objData.Alignment = _targetMethod.Context.Target.PointerSize * 2; objData.DefinedSymbols.Add(this); objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch")); // The second cell field uses the two lower-order bits to communicate the contents. // We add 1 to signal IDC_CachePointerIsInterfacePointer. See src\Native\Runtime\inc\rhbinder.h. objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), 1); // End the run of dispatch cells objData.EmitZeroPointer(); int interfaceMethodSlot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod); if (factory.Target.PointerSize == 8) { objData.EmitLong(interfaceMethodSlot); } else { throw new NotImplementedException(); } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolDefinitionNode[] { this })); } // Zero out the dictionary so that we AV if someone tries to insert after we're done. _insertedSymbolsDictionary = null; var builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialAlignment(factory.Target.SupportsRelativePointers ? 4 : factory.Target.PointerSize); foreach (SymbolAndDelta symbolAndDelta in _insertedSymbols) { if (factory.Target.SupportsRelativePointers) { // TODO: set low bit if the linkage of the symbol is IAT_PVALUE. builder.EmitReloc(symbolAndDelta.Symbol, RelocType.IMAGE_REL_BASED_RELPTR32, symbolAndDelta.Delta); } else { builder.EmitPointerReloc(symbolAndDelta.Symbol, symbolAndDelta.Delta); } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.AddSymbol(this); builder.AddSymbol(_endSymbol); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolDefinitionNode[] { this })); } var builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); builder.AddSymbol(this); ISortableSymbolNode[] symbolNodes = new ISortableSymbolNode[_exportableSymbols.Count]; _exportableSymbols.CopyTo(symbolNodes); Array.Sort(symbolNodes, new CompilerComparer()); builder.EmitInt(1); // Export table version 1 builder.EmitInt(symbolNodes.Length); // Count of exported symbols in this table uint index = GetInitialExportOrdinal == null ? 1 : GetInitialExportOrdinal(); foreach (ISortableSymbolNode symbol in symbolNodes) { builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_REL32); bool?baselineOrdinalFound = ReportExportedItem?.Invoke(index, (IExportableSymbolNode)symbol); if (baselineOrdinalFound.HasValue && !baselineOrdinalFound.Value) { index++; } } return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); builder.AddSymbol(this); ISymbolNode nameSymbol = factory.ConstantUtf8String(_pInvokeModuleData.ModuleName); ISymbolNode moduleTypeSymbol = factory.NecessaryTypeSymbol(_pInvokeModuleData.DeclaringModule.GetGlobalModuleType()); // // Emit a ModuleFixupCell struct // builder.EmitZeroPointer(); builder.EmitPointerReloc(nameSymbol); builder.EmitPointerReloc(moduleTypeSymbol); uint dllImportSearchPath = 0; if (_pInvokeModuleData.DllImportSearchPath.HasValue) { dllImportSearchPath = (uint)_pInvokeModuleData.DllImportSearchPath.Value; Debug.Assert((dllImportSearchPath & InteropDataConstants.HasDllImportSearchPath) == 0); dllImportSearchPath |= InteropDataConstants.HasDllImportSearchPath; } builder.EmitInt((int)dllImportSearchPath); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory, relocsOnly); // These need to be aligned the same as methods because they show up in same contexts builder.RequireInitialAlignment(factory.Target.MinimumFunctionAlignment); builder.AddSymbol(this); MethodDesc canonMethod = Method.GetCanonMethodTarget(CanonicalFormKind.Specific); // Pointer to the canonical body of the method builder.EmitPointerReloc(factory.MethodEntrypoint(canonMethod, _isUnboxingStub)); // Find out what's the context to use ISymbolNode contextParameter; if (canonMethod.RequiresInstMethodDescArg()) { contextParameter = factory.MethodGenericDictionary(Method); } else { Debug.Assert(canonMethod.RequiresInstMethodTableArg()); // Ask for a constructed type symbol because we need the vtable to get to the dictionary contextParameter = factory.ConstructedTypeSymbol(Method.OwningType); } // The next entry is a pointer to the pointer to the context to be used for the canonical method builder.EmitPointerReloc(factory.Indirection(contextParameter)); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolNode[] { this })); } ObjectDataBuilder builder = new ObjectDataBuilder(factory); foreach (var mappingEntry in factory.MetadataManager.GetTypeDefinitionMapping()) { var node = (EETypeNode)factory.ConstructedTypeSymbol(mappingEntry.Entity); if (node.Marked) { // TODO: this format got very inefficient due to not being able to use RVAs // replace with a hash table builder.EmitPointerReloc(node); builder.EmitInt(mappingEntry.MetadataHandle); if (factory.Target.PointerSize == 8) { builder.EmitInt(0); // Pad } } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.DefinedSymbols.Add(this); builder.DefinedSymbols.Add(_endSymbol); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { Debug.Assert(MethodHasAssociatedData(factory, _methodNode)); ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialAlignment(1); objData.AddSymbol(this); AssociatedDataFlags flags = AssociatedDataFlags.None; var flagsReservation = objData.ReserveByte(); ISpecialUnboxThunkNode unboxThunkNode = _methodNode as ISpecialUnboxThunkNode; if (unboxThunkNode != null && unboxThunkNode.IsSpecialUnboxingThunk) { flags |= AssociatedDataFlags.HasUnboxingStubTarget; objData.EmitPointerReloc(unboxThunkNode.GetUnboxingThunkTarget(factory)); } objData.EmitByte(flagsReservation, (byte)flags); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialAlignment(4); objData.AddSymbol(this); if (BuildSealedVTableSlots(factory, relocsOnly)) { for (int i = 0; i < _sealedVTableEntries.Count; i++) { MethodDesc canonImplMethod = _sealedVTableEntries[i].GetCanonMethodTarget(CanonicalFormKind.Specific); IMethodNode relocTarget = factory.MethodEntrypoint(canonImplMethod, _sealedVTableEntries[i].OwningType.IsValueType); if (factory.Target.SupportsRelativePointers) { objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32); } else { objData.EmitPointerReloc(relocTarget); } } } return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.Alignment = factory.Target.PointerSize; if (_sorter != null) _nestedNodesList.Sort(_sorter); builder.DefinedSymbols.Add(_startSymbol); foreach (EmbeddedObjectNode node in _nestedNodesList) { if (!relocsOnly) node.Offset = builder.CountBytes; node.EncodeData(ref builder, factory, relocsOnly); if (node is ISymbolNode) { builder.DefinedSymbols.Add((ISymbolNode)node); } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.DefinedSymbols.Add(_endSymbol); ObjectData objData = builder.ToObjectData(); return objData; }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory); // These need to be aligned the same as methods because they show up in same contexts builder.RequireAlignment(factory.Target.MinimumFunctionAlignment); builder.DefinedSymbols.Add(this); MethodDesc canonMethod = Method.GetCanonMethodTarget(CanonicalFormKind.Specific); // Pointer to the canonical body of the method builder.EmitPointerReloc(factory.MethodEntrypoint(canonMethod)); // Find out what's the context to use ISymbolNode contextParameter; if (canonMethod.RequiresInstMethodDescArg()) { contextParameter = factory.MethodGenericDictionary(Method); } else { Debug.Assert(canonMethod.RequiresInstMethodTableArg()); // Ask for a constructed type symbol because we need the vtable to get to the dictionary contextParameter = factory.ConstructedTypeSymbol(Method.OwningType); } // The next entry is a pointer to the pointer to the context to be used for the canonical method // TODO: in multi-module, this points to the import cell, and is no longer this weird pointer builder.EmitPointerReloc(factory.Indirection(contextParameter)); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); int delta = GCStaticRegionConstants.Uninitialized; // Set the flag that indicates next pointer following MethodTable is the preinit data bool isPreinitialized = _preinitializationInfo != null && _preinitializationInfo.IsPreinitialized; if (isPreinitialized) { delta |= GCStaticRegionConstants.HasPreInitializedData; } builder.EmitPointerReloc(GetGCStaticEETypeNode(factory), delta); if (isPreinitialized) { builder.EmitPointerReloc(factory.GCStaticsPreInitDataNode(_type)); } builder.AddSymbol(this); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolNode[] { this })); } // Zero out the dictionary so that we AV if someone tries to insert after we're done. _insertedSymbolsDictionary = null; var builder = new ObjectDataBuilder(factory); foreach (SymbolAndDelta symbolAndDelta in _insertedSymbols) { // TODO: set low bit if the linkage of the symbol is IAT_PVALUE. builder.EmitPointerReloc(symbolAndDelta.Symbol, symbolAndDelta.Delta); } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.AddSymbol(this); builder.AddSymbol(_endSymbol); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); builder.AddSymbol(this); builder.AddSymbol(StartSymbol); builder.EmitInt(1); builder.EmitInt(_importNodes.Count); builder.EmitPointerReloc(factory.ExternSymbol(ExportTableToImportSymbol)); if (!relocsOnly) { FinalizeOffsets(); foreach (MrtImportNode node in _importNodes) { Debug.Assert(((ISymbolDefinitionNode)node).Offset == builder.CountBytes); builder.AddSymbol(node); builder.EmitNaturalInt(node.Ordinal); } } EndSymbol.SetSymbolOffset(builder.CountBytes); builder.AddSymbol(EndSymbol); ObjectData objData = builder.ToObjectData(); return(objData); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.Alignment = factory.Target.PointerSize; if (_sorter != null) { _nestedNodesList.Sort(_sorter); } builder.DefinedSymbols.Add(_startSymbol); foreach (TEmbedded node in _nestedNodesList) { if (!relocsOnly) { node.Offset = builder.CountBytes; } node.EncodeData(ref builder, factory, relocsOnly); if (node is ISymbolNode) { builder.DefinedSymbols.Add((ISymbolNode)node); } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.DefinedSymbols.Add(_endSymbol); ObjectData objData = builder.ToObjectData(); return(objData); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolDefinitionNode[] { this })); } Debug.Assert(_dynamicInvokeMethodContainerType != null); // Ensure the native layout blob has been saved factory.MetadataManager.NativeLayoutInfo.SaveNativeLayoutInfoWriter(factory); ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialPointerAlignment(); objData.AddSymbol(this); if (factory.Target.SupportsRelativePointers) { objData.EmitReloc(factory.NecessaryTypeSymbol(_dynamicInvokeMethodContainerType), RelocType.IMAGE_REL_BASED_RELPTR32); } else { objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_dynamicInvokeMethodContainerType)); } List <KeyValuePair <MethodDesc, int> > sortedList = new List <KeyValuePair <MethodDesc, int> >(_methodToTemplateIndex); sortedList.Sort((firstEntry, secondEntry) => firstEntry.Value.CompareTo(secondEntry.Value)); for (int i = 0; i < sortedList.Count; i++) { var nameAndSig = factory.NativeLayout.PlacedSignatureVertex(factory.NativeLayout.MethodNameAndSignatureVertex(sortedList[i].Key)); if (factory.Target.SupportsRelativePointers) { objData.EmitInt(nameAndSig.SavedVertex.VertexOffset); objData.EmitReloc(factory.MethodEntrypoint(sortedList[i].Key), RelocType.IMAGE_REL_BASED_RELPTR32); } else { objData.EmitNaturalInt(nameAndSig.SavedVertex.VertexOffset); objData.EmitPointerReloc(factory.MethodEntrypoint(sortedList[i].Key)); } } _endSymbol.SetSymbolOffset(objData.CountBytes); objData.AddSymbol(_endSymbol); // Prevent further adds now we're done writing #if DEBUG if (!relocsOnly) { _dataEmitted = true; } #endif return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.DefinedSymbols.Add(this); objData.RequirePointerAlignment(); objData.EmitZeroPointer(); return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); builder.EmitZeros(_type.ThreadStaticFieldSize.AsInt); builder.AddSymbol(this); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialPointerAlignment(); objData.AddSymbol(this); objData.EmitReloc(factory.ThreadStaticsRegion.StartSymbol, RelocType.IMAGE_REL_SECREL); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialPointerAlignment(); objData.AddSymbol(this); ComputeOptionalEETypeFields(factory, relocsOnly); OutputGCDesc(ref objData); OutputComponentSize(ref objData); OutputFlags(factory, ref objData); OutputBaseSize(ref objData); OutputRelatedType(factory, ref objData); // Number of vtable slots will be only known later. Reseve the bytes for it. var vtableSlotCountReservation = objData.ReserveShort(); // Number of interfaces will only be known later. Reserve the bytes for it. var interfaceCountReservation = objData.ReserveShort(); objData.EmitInt(_type.GetHashCode()); objData.EmitPointerReloc(factory.TypeManagerIndirection); if (EmitVirtualSlotsAndInterfaces) { // Emit VTable Debug.Assert(objData.CountBytes - ((ISymbolDefinitionNode)this).Offset == GetVTableOffset(objData.TargetPointerSize)); SlotCounter virtualSlotCounter = SlotCounter.BeginCounting(ref /* readonly */ objData); OutputVirtualSlots(factory, ref objData, _type, _type, relocsOnly); // Update slot count int numberOfVtableSlots = virtualSlotCounter.CountSlots(ref /* readonly */ objData); objData.EmitShort(vtableSlotCountReservation, checked ((short)numberOfVtableSlots)); // Emit interface map SlotCounter interfaceSlotCounter = SlotCounter.BeginCounting(ref /* readonly */ objData); OutputInterfaceMap(factory, ref objData); // Update slot count int numberOfInterfaceSlots = interfaceSlotCounter.CountSlots(ref /* readonly */ objData); objData.EmitShort(interfaceCountReservation, checked ((short)numberOfInterfaceSlots)); } else { // If we're not emitting any slots, the number of slots is zero. objData.EmitShort(vtableSlotCountReservation, 0); objData.EmitShort(interfaceCountReservation, 0); } OutputFinalizerMethod(factory, ref objData); OutputOptionalFields(factory, ref objData); OutputNullableTypeParameter(factory, ref objData); OutputGenericInstantiationDetails(factory, ref objData); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory, relocsOnly); dataBuilder.RequireInitialPointerAlignment(); dataBuilder.AddSymbol(this); EETypeRareFlags rareFlags = 0; short flags = (short)EETypeKind.GenericTypeDefEEType; if (_type.IsValueType) { flags |= (short)EETypeFlags.ValueTypeFlag; } if (_type.IsInterface) { flags |= (short)EETypeFlags.IsInterfaceFlag; } if (factory.TypeSystemContext.HasLazyStaticConstructor(_type)) { rareFlags = rareFlags | EETypeRareFlags.HasCctorFlag; } if (_type.IsByRefLike) { rareFlags |= EETypeRareFlags.IsByRefLikeFlag; } if (rareFlags != 0) { _optionalFieldsBuilder.SetFieldValue(EETypeOptionalFieldTag.RareFlags, (uint)rareFlags); } if (HasOptionalFields) { flags |= (short)EETypeFlags.OptionalFieldsFlag; } if (_type.IsEnum) { flags |= (short)EETypeBuilderHelpers.ComputeElementTypeFlags(_type); } dataBuilder.EmitShort((short)_type.Instantiation.Length); dataBuilder.EmitShort(flags); dataBuilder.EmitInt(0); // Base size is always 0 dataBuilder.EmitZeroPointer(); // No related type dataBuilder.EmitShort(0); // No VTable dataBuilder.EmitShort(0); // No interface map dataBuilder.EmitInt(_type.GetHashCode()); dataBuilder.EmitPointerReloc(factory.TypeManagerIndirection); if (HasOptionalFields) { dataBuilder.EmitPointerReloc(_optionalFieldsNode); } return(dataBuilder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); // The interface dispatch cell has an alignment requirement of 2 * [Pointer size] as part of the // synchronization mechanism of the two values in the runtime. objData.RequireInitialAlignment(_targetMethod.Context.Target.PointerSize * 2); objData.AddSymbol(this); if (factory.Target.Architecture == TargetArchitecture.ARM) { objData.EmitPointerReloc(factory.InitialInterfaceDispatchStub); } else { objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch")); } if (factory.Target.Abi == TargetAbi.CoreRT) { // TODO: Enable Indirect Pointer for Interface Dispatch Cell. See https://github.com/dotnet/corert/issues/2542 objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), (int)InterfaceDispatchCellCachePointerFlags.CachePointerIsInterfacePointerOrMetadataToken); } else { if (factory.CompilationModuleGroup.ContainsType(_targetMethod.OwningType)) { objData.EmitReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), RelocType.IMAGE_REL_BASED_RELPTR32, (int)InterfaceDispatchCellCachePointerFlags.CachePointerIsInterfaceRelativePointer); } else { objData.EmitReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), RelocType.IMAGE_REL_BASED_RELPTR32, (int)InterfaceDispatchCellCachePointerFlags.CachePointerIsIndirectedInterfaceRelativePointer); } if (objData.TargetPointerSize == 8) { // IMAGE_REL_BASED_RELPTR is a 32-bit relocation. However, the cell needs a full pointer // width there since a pointer to the cache will be written into the cell. Emit additional // 32 bits on targets whose pointer size is 64 bit. objData.EmitInt(0); } } // End the run of dispatch cells objData.EmitZeroPointer(); // Avoid consulting VTable slots until they're guaranteed complete during final data emission if (!relocsOnly) { objData.EmitNaturalInt(VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod)); } return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.DefinedSymbols.Add(this); objData.RequirePointerAlignment(); objData.EmitZeroPointer(); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.RequirePointerAlignment(); builder.EmitPointerReloc(GetGCStaticEETypeNode(factory), 1); builder.DefinedSymbols.Add(this); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialPointerAlignment(); objData.AddSymbol(this); objData.EmitPointerReloc(factory.ReadyToRunHeader); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory); builder.RequirePointerAlignment(); builder.DefinedSymbols.Add(this); builder.EmitPointerReloc(_indirectedNode); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.RequirePointerAlignment(); builder.EmitPointerReloc(GetGCStaticEETypeNode(factory), 1); builder.DefinedSymbols.Add(this); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = 16; dataBuilder.DefinedSymbols.Add(this); bool hasPointers = NumSeries > 0; if (hasPointers) { for (int i = ((_runLengths.Length / 2) * 2) - 1; i >= 0; i--) { if (_targetPointerSize == 4) { dataBuilder.EmitInt(_runLengths[i]); } else { dataBuilder.EmitLong(_runLengths[i]); } } if (_targetPointerSize == 4) { dataBuilder.EmitInt(NumSeries); } else { dataBuilder.EmitLong(NumSeries); } } int totalSize = 0; foreach (int run in _runLengths) { totalSize += run * _targetPointerSize; } dataBuilder.EmitShort(0); // ComponentSize is always 0 if (hasPointers) { dataBuilder.EmitShort(0x20); // TypeFlags.HasPointers } else { dataBuilder.EmitShort(0x00); } totalSize = Math.Max(totalSize, _targetPointerSize * 3); // minimum GC eetype size is 3 pointers dataBuilder.EmitInt(totalSize); return(dataBuilder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory, relocsOnly); builder.RequireInitialPointerAlignment(); builder.AddSymbol(this); builder.EmitPointerReloc(_indirectedNode, _offsetDelta); return(builder.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { Encoding encoding = UTF8Encoding.UTF8; ObjectDataBuilder objDataBuilder = new ObjectDataBuilder(factory); AsmStringWriter stringWriter = new AsmStringWriter((byte b) => objDataBuilder.EmitByte(b)); stringWriter.WriteString(_data); objDataBuilder.DefinedSymbols.Add(this); return objDataBuilder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { Debug.Assert(factory.Target.IsWindows); ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly); objData.RequireInitialAlignment(factory.Target.MinimumFunctionAlignment); objData.AddSymbol(this); return(objData.ToObjectData()); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = factory.Target.PointerSize; objData.DefinedSymbols.Add(this); foreach (var map in _dispatchMaps) { objData.EmitPointerReloc(map); } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.RequirePointerAlignment(); objData.DefinedSymbols.Add(this); if (!relocsOnly) { objData.EmitBytes(_owner.GetOptionalFieldsData()); } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); // // Emit a MethodFixupCell struct // builder.EmitZeroPointer(); builder.EmitPointerReloc(factory.ConstantUtf8String(_entryPointName)); builder.EmitPointerReloc(factory.PInvokeModuleFixup(_moduleName)); return builder.ToObjectData(); }
public sealed override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); builder.RequirePointerAlignment(); // Node representing the generic dictionary doesn't have any dependencies for // dependency analysis purposes. The dependencies are tracked as dependencies of the // concrete method bodies. When we reach the object data emission phase, the dependencies // should all already have been marked. if (!relocsOnly) { EmitDataInternal(ref builder, factory); } return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); ISymbolNode nameSymbol = factory.Target.IsWindows ? factory.ConstantUtf16String(_moduleName) : factory.ConstantUtf8String(_moduleName); // // Emit a ModuleFixupCell struct // builder.EmitZeroPointer(); builder.EmitPointerReloc(nameSymbol); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); // // Emit a MethodFixupCell struct // builder.EmitZeroPointer(); int entryPointBytesCount = Encoding.UTF8.GetByteCount(_entryPointName); byte[] entryPointNameBytes = new byte[entryPointBytesCount + 1]; Encoding.UTF8.GetBytes(_entryPointName, 0, _entryPointName.Length, entryPointNameBytes, 0); builder.EmitPointerReloc(factory.ReadOnlyDataBlob("__pinvokename_" + _entryPointName, entryPointNameBytes, 1)); builder.EmitPointerReloc(factory.PInvokeModuleFixup(_moduleName)); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.DefinedSymbols.Add(this); // // Emit a ModuleFixupCell struct // builder.EmitZeroPointer(); Encoding encoding = factory.Target.IsWindows ? Encoding.Unicode : Encoding.UTF8; int moduleNameBytesCount = encoding.GetByteCount(_moduleName); byte[] moduleNameBytes = new byte[moduleNameBytesCount + 2]; encoding.GetBytes(_moduleName, 0, _moduleName.Length, moduleNameBytes, 0); builder.EmitPointerReloc(factory.ReadOnlyDataBlob("__modulename_" + _moduleName, moduleNameBytes, 2)); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = 16; dataBuilder.DefinedSymbols.Add(this); short flags = (short)EETypeKind.GenericTypeDefEEType; if (_type.IsValueType) flags |= (short)EETypeFlags.ValueTypeFlag; if (_type.IsInterface) flags |= (short)EETypeFlags.IsInterfaceFlag; dataBuilder.EmitShort((short)_type.Instantiation.Length); dataBuilder.EmitShort(flags); dataBuilder.EmitInt(0); // Base size is always 0 dataBuilder.EmitZeroPointer(); // No related type dataBuilder.EmitShort(0); // No VTable dataBuilder.EmitShort(0); // No interface map dataBuilder.EmitInt(_type.GetHashCode()); dataBuilder.EmitPointerReloc(factory.ModuleManagerIndirection); return dataBuilder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = dataBuilder.TargetPointerSize; dataBuilder.DefinedSymbols.Add(this); EETypeRareFlags rareFlags = 0; short flags = (short)EETypeKind.GenericTypeDefEEType; if (_type.IsValueType) flags |= (short)EETypeFlags.ValueTypeFlag; if (_type.IsInterface) flags |= (short)EETypeFlags.IsInterfaceFlag; if (factory.TypeSystemContext.HasLazyStaticConstructor(_type)) rareFlags = rareFlags | EETypeRareFlags.HasCctorFlag; if (rareFlags != 0) _optionalFieldsBuilder.SetFieldValue(EETypeOptionalFieldTag.RareFlags, (uint)rareFlags); if (_optionalFieldsBuilder.IsAtLeastOneFieldUsed()) flags |= (short)EETypeFlags.OptionalFieldsFlag; dataBuilder.EmitShort((short)_type.Instantiation.Length); dataBuilder.EmitShort(flags); dataBuilder.EmitInt(0); // Base size is always 0 dataBuilder.EmitZeroPointer(); // No related type dataBuilder.EmitShort(0); // No VTable dataBuilder.EmitShort(0); // No interface map dataBuilder.EmitInt(_type.GetHashCode()); dataBuilder.EmitPointerReloc(factory.ModuleManagerIndirection); if (_optionalFieldsBuilder.IsAtLeastOneFieldUsed()) { dataBuilder.EmitPointerReloc(factory.EETypeOptionalFields(_optionalFieldsBuilder)); } return dataBuilder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, new ISymbolNode[] { this }); ObjectDataBuilder builder = new ObjectDataBuilder(factory); foreach (var mappingEntry in factory.MetadataManager.GetTypeDefinitionMapping()) { if (!factory.CompilationModuleGroup.ContainsType(mappingEntry.Entity)) continue; var node = factory.ConstructedTypeSymbol(mappingEntry.Entity) as EETypeNode; if (node.Marked) { // TODO: this format got very inefficient due to not being able to use RVAs // replace with a hash table builder.EmitPointerReloc(node); builder.EmitInt(mappingEntry.MetadataHandle); if (factory.Target.PointerSize == 8) builder.EmitInt(0); // Pad } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.DefinedSymbols.Add(this); builder.DefinedSymbols.Add(_endSymbol); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = 16; objData.DefinedSymbols.Add(this); if (_type.IsArray) { objData.EmitShort((short)((ArrayType)_type).ElementType.GetElementSize()); // m_ComponentSize objData.EmitShort(0x4); // m_flags: IsArray(0x4) } else if (_type.IsString) { objData.EmitShort(2); // m_ComponentSize objData.EmitShort(0); // m_flags: 0 } else { objData.EmitShort(0); // m_ComponentSize objData.EmitShort(0); // m_flags: 0 } int pointerSize = _type.Context.Target.PointerSize; int minimumObjectSize = pointerSize * 3; int objectSize; if (_type is MetadataType) { objectSize = pointerSize + ((MetadataType)_type).InstanceByteCount; // +pointerSize for SyncBlock } else if (_type is ArrayType) { objectSize = 3 * pointerSize; // SyncBlock + EETypePtr + Length int rank = ((ArrayType)_type).Rank; if (rank > 1) objectSize += 2 * _type.Context.GetWellKnownType(WellKnownType.Int32).GetElementSize() * rank; } else throw new NotImplementedException(); objectSize = AlignmentHelper.AlignUp(objectSize, pointerSize); objectSize = Math.Max(minimumObjectSize, objectSize); if (_type.IsString) { // If this is a string, throw away objectSize we computed so far. Strings are special. // SyncBlock + EETypePtr + length + firstChar objectSize = 2 * pointerSize + _type.Context.GetWellKnownType(WellKnownType.Int32).GetElementSize() + _type.Context.GetWellKnownType(WellKnownType.Char).GetElementSize(); } objData.EmitInt(objectSize); if (Type.BaseType != null) { if (_constructed) { objData.EmitPointerReloc(factory.ConstructedTypeSymbol(Type.BaseType)); } else { objData.EmitPointerReloc(factory.NecessaryTypeSymbol(Type.BaseType)); } } else { objData.EmitZeroPointer(); } if (_constructed) { OutputVirtualSlots(ref objData, _type, _type, factory); } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); // If the type has a class constructor, it's non-GC statics section is prefixed // by System.Runtime.CompilerServices.StaticClassConstructionContext struct. if (HasClassConstructorContext) { int alignmentRequired = Math.Max(_type.NonGCStaticFieldAlignment, ClassConstructorContextAlignment); builder.RequireAlignment(alignmentRequired); Debug.Assert(((ISymbolNode)this).Offset >= ClassConstructorContextSize); // Add padding before the context if alignment forces us to do so builder.EmitZeros(((ISymbolNode)this).Offset - ClassConstructorContextSize); // Emit the actual StaticClassConstructionContext var cctorMethod = _type.GetStaticConstructor(); builder.EmitPointerReloc(factory.MethodEntrypoint(cctorMethod)); builder.EmitZeroPointer(); builder.DefinedSymbols.Add(_classConstructorContext); } else { builder.RequireAlignment(_type.NonGCStaticFieldAlignment); } builder.EmitZeros(_type.NonGCStaticFieldSize); builder.DefinedSymbols.Add(this); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = objData.TargetPointerSize; objData.DefinedSymbols.Add(this); ComputeOptionalEETypeFields(factory); OutputGCDesc(ref objData); OutputComponentSize(ref objData); OutputFlags(factory, ref objData); OutputBaseSize(ref objData); OutputRelatedType(factory, ref objData); // Avoid consulting VTable slots until they're guaranteed complete during final data emission if (!relocsOnly) { OutputVirtualSlotAndInterfaceCount(factory, ref objData); } objData.EmitInt(_type.GetHashCode()); objData.EmitPointerReloc(factory.TypeManagerIndirection); // Avoid consulting VTable slots until they're guaranteed complete during final data emission if (!relocsOnly) { OutputVirtualSlots(factory, ref objData, _type, _type); } OutputInterfaceMap(factory, ref objData); OutputFinalizerMethod(factory, ref objData); OutputOptionalFields(factory, ref objData); OutputNullableTypeParameter(factory, ref objData); OutputGenericInstantiationDetails(factory, ref objData); return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = 16; dataBuilder.DefinedSymbols.Add(this); bool hasPointers = NumSeries > 0; if (hasPointers) { for (int i = ((_runLengths.Length / 2) * 2) - 1; i >= 0; i--) { if (_targetPointerSize == 4) { dataBuilder.EmitInt(_runLengths[i]); } else { dataBuilder.EmitLong(_runLengths[i]); } } if (_targetPointerSize == 4) { dataBuilder.EmitInt(NumSeries); } else { dataBuilder.EmitLong(NumSeries); } } int totalSize = 0; foreach (int run in _runLengths) { totalSize += run * _targetPointerSize; } dataBuilder.EmitShort(0); // ComponentSize is always 0 if (hasPointers) dataBuilder.EmitShort(0x20); // TypeFlags.HasPointers else dataBuilder.EmitShort(0x00); totalSize = Math.Max(totalSize, _targetPointerSize * 3); // minimum GC eetype size is 3 pointers dataBuilder.EmitInt(totalSize); return dataBuilder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder builder = new ObjectDataBuilder(factory); builder.Alignment = factory.Target.PointerSize; builder.DefinedSymbols.Add(this); // Don't bother sorting if we're not emitting the contents if (!relocsOnly) _items.Sort((x, y) => Comparer<int>.Default.Compare((int)x.Id, (int)y.Id)); // ReadyToRunHeader.Magic builder.EmitInt((int)(ReadyToRunHeaderConstants.Signature)); // ReadyToRunHeader.MajorVersion builder.EmitShort((short)(ReadyToRunHeaderConstants.CurrentMajorVersion)); builder.EmitShort((short)(ReadyToRunHeaderConstants.CurrentMinorVersion)); // ReadyToRunHeader.Flags builder.EmitInt(0); // ReadyToRunHeader.NumberOfSections var sectionCountReservation = builder.ReserveShort(); // ReadyToRunHeader.EntrySize builder.EmitByte((byte)(8 + 2 * factory.Target.PointerSize)); // ReadyToRunHeader.EntryType builder.EmitByte(1); int count = 0; foreach (var item in _items) { // Skip empty entries if (item.Node.ShouldSkipEmittingObjectNode(factory)) continue; builder.EmitInt((int)item.Id); ModuleInfoFlags flags = 0; if (item.EndSymbol != null) { flags |= ModuleInfoFlags.HasEndPointer; } builder.EmitInt((int)flags); builder.EmitPointerReloc(item.StartSymbol); if (item.EndSymbol != null) { builder.EmitPointerReloc(item.EndSymbol); } else { builder.EmitZeroPointer(); } count++; } builder.EmitShort(sectionCountReservation, checked((short)count)); return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = 16; objData.DefinedSymbols.Add(this); if (!relocsOnly) { var entries = BuildDispatchMap(factory); objData.EmitInt(entries.Length); foreach (var entry in entries) { objData.EmitShort(entry.InterfaceIndex); objData.EmitShort(entry.InterfaceMethodSlot); objData.EmitShort(entry.ImplementationMethodSlot); } } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = 16; objData.DefinedSymbols.Add(this); // Todo: Generic Type Definition EETypes // Early-out just to prevent crashing at compile time... if (_type.HasInstantiation && _type.IsTypeDefinition) { objData.EmitZeroPointer(); return objData.ToObjectData(); } ComputeOptionalEETypeFields(factory); OutputComponentSize(ref objData); OutputFlags(factory, ref objData); OutputBaseSize(ref objData); OutputRelatedType(factory, ref objData); OutputVirtualSlotAndInterfaceCount(factory, ref objData); objData.EmitInt(_type.GetHashCode()); if (_constructed) { OutputVirtualSlots(factory, ref objData, _type, _type); OutputInterfaceMap(factory, ref objData); } OutputFinalizerMethod(factory, ref objData); OutputOptionalFields(factory, ref objData); OutputNullableTypeParameter(factory, ref objData); return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = 16; dataBuilder.DefinedSymbols.Add(this); // +2 for SyncBlock and EETypePtr field int totalSize = (_gcMap.Size + 2) * _target.PointerSize; // We only need to check for containsPointers because ThreadStatics are always allocated // on the GC heap (no matter what "HasGCStaticBase" says). // If that ever changes, we can assume "true" and switch this to an assert. bool containsPointers = _gcMap.NumSeries > 0; if (containsPointers) { GCDescEncoder.EncodeStandardGCDesc(ref dataBuilder, _gcMap, totalSize, 0); } Debug.Assert(dataBuilder.CountBytes == ((ISymbolNode)this).Offset); dataBuilder.EmitShort(0); // ComponentSize is always 0 short flags = 0; if (containsPointers) flags |= (short)EETypeFlags.HasPointersFlag; dataBuilder.EmitShort(flags); totalSize = Math.Max(totalSize, _target.PointerSize * 3); // minimum GC eetype size is 3 pointers dataBuilder.EmitInt(totalSize); // This is just so that EEType::Validate doesn't blow up at runtime dataBuilder.EmitPointerReloc(this); // Related type: itself return dataBuilder.ToObjectData(); }
private ObjectNode.ObjectData EncodeEHInfo() { var builder = new ObjectDataBuilder(); builder.Alignment = 1; // TODO: Filter out duplicate clauses builder.EmitCompressedUInt((uint)_ehClauses.Length); for (int i = 0; i < _ehClauses.Length; i++) { var clause = _ehClauses[i]; RhEHClauseKind clauseKind; if (((clause.Flags & CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FAULT) != 0) || ((clause.Flags & CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FINALLY) != 0)) { clauseKind = RhEHClauseKind.RH_EH_CLAUSE_FAULT; } else if ((clause.Flags & CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FILTER) != 0) { clauseKind = RhEHClauseKind.RH_EH_CLAUSE_FILTER; } else { clauseKind = RhEHClauseKind.RH_EH_CLAUSE_TYPED; } builder.EmitCompressedUInt((uint)clause.TryOffset); // clause.TryLength returned by the JIT is actually end offset... // https://github.com/dotnet/coreclr/issues/3585 int tryLength = (int)clause.TryLength - (int)clause.TryOffset; builder.EmitCompressedUInt((uint)((tryLength << 2) | (int)clauseKind)); switch (clauseKind) { case RhEHClauseKind.RH_EH_CLAUSE_TYPED: { builder.EmitCompressedUInt(clause.HandlerOffset); var methodIL = (MethodIL)HandleToObject((IntPtr)_methodScope); var type = (TypeDesc)methodIL.GetObject((int)clause.ClassTokenOrOffset); var typeSymbol = _compilation.NodeFactory.NecessaryTypeSymbol(type); RelocType rel = (_compilation.NodeFactory.Target.IsWindows) ? RelocType.IMAGE_REL_BASED_ABSOLUTE : RelocType.IMAGE_REL_BASED_REL32; builder.EmitReloc(typeSymbol, rel); } break; case RhEHClauseKind.RH_EH_CLAUSE_FAULT: builder.EmitCompressedUInt(clause.HandlerOffset); break; case RhEHClauseKind.RH_EH_CLAUSE_FILTER: builder.EmitCompressedUInt(clause.HandlerOffset); builder.EmitCompressedUInt(clause.ClassTokenOrOffset); break; } } return builder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { ObjectDataBuilder objData = new ObjectDataBuilder(factory); objData.Alignment = 16; objData.DefinedSymbols.Add(this); if (!relocsOnly) { EmitDispatchMap(ref objData, factory); } return objData.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly) { ObjectDataBuilder dataBuilder = new ObjectDataBuilder(factory); dataBuilder.Alignment = 16; dataBuilder.DefinedSymbols.Add(this); // +2 for SyncBlock and EETypePtr field int totalSize = (_gcMap.Size + 2) * _target.PointerSize; // We only need to check for containsPointers because ThreadStatics are always allocated // on the GC heap (no matter what "HasGCStaticBase" says). // If that ever changes, we can assume "true" and switch this to an assert. bool containsPointers = _gcMap.NumSeries > 0; if (containsPointers) { GCDescEncoder.EncodeStandardGCDesc(ref dataBuilder, _gcMap, totalSize, 0); } Debug.Assert(dataBuilder.CountBytes == Offset); dataBuilder.EmitShort(0); // ComponentSize is always 0 short flags = 0; if (containsPointers) flags |= (short)EETypeFlags.HasPointersFlag; dataBuilder.EmitShort(flags); totalSize = Math.Max(totalSize, _target.PointerSize * 3); // minimum GC eetype size is 3 pointers dataBuilder.EmitInt(totalSize); // Related type: System.Object. This allows storing an instance of this type in an array of objects. dataBuilder.EmitPointerReloc(factory.NecessaryTypeSymbol(factory.TypeSystemContext.GetWellKnownType(WellKnownType.Object))); return dataBuilder.ToObjectData(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, new ISymbolNode[] { this }); ObjectDataBuilder builder = new ObjectDataBuilder(factory); foreach (var mappingEntry in factory.MetadataManager.GetTypeDefinitionMapping()) { if (!factory.CompilationModuleGroup.ContainsType(mappingEntry.Entity)) continue; // We are looking for any EEType - constructed or not, it has to be in the mapping // table so that we can map it to metadata. EETypeNode node = null; if (!mappingEntry.Entity.IsGenericDefinition) { node = factory.ConstructedTypeSymbol(mappingEntry.Entity) as EETypeNode; } if (node == null || !node.Marked) { // This might have been a typeof() expression. node = factory.NecessaryTypeSymbol(mappingEntry.Entity) as EETypeNode; } if (node.Marked) { // TODO: this format got very inefficient due to not being able to use RVAs // replace with a hash table builder.EmitPointerReloc(node); builder.EmitInt(mappingEntry.MetadataHandle); if (factory.Target.PointerSize == 8) builder.EmitInt(0); // Pad } } _endSymbol.SetSymbolOffset(builder.CountBytes); builder.DefinedSymbols.Add(this); builder.DefinedSymbols.Add(_endSymbol); return builder.ToObjectData(); }