Hi Heather, On Tue, Oct 10, 2023 at 03:42:52PM +0200, Mark Wielaard wrote: > From: Heather McIntyre <h...@rice.edu> > > * libcpu/Makefile.am: Add USE_LOCKS condition for -pthread. > * libcpu/i386_parse.y: Add eu-search.h and remove search.h. > Change calls for tsearch/tfind to eu_tsearch/eu_tfind.
So in theory this looks like a simple obvious change to use eu-search instead of search. But I am not sure ths bison parser can even be used concurrently. It looks like it is using a lot of statics. Also i386_parse.y uses twalk, which also would have to be wrapped (no other part of elfutils uses twalk). I think I would advise to skip the i386 assembler. It isn't really complete at the moment and it is probably a lot of work to get a concurrent bison parser. Cheers, Mark > Signed-off-by: Heather S. McIntyre <h...@rice.edu> > Signed-off-by: Mark Wielaard <m...@klomp.org> > --- > libcpu/Makefile.am | 3 +++ > libcpu/i386_parse.y | 48 ++++++++++++++++++++++----------------------- > 2 files changed, 27 insertions(+), 24 deletions(-) > > diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am > index 4ba1be56..a51334b5 100644 > --- a/libcpu/Makefile.am > +++ b/libcpu/Makefile.am > @@ -33,6 +33,9 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ > if BUILD_STATIC > AM_CFLAGS += $(fpic_CFLAGS) > endif > +if USE_LOCKS > + AM_CFLAGS += -pthread > +endif > AM_CFLAGS += -fdollars-in-identifiers > LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS) -P$(<F:lex.l=) > LEX_OUTPUT_ROOT = lex.$(<F:lex.l=) > diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y > index 459684c6..3d7cb89e 100644 > --- a/libcpu/i386_parse.y > +++ b/libcpu/i386_parse.y > @@ -37,7 +37,7 @@ > #include <inttypes.h> > #include <math.h> > #include <obstack.h> > -#include <search.h> > +#include <eu-search.h> > #include <stdbool.h> > #include <stdio.h> > #include <stdlib.h> > @@ -269,12 +269,12 @@ mask: kMASK kBITFIELD kNUMBER > struct synonym *newp = xmalloc (sizeof (*newp)); > newp->from = $2; > newp->to = $3; > - if (tfind (newp, &synonyms, compare_syn) != NULL) > + if (eu_tfind (newp, &synonyms, compare_syn) != NULL) > error (0, 0, > "%d: duplicate definition for synonym '%s'", > i386_lineno, $2); > - else if (tsearch ( newp, &synonyms, compare_syn) == NULL) > - error (EXIT_FAILURE, 0, "tsearch"); > + else if (eu_tsearch ( newp, &synonyms, compare_syn) == > NULL) > + error (EXIT_FAILURE, 0, "eu_tsearch"); > } > | > ; > @@ -308,12 +308,12 @@ instr: bytes ':' bitfieldopt kID bitfieldopt > optargs > newp->bytes = $1; > newp->mnemonic = $4; > if (newp->mnemonic != (void *) -1l > - && tfind ($4, &mnemonics, > + && eu_tfind ($4, &mnemonics, > (int (*)(const void *, const void *)) > strcmp) == NULL) > { > - if (tsearch ($4, &mnemonics, > + if (eu_tsearch ($4, &mnemonics, > (int (*)(const void *, const void > *)) strcmp) == NULL) > - error (EXIT_FAILURE, errno, "tsearch"); > + error (EXIT_FAILURE, errno, "eu_tsearch"); > ++nmnemonics; > } > > @@ -339,15 +339,15 @@ instr: bytes ':' bitfieldopt kID bitfieldopt > optargs > infname, i386_lineno - 1, $5->name); > > struct suffix search = { .name = $5->name }; > - if (tfind (&search, &suffixes, compare_suf) > + if (eu_tfind (&search, &suffixes, compare_suf) > == NULL) > { > struct suffix *ns = xmalloc (sizeof (*ns)); > ns->name = $5->name; > ns->idx = ++nsuffixes; > - if (tsearch (ns, &suffixes, compare_suf) > + if (eu_tsearch (ns, &suffixes, compare_suf) > == NULL) > - error (EXIT_FAILURE, errno, "tsearch"); > + error (EXIT_FAILURE, errno, "eu_tsearch"); > } > } > > @@ -374,7 +374,7 @@ bitfieldopt: kBITFIELD > struct known_bitfield search; > search.name = $1; > struct known_bitfield **res; > - res = tfind (&search, &bitfields, bitfield_compare); > + res = eu_tfind (&search, &bitfields, bitfield_compare); > if (res == NULL) > { > error (0, 0, "%d: unknown bitfield '%s'", > @@ -437,7 +437,7 @@ bit: '0' > struct known_bitfield search; > search.name = $1; > struct known_bitfield **res; > - res = tfind (&search, &bitfields, bitfield_compare); > + res = eu_tfind (&search, &bitfields, bitfield_compare); > if (res == NULL) > { > error (0, 0, "%d: unknown bitfield '%s'", > @@ -497,7 +497,7 @@ argcomp: kBITFIELD > struct known_bitfield search; > search.name = $1; > struct known_bitfield **res; > - res = tfind (&search, &bitfields, bitfield_compare); > + res = eu_tfind (&search, &bitfields, bitfield_compare); > if (res == NULL) > { > if (strcmp ($1, "ax") == 0) > @@ -575,7 +575,7 @@ new_bitfield (char *name, unsigned long int num) > newp->bits = num; > newp->tmp = 0; > > - if (tfind (newp, &bitfields, bitfield_compare) != NULL) > + if (eu_tfind (newp, &bitfields, bitfield_compare) != NULL) > { > error (0, 0, "%d: duplicated definition of bitfield '%s'", > i386_lineno, name); > @@ -584,7 +584,7 @@ new_bitfield (char *name, unsigned long int num) > return; > } > > - if (tsearch (newp, &bitfields, bitfield_compare) == NULL) > + if (eu_tsearch (newp, &bitfields, bitfield_compare) == NULL) > error (EXIT_FAILURE, errno, "%d: cannot insert new bitfield '%s'", > i386_lineno, name); > } > @@ -813,7 +813,7 @@ fillin_arg (struct bitvalue *bytes, struct argname *name, > > struct synonym search = { .from = fieldname }; > > - struct synonym **res = tfind (&search, &synonyms, compare_syn); > + struct synonym **res = eu_tfind (&search, &synonyms, compare_syn); > if (res != NULL) > fieldname = (*res)->to; > > @@ -914,26 +914,26 @@ find_numbers (void) > if (runp->operands[i].fct != NULL) > { > struct argstring search = { .str = runp->operands[i].fct }; > - if (tfind (&search, &fct_names[i], compare_argstring) == NULL) > + if (eu_tfind (&search, &fct_names[i], compare_argstring) == NULL) > { > struct argstring *newp = xmalloc (sizeof (*newp)); > newp->str = runp->operands[i].fct; > newp->idx = 0; > - if (tsearch (newp, &fct_names[i], compare_argstring) == NULL) > - error (EXIT_FAILURE, errno, "tsearch"); > + if (eu_tsearch (newp, &fct_names[i], compare_argstring) == NULL) > + error (EXIT_FAILURE, errno, "eu_tsearch"); > ++nfct_names[i]; > } > > if (runp->operands[i].str != NULL) > { > search.str = runp->operands[i].str; > - if (tfind (&search, &strs[i], compare_argstring) == NULL) > + if (eu_tfind (&search, &strs[i], compare_argstring) == NULL) > { > struct argstring *newp = xmalloc (sizeof (*newp)); > newp->str = runp->operands[i].str; > newp->idx = 0; > - if (tsearch (newp, &strs[i], compare_argstring) == NULL) > - error (EXIT_FAILURE, errno, "tsearch"); > + if (eu_tsearch (newp, &strs[i], compare_argstring) == NULL) > + error (EXIT_FAILURE, errno, "eu_tsearch"); > ++nstrs[i]; > } > } > @@ -1206,7 +1206,7 @@ instrtable_out (void) > if (instr->operands[i].fct != NULL) > { > struct argstring search = { .str = instr->operands[i].fct }; > - struct argstring **res = tfind (&search, &fct_names[i], > + struct argstring **res = eu_tfind (&search, &fct_names[i], > compare_argstring); > assert (res != NULL); > idx = (*res)->idx; > @@ -1217,7 +1217,7 @@ instrtable_out (void) > if (instr->operands[i].str != NULL) > { > struct argstring search = { .str = instr->operands[i].str }; > - struct argstring **res = tfind (&search, &strs[i], > + struct argstring **res = eu_tfind (&search, &strs[i], > compare_argstring); > assert (res != NULL); > idx = (*res)->idx; > -- > 2.41.0 >