예제 #1
0
        protected void EmitRelocation(LinkerSection linkerSection, Section section)
        {
            int count = 0;

            foreach (var symbol in linkerSection.Symbols)
            {
                foreach (var patch in symbol.LinkRequests)
                {
                    if (patch.ReferenceOffset != 0)
                    {
                        continue;
                    }

                    if (patch.LinkType == LinkType.Size)
                    {
                        continue;
                    }

                    var relocationEntry = new RelocationEntry()
                    {
                        RelocationType = ConvertType(patch.LinkType, linker.MachineType),
                        Symbol         = symbolTableOffset[symbol],
                        Offset         = (ulong)patch.PatchOffset,
                    };

                    relocationEntry.Write(linkerFormatType, writer);
                    count++;
                }

                section.Size = (uint)(count * RelocationEntry.GetEntrySize(linkerFormatType));
            }
        }
예제 #2
0
        private void EmitRelocation(Section section, BinaryWriter writer)
        {
            int count = 0;

            foreach (var symbol in linker.Symbols)
            {
                if (symbol.IsExternalSymbol)
                {
                    continue;
                }

                foreach (var patch in symbol.LinkRequests)
                {
                    if (patch.ReferenceOffset != 0)
                    {
                        continue;
                    }

                    if (patch.ReferenceSymbol.SectionKind != section.SectionKind)
                    {
                        continue;
                    }

                    if (patch.LinkType == LinkType.Size)
                    {
                        continue;
                    }

                    if (!patch.ReferenceSymbol.IsExternalSymbol)                     // FUTURE: include relocations for static symbols, if option selected
                    {
                        continue;
                    }

                    Debug.Assert(symbolTableOffset.ContainsKey(patch.ReferenceSymbol));

                    var relocationEntry = new RelocationEntry()
                    {
                        RelocationType = ConvertType(linker.MachineType, patch.LinkType, patch.PatchType),
                        Symbol         = symbolTableOffset[patch.ReferenceSymbol],
                        Offset         = (ulong)(symbol.SectionOffset + patch.PatchOffset),
                    };

                    relocationEntry.Write(linkerFormatType, writer);
                    count++;
                }

                section.Size = (uint)(count * RelocationEntry.GetEntrySize(linkerFormatType));
            }
        }
예제 #3
0
        private Stream EmitRelocationSection(SectionKind kind)
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            foreach (var symbol in Linker.Symbols)
            {
                if (symbol.IsExternalSymbol)
                {
                    continue;
                }

                foreach (var patch in symbol.LinkRequests)
                {
                    if (patch.ReferenceOffset != 0)
                    {
                        continue;
                    }

                    if (patch.ReferenceSymbol.SectionKind != kind)
                    {
                        continue;
                    }

                    if (patch.LinkType == LinkType.Size)
                    {
                        continue;
                    }

                    if (!patch.ReferenceSymbol.IsExternalSymbol)                     // FUTURE: include relocations for static symbols, if option selected
                    {
                        continue;
                    }

                    var relocationEntry = new RelocationEntry()
                    {
                        RelocationType = ConvertType(MachineType, patch.LinkType, patch.PatchType),
                        Symbol         = symbolTableOffset[patch.ReferenceSymbol],
                        Offset         = (ulong)(symbol.SectionOffset + patch.PatchOffset),
                    };

                    relocationEntry.Write(LinkerFormatType, writer);
                }
            }

            return(stream);
        }