From e329eea055de8e018966c81d6e72075fb73a67f4 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sat, 13 Oct 2018 21:01:28 -0700 Subject: [PATCH] convert aa.c to aarray.d --- src/dmd/backend/aa.c | 6 +- src/dmd/backend/aa.h | 20 ++ src/dmd/backend/aarray.d | 545 +++++++++++++++++++++++++++++++++++++++ src/dmd/backend/dwarf.c | 264 ++----------------- src/dmd/backend/elfobj.c | 69 ++--- src/posix.mak | 4 +- src/win32.mak | 2 +- 7 files changed, 632 insertions(+), 278 deletions(-) create mode 100644 src/dmd/backend/aarray.d diff --git a/src/dmd/backend/aa.c b/src/dmd/backend/aa.c index f06510d954b9..bc3e8069ad36 100644 --- a/src/dmd/backend/aa.c +++ b/src/dmd/backend/aa.c @@ -2,7 +2,7 @@ * Compiler implementation of the * $(LINK2 http://www.dlang.org, D programming language). * - * Copyright: Copyright (C) 2000-2018 by The D Language Foundation, All Rights Reserved + * Copyright: Copyright (c) 2000-2017 by Digital Mars, All Rights Reserved * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/aa.c, backend/aa.c) @@ -14,6 +14,8 @@ #include #include +#if 0 + #include "tinfo.h" #include "aa.h" @@ -507,3 +509,5 @@ int AArray::apply_x(aaA* e, dg2_t dg, size_t aligned_keysize, void *parameter) return result; } + +#endif diff --git a/src/dmd/backend/aa.h b/src/dmd/backend/aa.h index f20e77ce4ed1..ca1ee760eaa2 100644 --- a/src/dmd/backend/aa.h +++ b/src/dmd/backend/aa.h @@ -12,6 +12,25 @@ #ifndef AA_H #define AA_H +#if 1 + +struct AAchars +{ + static AAchars* create(); + static void destroy(AAchars*); + uint* get(const char *s, unsigned len); + uint length(); +}; + +struct AApair +{ + static AApair* create(unsigned char** pbase); + static void destroy(AApair*); + uint* get(uint start, uint end); + uint length(); +}; + +#else #include #include "tinfo.h" @@ -106,4 +125,5 @@ struct AArray }; #endif +#endif diff --git a/src/dmd/backend/aarray.d b/src/dmd/backend/aarray.d new file mode 100644 index 000000000000..9070d8f72ed7 --- /dev/null +++ b/src/dmd/backend/aarray.d @@ -0,0 +1,545 @@ +/** + * Compiler implementation of the + * $(LINK2 http://www.dlang.org, D programming language). + * + * Copyright: Copyright (c) 2000-2018 by Digital Mars, All Rights Reserved + * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright), Dave Fladebo + * License: Distributed under the Boost Software License, Version 1.0. + * http://www.boost.org/LICENSE_1_0.txt + * Source: https://github.com/dlang/dmd/blob/master/src/dmd/backend/aarray.d + */ + +module dmd.backend.aarray; + +import core.stdc.stdio; +import core.stdc.stdlib; +import core.stdc.string; + +alias hash_t = size_t; + +struct aaA +{ + aaA *next; + hash_t hash; + /* key */ + /* value */ +} + +struct AArray(TKey, Value) +{ + alias Key = TKey.Key; // key type + + ~this() + { + destroy(); + } + + void destroy() + { + if (buckets) + { + foreach (e; buckets) + { + while (e) + { + auto en = e; + e = e.next; + free(en); + } + } + free(buckets.ptr); + buckets = null; + nodes = 0; + } + } + + size_t length() + { + return nodes; + } + + /************************************************* + * Get pointer to value in associative array indexed by key. + * Add entry for key if it is not already there. + * Returns: + * pointer to Value + */ + + Value* get(Key* pkey) + { + //printf("AArray::get()\n"); + const aligned_keysize = aligntsize(Key.sizeof); + + if (!buckets.length) + { + alias aaAp = aaA*; + const len = prime_list[0]; + auto p = cast(aaAp*)calloc(len, aaAp.sizeof); + assert(p); + buckets = p[0 .. len]; + } + + hash_t key_hash = tkey.getHash(pkey); + const i = key_hash % buckets.length; + //printf("key_hash = %x, buckets.length = %d, i = %d\n", key_hash, buckets.length, i); + aaA* e; + auto pe = &buckets[i]; + while ((e = *pe) != null) + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + goto Lret; + } + pe = &e.next; + } + + // Not found, create new elem + //printf("create new one\n"); + e = cast(aaA *) malloc(aaA.sizeof + aligned_keysize + Value.sizeof); + assert(e); + memcpy(e + 1, pkey, Key.sizeof); + memset(cast(void *)(e + 1) + aligned_keysize, 0, Value.sizeof); + e.hash = key_hash; + e.next = null; + *pe = e; + + ++nodes; + //printf("length = %d, nodes = %d\n", buckets_length, nodes); + if (nodes > buckets.length * 4) + { + //printf("rehash()\n"); + rehash(); + } + + Lret: + return cast(Value*)(cast(void*)(e + 1) + aligned_keysize); + } + + /************************************************* + * Determine if key is in aa. + * Returns: + * null not in aa + * !=null in aa, return pointer to value + */ + + Value* isIn(Key* pkey) + { + //printf("AArray.isIn(), .length = %d, .ptr = %p\n", nodes, buckets.ptr); + if (!nodes) + return null; + + const key_hash = tkey.getHash(pkey); + //printf("hash = %d\n", key_hash); + const i = key_hash % buckets.length; + auto e = buckets[i]; + while (e != null) + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + return cast(Value*)(cast(void*)(e + 1) + aligntsize(Key.sizeof)); + } + + e = e.next; + } + + // Not found + return null; + } + + + /************************************************* + * Delete key entry in aa[]. + * If key is not in aa[], do nothing. + */ + + void del(Key *pkey) + { + if (!nodes) + return; + + const key_hash = tkey.getHash(pkey); + //printf("hash = %d\n", key_hash); + const i = key_hash % buckets.length; + auto pe = &buckets[i]; + aaA* e; + while ((e = *pe) != null) // null means not found + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + *pe = e.next; + --nodes; + free(e); + break; + } + pe = &e.next; + } + } + + + /******************************************** + * Produce array of keys from aa. + */ + + Key[] keys() + { + if (!nodes) + return null; + + auto p = cast(Key *)malloc(nodes * Key.sizeof); + assert(p); + auto q = p; + foreach (e; buckets) + { + while (e) + { + memcpy(q, e + 1, Key.sizeof); + ++q; + e = e.next; + } + } + return p[0 .. nodes]; + } + + /******************************************** + * Produce array of values from aa. + */ + + Value[] values() + { + if (!nodes) + return null; + + const aligned_keysize = aligntsize(Key.sizeof); + auto p = cast(Value *)malloc(nodes * Value.sizeof); + assert(p); + auto q = p; + foreach (e; buckets) + { + while (e) + { + memcpy(q, cast(void*)(e + 1) + aligned_keysize, Value.sizeof); + ++q; + e = e.next; + } + } + return p[0 .. nodes]; + } + + /******************************************** + * Rehash an array. + */ + + void rehash() + { + //printf("Rehash\n"); + if (!nodes) + return; + + size_t newbuckets_length = prime_list[$ - 1]; + + foreach (prime; prime_list[0 .. $ - 1]) + { + if (nodes <= prime) + { + newbuckets_length = prime; + break; + } + } + auto newbuckets = cast(aaA**)calloc(newbuckets_length, (aaA*).sizeof); + assert(newbuckets); + + foreach (e; buckets) + { + while (e) + { + auto en = e.next; + auto b = &newbuckets[e.hash % newbuckets_length]; + e.next = *b; + *b = e; + e = en; + } + } + + free(buckets.ptr); + buckets = null; + buckets = newbuckets[0 .. newbuckets_length]; + } + + + /********************************************* + * For each element in the AArray, + * call dg(Key* pkey, Value* pvalue) + * If dg returns !=0, stop and return that value. + */ + + int apply(int delegate(Key*, Value*) dg) + { + if (!nodes) + return 0; + + //printf("AArray.apply(aa = %p, keysize = %d, dg = %p)\n", &this, Key.sizeof, dg); + + const aligned_keysize = aligntsize(Key.sizeof); + + foreach (e; buckets) + { + while (e) + { + auto result = dg(cast(Key*)(e + 1), cast(Value*)(e + 1) + aligned_keysize); + if (result) + return result; + e = e.next; + } + } + + return 0; + } + + private: + + aaA*[] buckets; + size_t nodes; // number of nodes + TKey tkey; +} + +private: + +/********************************** + * Align to next pointer boundary, so value + * will be aligned. + */ + +size_t aligntsize(size_t tsize) +{ + // Is pointer alignment on the x64 4 bytes or 8? + return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); +} + +immutable uint[14] prime_list = +[ + 97U, 389U, + 1543U, 6151U, + 24593U, 98317U, + 393241U, 1572869U, + 6291469U, 25165843U, + 100663319U, 402653189U, + 1610612741U, 4294967291U +]; + +/***************************************************************/ + +// Simple values +public struct Tinfo(K) +{ + alias Key = K; + + static hash_t getHash(Key* pk) + { + return cast(hash_t)*pk; + } + + static bool equals(Key* pk1, Key* pk2) + { + return *pk1 == *pk2; + } +} + +/***************************************************************/ + +// char[] +public struct TinfoChars +{ + alias Key = const(char)[]; + + static hash_t getHash(Key* pk) + { + auto buf = *pk; + hash_t hash = 0; + foreach (v; buf) + hash = hash * 11 + v; + return hash; + } + + static bool equals(Key* pk1, Key* pk2) + { + auto buf1 = *pk1; + auto buf2 = *pk2; + return buf1.length == buf2.length && + memcmp(buf1.ptr, buf2.ptr, buf1.length) == 0; + } +} + +// Interface for C++ code +extern (C++) struct AAchars +{ + alias AA = AArray!(TinfoChars, uint); + AA aa; + + static AAchars* create() + { + auto a = cast(AAchars*)calloc(1, AAchars.sizeof); + assert(a); + return a; + } + + static void destroy(AAchars* aac) + { + aac.aa.destroy(); + free(aac); + } + + uint* get(const(char)* s, uint len) + { + auto buf = s[0 .. len]; + return aa.get(&buf); + } + + uint length() + { + return cast(uint)aa.length(); + } +} + +/***************************************************************/ + +// Key is the slice specified by (*TinfoPair.pbase)[Pair.start .. Pair.end] + +struct Pair { uint start, end; } + +public struct TinfoPair +{ + alias Key = Pair; + + ubyte** pbase; + + hash_t getHash(Key* pk) + { + auto buf = (*pbase)[pk.start .. pk.end]; + hash_t hash = 0; + foreach (v; buf) + hash = hash * 11 + v; + return hash; + } + + bool equals(Key* pk1, Key* pk2) + { + const len1 = pk1.end - pk1.start; + const len2 = pk2.end - pk2.start; + + auto buf1 = *pk1; + auto buf2 = *pk2; + return len1 == len2 && + memcmp(*pbase + pk1.start, *pbase + pk2.start, len1) == 0; + } +} + +// Interface for C++ code +extern (C++) struct AApair +{ + alias AA = AArray!(TinfoPair, uint); + AA aa; + + static AApair* create(ubyte** pbase) + { + auto a = cast(AApair*)calloc(1, AApair.sizeof); + assert(a); + a.aa.tkey.pbase = pbase; + return a; + } + + static void destroy(AApair* aap) + { + aap.aa.destroy(); + free(aap); + } + + uint* get(uint start, uint end) + { + auto p = Pair(start, end); + return aa.get(&p); + } + + uint length() + { + return cast(uint)aa.length(); + } +} + +/*************************************************************/ + +version (none) +{ + +/* Since -betterC doesn't support unittests, do it this way + * for the time being. + * This is a stand-alone file anyway. + */ + +int main() +{ + testAArray(); + testAApair(); + + return 0; +} + +void testAArray() +{ + int dg(int* pk, bool* pv) { return 3; } + int dgz(int* pk, bool* pv) { return 0; } + + AArray!(Tinfo!int, bool) aa; + aa.rehash(); + assert(aa.keys() == null); + assert(aa.values() == null); + assert(aa.apply(&dg) == 0); + + assert(aa.length == 0); + int k = 8; + aa.del(&k); + bool v = true; + assert(!aa.isIn(&k)); + bool *pv = aa.get(&k); + *pv = true; + int j = 9; + pv = aa.get(&j); + *pv = false; + aa.rehash(); + + assert(aa.length() == 2); + assert(*aa.get(&k) == true); + assert(*aa.get(&j) == false); + + assert(aa.apply(&dg) == 3); + assert(aa.apply(&dgz) == 0); + + aa.del(&k); + assert(aa.length() == 1); + assert(!aa.isIn(&k)); + assert(*aa.isIn(&j) == false); + + auto keys = aa.keys(); + assert(keys.length == 1); + assert(keys[0] == 9); + + auto values = aa.values(); + assert(values.length == 1); + assert(values[0] == false); +} + +void testAApair() +{ + const(char)* buf = "abcb"; + auto aap = AApair.create(cast(ubyte**)&buf); + auto pu = aap.get(1,2); + *pu = 10; + assert(aap.length == 1); + pu = aap.get(3,4); + assert(*pu == 10); + AApair.destroy(aap); +} + +} diff --git a/src/dmd/backend/dwarf.c b/src/dmd/backend/dwarf.c index 901dca5851e7..c759e8d0bb04 100644 --- a/src/dmd/backend/dwarf.c +++ b/src/dmd/backend/dwarf.c @@ -56,7 +56,6 @@ application if debug info is needed when the application is deployed. #include "dt.h" #include "aa.h" -#include "tinfo.h" #if ELFOBJ #include "melf.h" @@ -523,84 +522,16 @@ const char* debug_frame_name = ".debug_frame"; * representing the abbreviation code itself." */ static uint abbrevcode = 1; -static AArray *abbrev_table; +static AApair *abbrev_table; static int hasModname; // 1 if has DW_TAG_module // .debug_info -static AArray *infoFileName_table; +static AAchars *infoFileName_table; -static AArray *type_table; -static AArray *functype_table; // not sure why this cannot be combined with type_table +static AApair *type_table; +static AApair *functype_table; // not sure why this cannot be combined with type_table static Outbuffer *functypebuf; -// typeinfo declarations for hash of char* - -struct Abuf -{ - const ubyte *buf; - size_t length; -}; - -struct TypeInfo_Abuf : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Abuf ti_abuf; - -const char* TypeInfo_Abuf::toString() -{ - return "Abuf"; -} - -hash_t TypeInfo_Abuf::getHash(void *p) -{ - Abuf a = *(Abuf *)p; - - hash_t hash = 0; - for (size_t i = 0; i < a.length; i++) - hash = hash * 11 + a.buf[i]; - - return hash; -} - -int TypeInfo_Abuf::equals(void *p1, void *p2) -{ - Abuf a1 = *(Abuf*)p1; - Abuf a2 = *(Abuf*)p2; - - return a1.length == a2.length && - memcmp(a1.buf, a2.buf, a1.length) == 0; -} - -int TypeInfo_Abuf::compare(void *p1, void *p2) -{ - Abuf a1 = *(Abuf*)p1; - Abuf a2 = *(Abuf*)p2; - - if (a1.length == a2.length) - return memcmp(a1.buf, a2.buf, a1.length); - else if (a1.length < a2.length) - return -1; - else - return 1; -} - -size_t TypeInfo_Abuf::tsize() -{ - return sizeof(Abuf); -} - -void TypeInfo_Abuf::swap(void *p1, void *p2) -{ - assert(0); -} - #pragma pack(1) struct DebugInfoHeader { uint total_length; @@ -1076,7 +1007,8 @@ void dwarf_initfile(const char *filename) /* ======================================== */ if (infoFileName_table) - { delete infoFileName_table; + { + AAchars::destroy(infoFileName_table); infoFileName_table = null; } @@ -1110,7 +1042,8 @@ void dwarf_initfile(const char *filename) // Free only if starting another file. Waste of time otherwise. if (abbrev_table) - { delete abbrev_table; + { + AApair::destroy(abbrev_table); abbrev_table = null; } @@ -1240,15 +1173,11 @@ void dwarf_initfile(const char *filename) int dwarf_line_addfile(const char* filename) { if (!infoFileName_table) { - infoFileName_table = new AArray(&ti_abuf, sizeof(uint)); + infoFileName_table = AAchars::create(); linebuf_filetab_end = debug_line.buf->size(); } - Abuf abuf; - abuf.buf = (const ubyte*)filename; - abuf.length = strlen(filename); - - uint *pidx = cast(uint *)infoFileName_table->get(&abuf); + uint *pidx = infoFileName_table->get(filename, strlen(filename)); if (!*pidx) // if no idx assigned yet { *pidx = infoFileName_table->length(); // assign newly computed idx @@ -1478,11 +1407,13 @@ void dwarf_termfile() // Free only if starting another file. Waste of time otherwise. if (type_table) - { delete type_table; + { + AApair::destroy(type_table); type_table = null; } if (functype_table) - { delete functype_table; + { + AApair::destroy(functype_table); functype_table = null; } if (functypebuf) @@ -1945,75 +1876,6 @@ void cv_func(Funcsym *s) /* =================== Cached Types in debug_info ================= */ -struct Atype -{ - Outbuffer *buf; - size_t start; - size_t end; -}; - -struct TypeInfo_Atype : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Atype ti_atype; - -const char* TypeInfo_Atype::toString() -{ - return "Atype"; -} - -hash_t TypeInfo_Atype::getHash(void *p) -{ - hash_t hash = 0; - - Atype a = *cast(Atype *)p; - for (size_t i = a.start; i < a.end; i++) - { - hash = hash * 11 + a.buf->buf[i]; - } - return hash; -} - -int TypeInfo_Atype::equals(void *p1, void *p2) -{ - Atype a1 = *cast(Atype*)p1; - Atype a2 = *cast(Atype*)p2; - size_t len = a1.end - a1.start; - - return len == a2.end - a2.start && - memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len) == 0; -} - -int TypeInfo_Atype::compare(void *p1, void *p2) -{ - Atype a1 = *cast(Atype*)p1; - Atype a2 = *cast(Atype*)p2; - size_t len = a1.end - a1.start; - if (len == a2.end - a2.start) - return memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len); - else if (len < a2.end - a2.start) - return -1; - else - return 1; -} - -size_t TypeInfo_Atype::tsize() -{ - return sizeof(Atype); -} - -void TypeInfo_Atype::swap(void *p1, void *p2) -{ - assert(0); -} - ubyte dwarf_classify_struct(uint sflags) { if (sflags & STRclass) @@ -2410,12 +2272,8 @@ uint dwarf_typidx(type *t) /* If it's in the cache already, return the existing typidx */ if (!functype_table) - functype_table = new AArray(&ti_atype, sizeof(uint)); - Atype functype; - functype.buf = functypebuf; - functype.start = functypebufidx; - functype.end = functypebuf->size(); - uint *pidx = cast(uint *)functype_table->get(&functype); + functype_table = AApair::create(&functypebuf->buf); + uint *pidx = cast(uint *)functype_table->get(functypebufidx, functypebuf->size()); if (*pidx) { // Reuse existing typidx functypebuf->setsize(functypebufidx); @@ -2839,19 +2697,13 @@ uint dwarf_typidx(type *t) /* If debug_info.buf->buf[idx .. size()] is already in debug_info.buf, * discard this one and use the previous one. */ - Atype atype; - atype.buf = debug_info.buf; - atype.start = idx; - atype.end = debug_info.buf->size(); - if (!type_table) /* uint[Adata] type_table; * where the table values are the type indices */ - type_table = new AArray(&ti_atype, sizeof(uint)); + type_table = AApair::create(&debug_info.buf->buf); - uint *pidx; - pidx = cast(uint *)type_table->get(&atype); + uint *pidx = type_table->get(idx, debug_info.buf->size()); if (!*pidx) // if no idx assigned yet { *pidx = idx; // assign newly computed idx @@ -2866,76 +2718,6 @@ uint dwarf_typidx(type *t) /* ======================= Abbreviation Codes ====================== */ -struct Adata -{ - size_t start; - size_t end; -}; - -struct TypeInfo_Adata : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Adata ti_adata; - -const char* TypeInfo_Adata::toString() -{ - return "Adata"; -} - -hash_t TypeInfo_Adata::getHash(void *p) -{ - hash_t hash = 0; - - Adata a = *cast(Adata *)p; - for (size_t i = a.start; i < a.end; i++) - { - //printf("%02x ", debug_abbrev.buf->buf[i]); - hash = hash * 11 + debug_abbrev.buf->buf[i]; - } - //printf("\nhash = %x, length = %d\n", hash, a.end - a.start); - return hash; -} - -int TypeInfo_Adata::equals(void *p1, void *p2) -{ - Adata a1 = *cast(Adata*)p1; - Adata a2 = *cast(Adata*)p2; - size_t len = a1.end - a1.start; - - return len == a2.end - a2.start && - memcmp(debug_abbrev.buf->buf + a1.start, debug_abbrev.buf->buf + a2.start, len) == 0; -} - -int TypeInfo_Adata::compare(void *p1, void *p2) -{ - Adata a1 = *cast(Adata*)p1; - Adata a2 = *cast(Adata*)p2; - size_t len = a1.end - a1.start; - if (len == a2.end - a2.start) - return memcmp(debug_abbrev.buf->buf + a1.start, debug_abbrev.buf->buf + a2.start, len); - else if (len < a2.end - a2.start) - return -1; - else - return 1; -} - -size_t TypeInfo_Adata::tsize() -{ - return sizeof(Adata); -} - -void TypeInfo_Adata::swap(void *p1, void *p2) -{ - assert(0); -} - uint dwarf_abbrev_code(ubyte *data, size_t nbytes) { @@ -2943,25 +2725,23 @@ uint dwarf_abbrev_code(ubyte *data, size_t nbytes) /* uint[Adata] abbrev_table; * where the table values are the abbreviation codes. */ - abbrev_table = new AArray(&ti_adata, sizeof(uint)); + abbrev_table = AApair::create(&debug_abbrev.buf->buf); /* Write new entry into debug_abbrev.buf */ - Adata adata; uint idx = debug_abbrev.buf->size(); abbrevcode++; debug_abbrev.buf->writeuLEB128(abbrevcode); - adata.start = debug_abbrev.buf->size(); + size_t start = debug_abbrev.buf->size(); debug_abbrev.buf->write(data, nbytes); - adata.end = debug_abbrev.buf->size(); + size_t end = debug_abbrev.buf->size(); /* If debug_abbrev.buf->buf[idx .. size()] is already in debug_abbrev.buf, * discard this one and use the previous one. */ - uint *pcode; - pcode = cast(uint *)abbrev_table->get(&adata); + uint *pcode = abbrev_table->get(start, end); if (!*pcode) // if no code assigned yet { *pcode = abbrevcode; // assign newly computed code diff --git a/src/dmd/backend/elfobj.c b/src/dmd/backend/elfobj.c index c02f3a3f711d..85db9b3199e5 100644 --- a/src/dmd/backend/elfobj.c +++ b/src/dmd/backend/elfobj.c @@ -166,7 +166,7 @@ static Outbuffer *section_names; #define SEC_NAMES_INC 400 // Hash table for section_names -AArray *section_names_hashtable; +AApair *section_names_hashtable; int jmpseg; @@ -641,7 +641,8 @@ static IDXSTR elf_addsectionname(const char *name, const char *suffix = NULL, bo section_names->setsize(section_names->size() - 1); // back up over terminating 0 section_names->writeString(suffix); } - IDXSTR *pidx = (IDXSTR *)section_names_hashtable->get(&namidx); + IDXSTR *pidx = section_names_hashtable->get(namidx, section_names->size() - 1); + //IDXSTR *pidx = (IDXSTR *)section_names_hashtable->get(&namidx); if (*pidx) { // this section name already exists, remove addition @@ -814,8 +815,10 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) } if (section_names_hashtable) - delete section_names_hashtable; - section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); + AApair::destroy(section_names_hashtable); + //delete section_names_hashtable; + section_names_hashtable = AApair::create(§ion_names->buf); + //section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); // name,type,flags,addr,offset,size,link,info,addralign,entsize elf_newsection2(0, SHT_NULL, 0, 0,0,0,0,0, 0,0); @@ -834,19 +837,19 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) elf_newsection2(NAMIDX_CDATAREL,SHT_PROGBITS,SHF_ALLOC|SHF_WRITE,0,0,0,0,0, 16,0); IDXSTR namidx; - namidx = NAMIDX_TEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELTEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_DATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELDATA64; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_BSS; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RODATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_STRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SYMTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SHSTRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_COMMENT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_NOTE; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_GNUSTACK; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_CDATAREL; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; + namidx = NAMIDX_TEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RELTEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_DATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RELDATA64; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_BSS; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RODATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_STRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_SYMTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_SHSTRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_COMMENT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_NOTE; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_GNUSTACK; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_CDATAREL; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; } else { @@ -862,8 +865,10 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) } if (section_names_hashtable) - delete section_names_hashtable; - section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); + AApair::destroy(section_names_hashtable); + //delete section_names_hashtable; + section_names_hashtable = AApair::create(§ion_names->buf); + //section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); // name,type,flags,addr,offset,size,link,info,addralign,entsize elf_newsection2(0, SHT_NULL, 0, 0,0,0,0,0, 0,0); @@ -882,19 +887,19 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) elf_newsection2(NAMIDX_CDATAREL,SHT_PROGBITS,SHF_ALLOC|SHF_WRITE,0,0,0,0,0, 1,0); IDXSTR namidx; - namidx = NAMIDX_TEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELTEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_DATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELDATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_BSS; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RODATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_STRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SYMTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SHSTRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_COMMENT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_NOTE; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_GNUSTACK; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_CDATAREL; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; + namidx = NAMIDX_TEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RELTEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_DATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RELDATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_BSS; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RODATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_STRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_SYMTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_SHSTRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_COMMENT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_NOTE; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_GNUSTACK; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_CDATAREL; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; } if (SYMbuf) diff --git a/src/posix.mak b/src/posix.mak index f8bfdea2f257..bf33484da418 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -361,7 +361,7 @@ BACK_DOBJS = bcomplex.o evalu8.o divcoeff.o dvec.o go.o gsroa.o glocal.o gdag.o out.o \ gloop.o compress.o cgelem.o cgcs.o ee.o cod4.o cod5.o nteh.o blockopt.o memh.o cg.o cgreg.o \ dtype.o debugprint.o symbol.o elem.o dcode.o cgsched.o cg87.o cgxmm.o cgcod.o cod1.o cod2.o \ - cod3.o cv8.o dcgcv.o pdata.o util2.o var.o md5.o backconfig.o ph2.o drtlsym.o dwarfeh.o + cod3.o cv8.o dcgcv.o pdata.o util2.o var.o md5.o backconfig.o ph2.o drtlsym.o dwarfeh.o aarray.o G_OBJS = $(addprefix $G/, $(BACK_OBJS)) G_DOBJS = $(addprefix $G/, $(BACK_DOBJS)) @@ -402,7 +402,7 @@ BACK_SRC = \ $C/dtype.d $C/melf.h $C/mach.h $C/mscoff.h $C/bcomplex.h \ $C/outbuf.h $C/token.h $C/tassert.h \ $C/elfobj.c $C/cv4.h $C/dwarf2.h $C/exh.h $C/go.h \ - $C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \ + $C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c $C/aarray.d \ $C/ti_pvoid.c $C/platform_stub.c $C/code_x86.h $C/code_stub.h \ $C/machobj.c $C/mscoffobj.c \ $C/xmm.h $C/obj.h $C/pdata.d $C/cv8.d $C/backconfig.d $C/sizecheck.c $C/divcoeff.d \ diff --git a/src/win32.mak b/src/win32.mak index 7d8e2c3797af..9d04956480f0 100644 --- a/src/win32.mak +++ b/src/win32.mak @@ -239,7 +239,7 @@ BACKSRC= $C\cdef.h $C\cc.h $C\oper.h $C\ty.h $C\optabgen.d \ $C\dtype.d $C\melf.h $C\mach.h $C\mscoff.h $C\bcomplex.h \ $C\outbuf.h $C\token.h $C\tassert.h \ $C\elfobj.c $C\cv4.h $C\dwarf2.h $C\exh.h $C\go.h \ - $C\dwarf.c $C\dwarf.h $C\machobj.c \ + $C\dwarf.c $C\dwarf.h $C\machobj.c $C\aarray.d \ $C\strtold.c $C\aa.h $C\aa.c $C\tinfo.h $C\ti_achar.c \ $C\md5.h $C\md5.d $C\ti_pvoid.c $C\xmm.h $C\ph2.d $C\util2.d \ $C\mscoffobj.c $C\obj.h $C\pdata.d $C\cv8.d $C\backconfig.d $C\sizecheck.c \