Exemple #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));
        }
        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));
        }
Exemple #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);
        }
Exemple #4
0
        private void RegisterRelocationSection(SectionKind kind, bool addend)
        {
            var relocationSection = new Section()
            {
                Name      = (addend ? ".rela" : ".rel") + SectionNames[(int)kind],
                Type      = addend ? SectionType.RelocationA : SectionType.Relocation,
                Link      = symbolSection,
                Info      = GetSection(kind),
                EntrySize = addend ? RelocationAddendEntry.GetEntrySize(LinkerFormatType) : RelocationEntry.GetEntrySize(LinkerFormatType),
                Emitter   = () => { return(addend ? EmitRelocationAddendSection(kind) : EmitRelocationSection(kind)); }
            };

            RegisterSection(relocationSection);

            relocationSection.AddDependency(symbolSection);
            relocationSection.AddDependency(GetSection(kind));
        }
        private void CreateRelocationSection(SectionKind kind, bool addend)
        {
            var relocationSection = new Section()
            {
                Name             = (addend ? ".rela" : ".rel") + LinkerSectionNames[(int)kind],
                Type             = addend ? SectionType.RelocationA : SectionType.Relocation,
                Link             = symbolSection,
                Info             = GetSection(kind),
                AddressAlignment = linker.SectionAlignment,
                EntrySize        = addend ? RelocationAddendEntry.GetEntrySize(linkerFormatType) : RelocationEntry.GetEntrySize(linkerFormatType),
                EmitMethod       = WriteRelocationSection
            };

            AddSection(relocationSection);

            relocationSection.AddDependency(symbolSection);
            relocationSection.AddDependency(GetSection(kind));
        }