Skip to content

Commit

Permalink
replace usage of slow slist
Browse files Browse the repository at this point in the history
- directly reset symbols after putting them out to the obj file
- it's done in the obj implementations b/c some (macho, mscoff)
  defer writing the symbol table until all sections are written
  • Loading branch information
MartinNowak committed Oct 29, 2015
1 parent 681ebb3 commit beb4de4
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 74 deletions.
20 changes: 20 additions & 0 deletions src/backend/cgobj.c
Expand Up @@ -265,6 +265,7 @@ struct Objstate
int segidx; // index of next SEGDEF record
int extidx; // index of next EXTDEF record
int pubnamidx; // index of COMDAT public name index
Outbuffer *reset_symbuf; // Keep pointers to reset symbols

Symbol *startaddress; // if !NULL, then Symbol is start address

Expand Down Expand Up @@ -590,11 +591,27 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
//printf("Obj::init()\n");
Obj *mobj = new Obj();

Outbuffer *reset_symbuf = obj.reset_symbuf;
if (reset_symbuf)
{
symbol **p = (symbol **)reset_symbuf->buf;
const size_t n = reset_symbuf->size() / sizeof(symbol *);
for (size_t i = 0; i < n; ++i)
symbol_reset(p[i]);
reset_symbuf->setsize(0);
}
else
{
reset_symbuf = new Outbuffer(50 * sizeof(symbol *));
}

memset(&obj,0,sizeof(obj));

obj.buf = objbuf;
obj.buf->reserve(40000);

obj.reset_symbuf = reset_symbuf; // reuse buffer

obj.lastfardatasegi = -1;

obj.mlidata = LIDATA;
Expand Down Expand Up @@ -1872,6 +1889,7 @@ int Obj::comdat(Symbol *s)
tym_t ty;

symbol_debug(s);
obj.reset_symbuf->write(&s, sizeof(s));
ty = s->ty();
isfunc = tyfunc(ty) != 0;

Expand Down Expand Up @@ -2516,6 +2534,7 @@ int Obj::external(Symbol *s)
{
//dbg_printf("Obj::external('%s')\n",s->Sident);
symbol_debug(s);
obj.reset_symbuf->write(&s, sizeof(s));
if (obj.extdatai + (IDMAX + IDOHD) + 3 > sizeof(obj.extdata))
outextdata();

Expand Down Expand Up @@ -2716,6 +2735,7 @@ STATIC void obj_modend()
// Turn startaddress into a fixup.
// Borrow heavilly from Obj::reftoident()

obj.reset_symbuf->write(&s, sizeof(s));
symbol_debug(s);
offset = 0;
ty = s->ty();
Expand Down
1 change: 0 additions & 1 deletion src/backend/dt.c
Expand Up @@ -318,7 +318,6 @@ dt_t **dtdtoff(dt_t **pdtend, dt_t *dt, unsigned offset)
s->Sflags |= SFLnodebug;
s->Stype = t;
s->Sdt = dt;
slist_add(s);
outdata(s);
return dtxoff(pdtend, s, offset);
}
Expand Down
5 changes: 0 additions & 5 deletions src/backend/el.c
Expand Up @@ -43,10 +43,6 @@ static int elfreed = 0; /* number of freed elems */
static int eprm_cnt; /* max # of allocs at any point */
#endif

#if TARGET_OSX
extern void slist_add(Symbol *s);
#endif

/*******************************
* Do our own storage allocation of elems.
*/
Expand Down Expand Up @@ -1254,7 +1250,6 @@ elem *el_picvar(symbol *s)
*/
tls_get_addr_sym = symbol_name("___tls_get_addr",SCglobal,type_fake(TYjfunc));
symbol_keep(tls_get_addr_sym);
slist_add(tls_get_addr_sym);
}
if (x == 1)
e = el_una(OPind, TYnptr, e);
Expand Down
16 changes: 16 additions & 0 deletions src/backend/elfobj.c
Expand Up @@ -268,6 +268,7 @@ static int local_cnt; // Number of symbols with STB_LOCAL

// Symbol Table
Outbuffer *SYMbuf; // Buffer to build symbol table in
Outbuffer *reset_symbuf; // Keep pointers to reset symbols

// Extended section header indices
static Outbuffer *shndx_data;
Expand Down Expand Up @@ -814,6 +815,18 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)

