Exemplo n.º 1
0
        public int GetStringAddress(string s, target.Target t)
        {
            if (str_addrs.ContainsKey(s))
            {
                return(str_addrs[s]);
            }
            else
            {
                var ptr_size = t.GetCTSize(ir.Opcode.ct_object);
                while (str_tab.Count % ptr_size != 0)
                {
                    str_tab.Add(0);
                }

                int ret = str_tab.Count;
                str_addrs.Add(s, ret);

                //int string_obj_len = layout.Layout.GetTypeSize(StringObject,
                //    t, false);
                //int string_type_offset =

                int i = 0;
                for (; i < length_offset; i++)
                {
                    str_tab.Add(0);
                }
                int len = s.Length;
                str_tab.Add((byte)(len & 0xff));
                str_tab.Add((byte)((len >> 8) & 0xff));
                str_tab.Add((byte)((len >> 16) & 0xff));
                str_tab.Add((byte)((len >> 24) & 0xff));
                i += 4;
                for (; i < string_obj_len; i++)
                {
                    str_tab.Add(0);
                }

                foreach (char c in s)
                {
                    str_tab.Add((byte)(c & 0xff));
                    str_tab.Add((byte)((c >> 8) & 0xff));
                }

                // null-terminate and align up to ensure coreclr String.EqualsHelper works
                str_tab.Add(0);
                str_tab.Add(0);
                while ((str_tab.Count % t.GetPointerSize()) != 0)
                {
                    str_tab.Add(0);
                }
                return(ret);
            }
        }
Exemplo n.º 2
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.º 3
0
        public int GetSignatureAddress(metadata.TypeSpec.FullySpecSignature sig, target.Target t, TysilaState s)
        {
            var ptr_size = t.GetCTSize(ir.Opcode.ct_object);

            while (str_tab.Count % ptr_size != 0)
            {
                str_tab.Add(0);
            }

            int ret = str_tab.Count;

            // first is type of signature
            str_tab.AddRange(t.IntPtrArray(BitConverter.GetBytes((int)sig.Type)));

            // then any extra data if necessary
            switch (sig.Type)
            {
            case metadata.Spec.FullySpecSignature.FSSType.Field:
                // For fields with static data we insert it here
                AddFieldSpecFields(sig.OriginalSpec as MethodSpec, str_tab, t, s);
                break;

            case Spec.FullySpecSignature.FSSType.Type:
                AddTypeSpecFields(sig.OriginalSpec as TypeSpec, str_tab, t, s);
                break;
            }

            // then is length of module references
            str_tab.AddRange(t.IntPtrArray(BitConverter.GetBytes(sig.Modules.Count)));

            // then module references
            foreach (var mod in sig.Modules)
            {
                sig_metadata_addrs[str_tab.Count] = mod.AssemblyName;
                for (int i = 0; i < ptr_size; i++)
                {
                    str_tab.Add(0);
                }
            }

            // then signature
            str_tab.AddRange(sig.Signature);

            return(ret);
        }
Exemplo n.º 4
0
        public int GetSignatureAddress(IEnumerable <byte> sig, target.Target t, TysilaState s)
        {
            var ptr_size = t.GetCTSize(ir.Opcode.ct_object);

            while (str_tab.Count % ptr_size != 0)
            {
                str_tab.Add(0);
            }

            int ret = str_tab.Count;

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

            return(ret);
        }
Exemplo n.º 5
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;
        }