Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbol _bfdec_normalize_and_round, when compiling without CONFIG_BIGNUM, since 94010ed #241

Open
past-due opened this issue Feb 17, 2024 · 1 comment

Comments

@past-due
Copy link

past-due commented Feb 17, 2024

In 94010ed, the defines for USE_BF_DEC and USE_FFT_MUL were placed inside an #ifdef CONFIG_BIGNUM:

quickjs/libbf.c

Lines 40 to 45 in 94010ed

#ifdef CONFIG_BIGNUM
/* enable it to use FFT/NTT multiplication */
#define USE_FFT_MUL
/* enable decimal floating point support */
#define USE_BF_DEC
#endif

This causes an undefined symbol error when compiling without CONFIG_BIGNUM defined, due to _bf_atof_internal's referencing _bfdec_normalize_and_round.

ld: Undefined symbols:
  _bfdec_normalize_and_round, referenced from:
      _bf_atof_internal in libquickjs.a[3](libbf.o)

(Example: Try compiling QuickJS without optimizations and without CONFIG_BIGNUM defined.)

It appears that there are only two uses of _bf_atof_internal when CONFIG_BIGNUM is undefined:

quickjs/libbf.c

Lines 3159 to 3172 in 3bb2ca3

int bf_atof2(bf_t *r, slimb_t *pexponent,
const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags)
{
return bf_atof_internal(r, pexponent, str, pnext, radix, prec, flags,
FALSE);
}
int bf_atof(bf_t *r, const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags)
{
slimb_t dummy_exp;
return bf_atof_internal(r, &dummy_exp, str, pnext, radix, prec, flags, FALSE);
}

Both of these pass FALSE to the BOOL is_dec parameter of _bf_atof_internal, and so _bfdec_normalize_and_round should never actually be called when CONFIG_BIGNUM is undefined:

quickjs/libbf.c

Lines 3105 to 3108 in 3bb2ca3

if (is_dec) {
a->expn = expn + int_len;
a->sign = is_neg;
ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);


So it seems like _bf_atof_internal could use an #ifdef USE_BF_DEC check around this single use of bfdec_normalize_and_round. For example (not sure if this is the best / desired approach):

      if (is_dec) {
+ #ifdef USE_BF_DEC
          a->expn = expn + int_len;
          a->sign = is_neg;
          ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);
+ #else
+         // bfdec_normalize_and_round not available without USE_BF_DEC
+         // if (!radix_bits)
+         //    bf_delete(a); // needed?
+         bf_set_nan(r);
+         ret = BF_ST_MEM_ERROR;
+ #endif
      } else if (radix_bits) {

@chqrlie : Any thoughts / suggestions?

@chqrlie
Copy link
Collaborator

chqrlie commented Mar 18, 2024

@past-due Sorry for the lack of responsiveness, I shall fix it this week.

GerHobbelt pushed a commit to GerHobbelt/quickjs that referenced this issue May 6, 2024
HarlonWang added a commit to HarlonWang/quickjs that referenced this issue Sep 19, 2024
HarlonWang added a commit to HarlonWang/quickjs that referenced this issue Sep 19, 2024
HarlonWang added a commit to HarlonWang/quickjs that referenced this issue Sep 19, 2024
HarlonWang added a commit to HarlonWang/quickjs that referenced this issue Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants