示例#1
0
        protected void EmitRelocationAddend(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 relocationAddendEntry = new RelocationAddendEntry()
                    {
                        RelocationType = ConvertType(patch.LinkType, linker.MachineType),
                        Symbol         = symbolTableOffset[symbol],
                        Offset         = (ulong)patch.PatchOffset,
                        Addend         = (ulong)patch.ReferenceOffset,
                    };

                    relocationAddendEntry.Write(linkerFormatType, writer);

                    count++;
                }
            }

            section.Size = (uint)(count * RelocationAddendEntry.GetEntrySize(linkerFormatType));
        }
示例#2
0
        private void EmitRelocationAddend(Section section, BinaryWriter writer)
        {
            int count = 0;

            foreach (var symbol in linker.Symbols)
            {
                //if (symbol.SectionKind != section.SectionKind)
                //	continue;

                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;
                    }

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

                    relocationAddendEntry.Write(linkerFormatType, writer);

                    count++;
                }
            }

            section.Size = (uint)(count * RelocationAddendEntry.GetEntrySize(linkerFormatType));
        }
示例#3
0
        private Stream EmitRelocationAddendSection(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 relocationAddendEntry = new RelocationAddendEntry()
                    {
                        RelocationType = ConvertType(MachineType, patch.LinkType, patch.PatchType),
                        Symbol         = symbolTableOffset[patch.ReferenceSymbol],
                        Offset         = (ulong)(symbol.SectionOffset + patch.PatchOffset),
                        Addend         = (ulong)patch.ReferenceOffset,
                    };

                    relocationAddendEntry.Write(LinkerFormatType, writer);
                }
            }

            return(stream);
        }