简体   繁体   中英

How can I undefine a HAVE_[function] macro by passing arguments to Autoconf?

The problem: In the Ruby interpreter C code there's a couple of sections that call the __syscall function on macOS and BSD. This is very bad behaviour in macOS land because it is a private (and volatile) API.

The __syscall usage is only included conditionally based on HAVE_ defines, so I would like to find out if I can compile Ruby without it. Here is an example from io.c :

#if defined(HAVE___SYSCALL) && (defined(__APPLE__) || defined(__OpenBSD__))
/* Mac OS X and OpenBSD have __syscall but don't define it in headers */
    off_t __syscall(quad_t number, ...);
#endif

...some time later...

static VALUE
rb_f_syscall(int argc, VALUE *argv)
{
    VALUE arg[8];

    ...a bunch of platform checks that usually end up doing this...

    # define SYSCALL __syscall

    ...some time later...

    switch (argc) {
      case 1:
        retval = SYSCALL(num);
        break;
      case 2:
        retval = SYSCALL(num, arg[0]);
        break;
      case 3:
        retval = SYSCALL(num, arg[0],arg[1]);
        break;

      ... and so on up to case 8...

    }

    ... function returns and then...

    #undef SYSCALL
}

Sharp-eyed readers will also notice that even the Ruby devs don't like using __syscall - they want to replace it with the DL (Fiddle) library instead.

The constraint: I do not want to fork the Ruby interpreter source to do this as that will lead to continuous cumbersome maintenance of the fork. Instead I would like to pass an argument to the build tool when it compiles Ruby that does this.

The question: Can I force one of the related HAVE__ macros to be undefined, or perhaps disable the AC_CHECK_HEADERS in configure.in, and so prevent the use of __syscall here, by passing an argument to the build tool?

You should be able to tweak one of the ac_cv_* variables at ./configure time.

Particularly, for ruby-2.1.9 this should work:

./configure ac_cv_func___syscall=no

(For reference, you can see the ac_cv_* variables set in config.log .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM