Exemplo n.º 1
0
        public void WriteToOutput(binary_library.IBinaryFile of,
                                  metadata.MetadataStream ms, target.Target t,
                                  binary_library.ISection rd = null)
        {
            if (str_tab.Count == 0)
            {
                return;
            }

            if (rd == null)
            {
                rd = of.GetRDataSection();
            }
            rd.Align(t.GetCTSize(ir.Opcode.ct_object));

            var stab_lab = of.CreateSymbol();

            stab_lab.Name       = Label;
            stab_lab.ObjectType = binary_library.SymbolObjectType.Object;
            stab_lab.Offset     = (ulong)rd.Data.Count;
            stab_lab.Type       = binary_library.SymbolType.Weak;
            rd.AddSymbol(stab_lab);

            int stab_base = rd.Data.Count;

            foreach (byte b in str_tab)
            {
                rd.Data.Add(b);
            }

            foreach (var kvp in sig_metadata_addrs)
            {
                var reloc = of.CreateRelocation();
                reloc.DefinedIn = rd;
                reloc.Type      = t.GetDataToDataReloc();
                reloc.Addend    = 0;

                if (sig_metadata_addends.ContainsKey(kvp.Key))
                {
                    reloc.Addend = sig_metadata_addends[kvp.Key];
                }

                var md_lab = of.CreateSymbol();
                md_lab.Name       = kvp.Value;
                md_lab.ObjectType = binary_library.SymbolObjectType.Object;

                reloc.References = md_lab;
                reloc.Offset     = (ulong)(kvp.Key + stab_base);
                of.AddRelocation(reloc);
            }

            stab_lab.Size = rd.Data.Count - (int)stab_lab.Offset;
        }
Exemplo n.º 2
0
        public void WriteToOutput(binary_library.IBinaryFile of,
                                  metadata.MetadataStream ms, target.Target t)
        {
            var rd = of.GetRDataSection();

            rd.Align(t.GetCTSize(ir.Opcode.ct_object));

            var stab_lab = GetStringTableSymbol(of);

            stab_lab.Name       = Label;
            stab_lab.ObjectType = binary_library.SymbolObjectType.Object;
            stab_lab.Offset     = (ulong)rd.Data.Count;
            stab_lab.Type       = binary_library.SymbolType.Global;
            rd.AddSymbol(stab_lab);

            int stab_base = rd.Data.Count;

            foreach (byte b in str_tab)
            {
                rd.Data.Add(b);
            }

            var str_lab = of.CreateSymbol();

            str_lab.Name       = StringObject.m.MangleType(StringObject);
            str_lab.ObjectType = binary_library.SymbolObjectType.Object;

            foreach (var str_addr in str_addrs.Values)
            {
                var reloc = of.CreateRelocation();
                reloc.DefinedIn  = rd;
                reloc.Type       = t.GetDataToDataReloc();
                reloc.Addend     = 0;
                reloc.References = str_lab;
                reloc.Offset     = (ulong)(str_addr + stab_base);
                of.AddRelocation(reloc);
            }

            stab_lab.Size = rd.Data.Count - (int)stab_lab.Offset;
        }
Exemplo n.º 3
0
        public static void OutputEHdr(MethodSpecWithEhdr ms,
                                      Target t, binary_library.IBinaryFile of,
                                      TysilaState s,
                                      MetadataStream base_m      = null,
                                      binary_library.ISection os = null)
        {
            // Don't compile if not for this architecture
            if (!t.IsMethodValid(ms.ms))
            {
                return;
            }

            if (os == null)
            {
                os = of.GetRDataSection();
            }
            os.Align(t.GetPointerSize());
            var d = os.Data;

            /* Symbol */
            var sym = of.CreateSymbol();

            sym.Name       = ms.ms.MangleMethod() + "EH";
            sym.ObjectType = binary_library.SymbolObjectType.Object;
            sym.Offset     = (ulong)d.Count;
            sym.Type       = binary_library.SymbolType.Global;
            os.AddSymbol(sym);

            if (base_m != null && ms.ms.m != base_m)
            {
                sym.Type = binary_library.SymbolType.Weak;
            }

            foreach (var ehdr in ms.c.ehdrs)
            {
                var v = t.IntPtrArray(BitConverter.GetBytes((int)ehdr.EType));
                foreach (var b in v)
                {
                    d.Add(b);
                }

                /* Handler */
                var hand_sym = of.CreateSymbol();
                hand_sym.Name = ms.ms.MangleMethod() + "EH" + ehdr.EhdrIdx.ToString();

                var hand_reloc = of.CreateRelocation();
                hand_reloc.Addend     = 0;
                hand_reloc.DefinedIn  = os;
                hand_reloc.Offset     = (ulong)d.Count;
                hand_reloc.References = hand_sym;
                hand_reloc.Type       = t.GetDataToCodeReloc();
                of.AddRelocation(hand_reloc);

                for (int i = 0; i < t.GetPointerSize(); i++)
                {
                    d.Add(0);
                }

                /* Catch object */
                if (ehdr.ClassToken != null)
                {
                    var catch_sym = of.CreateSymbol();
                    catch_sym.Name = ehdr.ClassToken.MangleType();

                    var catch_reloc = of.CreateRelocation();
                    catch_reloc.Addend     = 0;
                    catch_reloc.DefinedIn  = os;
                    catch_reloc.Offset     = (ulong)d.Count;
                    catch_reloc.References = catch_sym;
                    catch_reloc.Type       = t.GetDataToDataReloc();
                    of.AddRelocation(catch_reloc);

                    s.r.VTableRequestor.Request(ehdr.ClassToken);
                }
                else if (ehdr.EType == ExceptionHeader.ExceptionHeaderType.Filter)
                {
                    var filt_sym = of.CreateSymbol();
                    filt_sym.Name = ms.ms.MangleMethod() + "EHF" + ehdr.EhdrIdx.ToString();

                    var filt_reloc = of.CreateRelocation();
                    filt_reloc.Addend     = 0;
                    filt_reloc.DefinedIn  = os;
                    filt_reloc.Offset     = (ulong)d.Count;
                    filt_reloc.References = filt_sym;
                    filt_reloc.Type       = t.GetDataToCodeReloc();
                    of.AddRelocation(filt_reloc);
                }
                for (int i = 0; i < t.GetPointerSize(); i++)
                {
                    d.Add(0);
                }
            }

            sym.Size = (long)((ulong)d.Count - sym.Offset);
        }