This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: [PATCH] Support -plugin-opt=disable-output for LLVM plugin


I would be happy to transition the plugin to an exit callback if that
was supported by both bfd and gold.

Thanks,
Rafael


On 11 February 2015 at 18:41, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Should we support -plugin-opt=disable-output for LLVM plugin? If yes,
> is this the right approach?
>
>
> H.J.
> ---
> LLVM plugin uses --plugin-opt=disable-output to disable output.
> all_symbols_read_hook() calls exit() to disable output when
> --plugin-opt=disable-output is passed to LLVM plugin.  This patch
> registers plugin_cleanup() with atexit(), which removes output file
> if --plugin-opt=disable-output is used.
>
>         PR ld/17878
>         * configure.ac: Check if atexit exists.
>         * config.in: Regenerated.
>         * configure: Likewise.
>         * plugin.c (plugin_t): Add disable_output.
>         (plugin_opt_plugin_arg): Set disable_output for disable-output.
>         (plugin_cleanup): New.
>         (plugin_load_plugins): Register plugin_cleanup() with atexit().
> ---
>  ld/config.in    |  3 +++
>  ld/configure    | 12 ++++++++++++
>  ld/configure.ac |  2 ++
>  ld/plugin.c     | 31 +++++++++++++++++++++++++++++++
>  4 files changed, 48 insertions(+)
>
> diff --git a/ld/config.in b/ld/config.in
> index ad015fe..fe6592d 100644
> --- a/ld/config.in
> +++ b/ld/config.in
> @@ -17,6 +17,9 @@
>  /* Define to choose default GOT handling scheme */
>  #undef GOT_HANDLING_DEFAULT
>
> +/* Define to 1 if you have the `atexit' function. */
> +#undef HAVE_ATEXIT
> +
>  /* Define to 1 if you have the `close' function. */
>  #undef HAVE_CLOSE
>
> diff --git a/ld/configure b/ld/configure
> index 7af2626..fd2fedb 100755
> --- a/ld/configure
> +++ b/ld/configure
> @@ -16549,6 +16549,18 @@ fi
>  fi
>
>
> +for ac_func in atexit
> +do :
> +  ac_fn_c_check_func "$LINENO" "atexit" "ac_cv_func_atexit"
> +if test "x$ac_cv_func_atexit" = x""yes; then :
> +  cat >>confdefs.h <<_ACEOF
> +#define HAVE_ATEXIT 1
> +_ACEOF
> +
> +fi
> +done
> +
> +
>  for ac_header in stdlib.h unistd.h
>  do :
>    as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
> diff --git a/ld/configure.ac b/ld/configure.ac
> index e926c03..2f7d626 100644
> --- a/ld/configure.ac
> +++ b/ld/configure.ac
> @@ -195,6 +195,8 @@ AC_CHECK_FUNCS(glob mkstemp realpath sbrk setlocale waitpid)
>  AC_CHECK_FUNCS(open lseek close)
>  AC_HEADER_DIRENT
>
> +AC_CHECK_FUNCS(atexit)
> +
>  dnl AC_CHECK_HEADERS(sys/mman.h)
>  AC_FUNC_MMAP
>
> diff --git a/ld/plugin.c b/ld/plugin.c
> index 4fee305..4640d38 100644
> --- a/ld/plugin.c
> +++ b/ld/plugin.c
> @@ -88,6 +88,8 @@ typedef struct plugin
>    ld_plugin_cleanup_handler cleanup_handler;
>    /* TRUE if the cleanup handlers have been called.  */
>    bfd_boolean cleanup_done;
> +  /* TRUE if output should be disabled.  */
> +  bfd_boolean disable_output;
>  } plugin_t;
>
>  typedef struct view_buffer
> @@ -283,6 +285,11 @@ plugin_opt_plugin_arg (const char *arg)
>    *last_plugin_args_tail_chain_ptr = newarg;
>    last_plugin_args_tail_chain_ptr = &newarg->next;
>    last_plugin->n_args++;
> +
> +  /* LLVM plugin uses --plugin-opt=disable-output to disable output.  */
> +  if (strcmp (arg, "disable-output") == 0)
> +    last_plugin->disable_output = TRUE;
> +
>    return 0;
>  }
>
> @@ -934,6 +941,24 @@ set_tv_plugin_args (plugin_t *plugin, struct ld_plugin_tv *tv)
>    tv->tv_u.tv_val = 0;
>  }
>
> +#if HAVE_ATEXIT
> +static void
> +plugin_cleanup (void)
> +{
> +  plugin_t *curplug = plugins_list;
> +  while (curplug)
> +    {
> +      if (curplug->all_symbols_read_handler
> +         && curplug->disable_output)
> +       {
> +         unlink_if_ordinary (output_filename);
> +         break;
> +       }
> +      curplug = curplug->next;
> +    }
> +}
> +#endif
> +
>  /* Load up and initialise all plugins after argument parsing.  */
>  void
>  plugin_load_plugins (void)
> @@ -994,6 +1019,12 @@ plugin_load_plugins (void)
>
>    register_ld_plugin_object_p (plugin_object_p);
>
> +#if HAVE_ATEXIT
> +  /* Since all_symbols_read_hook() in LLVM plugin calls exit() to
> +     disable output, we must register plugin_cleanup() with atexit().  */
> +  atexit (plugin_cleanup);
> +#endif
> +
>  #if HAVE_MMAP && HAVE_GETPAGESIZE
>    plugin_pagesize = getpagesize ();;
>  #endif
> --
> 1.9.3
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]