if (SYMbuf)
SYMbuf->setsize(0);
if (reset_symbuf)
{
symbol **p = (symbol **)reset_symbuf->buf;
const size_t n = reset_symbuf->size() / sizeof(symbol *);
for (size_t i = 0; i < n; ++i)
symbol_reset(p[i]);
reset_symbuf->setsize(0);
}
else
{
reset_symbuf = new Outbuffer(50 * sizeof(symbol *));
}
if (shndx_data)
shndx_data->setsize(0);
symbol_idx = 0;
Expand Down Expand Up @@ -2194,6 +2207,7 @@ void Obj::pubdefsize(int seg, Symbol *s, targ_size_t offset, targ_size_t symsize
#endif

symbol_debug(s);
reset_symbuf->write(&s, sizeof(s));
IDXSTR namidx = elf_addmangled(s);
//printf("\tnamidx %d,section %d\n",namidx,MAP_SEG2SECIDX(seg));
if (tyfunc(s->ty()))
Expand Down Expand Up @@ -2246,6 +2260,7 @@ int Obj::external(Symbol *s)

//dbg_printf("Obj::external('%s') %x\n",s->Sident,s->Svalue);
symbol_debug(s);
reset_symbuf->write(&s, sizeof(s));
IDXSTR namidx = elf_addmangled(s);

#if SCPP
Expand Down Expand Up @@ -2313,6 +2328,7 @@ int Obj::common_block(Symbol *s,targ_size_t size,targ_size_t count)
return s->Sseg;
}
#if 0
reset_symbuf->write(s);
IDXSTR namidx = elf_addmangled(s);
alignOffset(UDATA,size);
IDXSYM symidx = elf_addsym(namidx, SegData[UDATA]->SDoffset, size*count,
Expand Down
5 changes: 1 addition & 4 deletions src/backend/global.h
Expand Up @@ -372,9 +372,7 @@ SYMIDX symbol_add(Symbol *s);
void freesymtab(Symbol **stab, SYMIDX n1, SYMIDX n2);
Symbol * symbol_copy(Symbol *s);
Symbol * symbol_searchlist(symlist_t sl, const char *vident);
void slist_add(Symbol *s);
void slist_reset();

void symbol_reset(Symbol *s);

#if TX86
// cg87.c
Expand Down Expand Up @@ -543,4 +541,3 @@ int lnx_attributes(int hinttype,const void *hint, type **ptyp, tym_t *ptym,int
#endif

#endif /* GLOBAL_H */

24 changes: 20 additions & 4 deletions src/backend/machobj.c
Expand Up @@ -126,6 +126,14 @@ static Outbuffer *local_symbuf;
static Outbuffer *public_symbuf;
static Outbuffer *extern_symbuf;

static void reset_symbols(Outbuffer *buf)
{
symbol **p = (symbol **)buf->buf;
const size_t n = buf->size() / sizeof(symbol *);
for (size_t i = 0; i < n; ++i)
symbol_reset(p[i]);
}

struct Comdef { symbol *sym; targ_size_t size; int count; };
static Outbuffer *comdef_symbuf; // Comdef's are stored here

Expand Down Expand Up @@ -436,13 +444,21 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname)
local_symbuf = new Outbuffer(sizeof(symbol *) * SYM_TAB_INIT);
local_symbuf->setsize(0);

if (!public_symbuf)
if (public_symbuf)
{
reset_symbols(public_symbuf);
public_symbuf->setsize(0);
}
else
public_symbuf = new Outbuffer(sizeof(symbol *) * SYM_TAB_INIT);
public_symbuf->setsize(0);

if (!extern_symbuf)
if (extern_symbuf)
{
reset_symbols(extern_symbuf);
extern_symbuf->setsize(0);
}
else
extern_symbuf = new Outbuffer(sizeof(symbol *) * SYM_TAB_INIT);
extern_symbuf->setsize(0);

if (!comdef_symbuf)
comdef_symbuf = new Outbuffer(sizeof(symbol *) * SYM_TAB_INIT);
Expand Down
11 changes: 9 additions & 2 deletions src/backend/mscoffobj.c
Expand Up @@ -378,9 +378,16 @@ MsCoffObj *MsCoffObj::init(Outbuffer *objbuf, const char *filename, const char *
string_table->setsize(0);
string_table->write32(4); // first 4 bytes are length of string table

if (!symbuf)
if (symbuf)
{
symbol **p = (symbol **)symbuf->buf;
const size_t n = symbuf->size() / sizeof(symbol *);
for (size_t i = 0; i < n; ++i)
symbol_reset(p[i]);
symbuf->setsize(0);
}
else
symbuf = new Outbuffer(sizeof(symbol *) * SYM_TAB_INIT);
symbuf->setsize(0);

if (!syment_buf)
syment_buf = new Outbuffer(sizeof(SymbolTable32) * SYM_TAB_INIT);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/rtlsym.c
Expand Up @@ -85,14 +85,14 @@ void rtlsym_init()
* Reset the symbols for the case when we are generating multiple
* .OBJ files from one compile.
*/

#if MARS

void rtlsym_reset()
{
clib_inited = 0; // reset CLIB symbols, too
for (size_t i = 0; i < RTLSYM_MAX; i++)
{ rtlsym[i]->Sxtrnnum = 0;
{
rtlsym[i]->Sxtrnnum = 0;
rtlsym[i]->Stypidx = 0;
}
}
Expand Down
43 changes: 10 additions & 33 deletions src/backend/symbol.c
Expand Up @@ -2269,43 +2269,20 @@ void symbol_gendebuginfo()

#endif

/************************************
* Add symbol to global slist, which are symbols we need to keep around
* for next obj file to be created.
*/

static Symbol **slist;
static size_t slist_length;

void slist_add(Symbol *s)
{
slist = (Symbol **)realloc(slist, (slist_length + 1) * sizeof(Symbol *));
slist[slist_length++] = s;
}

/*************************************
* Resets Symbols so they are now "externs" to the next obj file being created.
* Reset Symbol so that it's now an "extern" to the next obj file being created.
*/

void slist_reset()
void symbol_reset(Symbol *s)
{
//printf("slist_reset()\n");
for (size_t i = 0; i < slist_length; ++i)
{
Symbol *s = slist[i];

s->Soffset = 0;
s->Sxtrnnum = 0;
s->Stypidx = 0;
s->Sflags &= ~(STRoutdef | SFLweak);
if (s->Sclass == SCglobal || s->Sclass == SCcomdat ||
s->Sfl == FLudata || s->Sclass == SCstatic)
{ s->Sclass = SCextern;
s->Sfl = FLextern;
}
s->Soffset = 0;
s->Sxtrnnum = 0;
s->Stypidx = 0;
s->Sflags &= ~(STRoutdef | SFLweak);
if (s->Sclass == SCglobal || s->Sclass == SCcomdat ||
s->Sfl == FLudata || s->Sclass == SCstatic)
{ s->Sclass = SCextern;
s->Sfl = FLextern;
}
}



#endif /* !SPP */
2 changes: 0 additions & 2 deletions src/backend/type.c
Expand Up @@ -468,7 +468,6 @@ type *type_enum(const char *name, type *tbase)
s->Sclass = SCenum;
s->Senum = (enum_t *) MEM_PH_CALLOC(sizeof(enum_t));
s->Senum->SEflags |= SENforward; // forward reference
slist_add(s);

type *t = type_allocn(TYenum, tbase);
t->Ttag = (Classsym *)s; // enum tag name
Expand Down Expand Up @@ -510,7 +509,6 @@ type *type_struct_class(const char *name, unsigned alignsize, unsigned structsiz
t->Ttag = (Classsym *)s; // structure tag name
t->Tcount++;
s->Stype = t;
slist_add(s);
t->Tcount++;
return t;
}
Expand Down
4 changes: 1 addition & 3 deletions src/glue.c
Expand Up @@ -236,7 +236,6 @@ void obj_start(char *srcfile)
//printf("obj_start()\n");

rtlsym_reset();
slist_reset();
clearStringTab();

#if TARGET_WINDOS
Expand Down Expand Up @@ -374,7 +373,6 @@ void genObjFile(Module *m, bool multiobj)
m->cov->Sfl = FLdata;
dtnzeros(&m->cov->Sdt, 4 * m->numlines);
outdata(m->cov);
slist_add(m->cov);

m->covb = (unsigned *)calloc((m->numlines + 32) / 32, sizeof(*m->covb));
}
Expand All @@ -389,7 +387,7 @@ void genObjFile(Module *m, bool multiobj)
if (global.params.cov)
{
/* Generate
* bit[numlines] __bcoverage;
* private bit[numlines] __bcoverage;
*/
Symbol *bcov = symbol_calloc("__bcoverage");
bcov->Stype = type_fake(TYuint);
Expand Down

0 comments on commit beb4de4

Please sign in to comment.