jit-result.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Internals of libgccjit: implementation of gcc_jit_result
  2. Copyright (C) 2013-2015 Free Software Foundation, Inc.
  3. Contributed by David Malcolm <dmalcolm@redhat.com>.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "jit-common.h"
  20. #include "jit-logging.h"
  21. #include "jit-result.h"
  22. #include "jit-tempdir.h"
  23. namespace gcc {
  24. namespace jit {
  25. /* Constructor for gcc::jit::result. */
  26. result::
  27. result(logger *logger, void *dso_handle, tempdir *tempdir_) :
  28. log_user (logger),
  29. m_dso_handle (dso_handle),
  30. m_tempdir (tempdir_)
  31. {
  32. JIT_LOG_SCOPE (get_logger ());
  33. }
  34. /* gcc::jit::result's destructor.
  35. Called implicitly by gcc_jit_result_release. */
  36. result::~result()
  37. {
  38. JIT_LOG_SCOPE (get_logger ());
  39. dlclose (m_dso_handle);
  40. /* Responsibility for cleaning up the tempdir (including "fake.so" within
  41. the filesystem) might have been handed to us by the playback::context,
  42. so that the cleanup can be delayed (see PR jit/64206).
  43. If so, clean it up now. */
  44. delete m_tempdir;
  45. }
  46. /* Attempt to locate the given function by name within the
  47. playback::result, using dlsym.
  48. Implements the post-error-checking part of
  49. gcc_jit_result_get_code. */
  50. void *
  51. result::
  52. get_code (const char *funcname)
  53. {
  54. JIT_LOG_SCOPE (get_logger ());
  55. void *code;
  56. const char *error;
  57. /* Clear any existing error. */
  58. dlerror ();
  59. code = dlsym (m_dso_handle, funcname);
  60. if ((error = dlerror()) != NULL) {
  61. fprintf(stderr, "%s\n", error);
  62. }
  63. return code;
  64. }
  65. /* Attempt to locate the given global by name within the
  66. playback::result, using dlsym.
  67. Implements the post-error-checking part of
  68. gcc_jit_result_get_global. */
  69. void *
  70. result::
  71. get_global (const char *name)
  72. {
  73. JIT_LOG_SCOPE (get_logger ());
  74. void *global;
  75. const char *error;
  76. /* Clear any existing error. */
  77. dlerror ();
  78. global = dlsym (m_dso_handle, name);
  79. if ((error = dlerror()) != NULL) {
  80. fprintf(stderr, "%s\n", error);
  81. }
  82. return global;
  83. }
  84. } // namespace gcc::jit
  85. } // namespace gcc