[Mesa-dev] [PATCH v2] intel: tools: fix build on old systems

Lionel Landwerlin lionel.g.landwerlin at intel.com
Fri Jul 6 10:01:23 UTC 2018


Older system might not have support for memfd_create at the kernel
level. There we won't be able to use aubinator.

We also initially tried to workaround some libc having the
memfd_create syscall number defined, but not the memfd_create()
function.

This change makes dealing with the 2 problems above simpler by
creating our own syscall wrapper regardless. Aubinator won't be
compiled if the syscall number isn't defined.

v2: Simplify dealing with memfd_create (Matt)
    Print error message if memfd_create syscall number not found (Eric)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 configure.ac                     | 13 +++++++++++--
 meson.build                      |  2 +-
 src/intel/Makefile.tools.am      |  6 +++++-
 src/intel/tools/aubinator.c      |  9 +++------
 src/intel/tools/meson.build      | 30 ++++++++++++++++++++----------
 src/intel/vulkan/anv_allocator.c |  6 ++----
 6 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index f135d057365..f2c1bd1cd8e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -875,7 +875,16 @@ AC_CHECK_HEADERS([endian.h])
 AC_CHECK_FUNC([strtof], [DEFINES="$DEFINES -DHAVE_STRTOF"])
 AC_CHECK_FUNC([mkostemp], [DEFINES="$DEFINES -DHAVE_MKOSTEMP"])
 AC_CHECK_FUNC([timespec_get], [DEFINES="$DEFINES -DHAVE_TIMESPEC_GET"])
-AC_CHECK_FUNC([memfd_create], [DEFINES="$DEFINES -DHAVE_MEMFD_CREATE"])
+AC_CHECK_FUNC([memfd_create], [MEMFD_CREATE=yes], [MEMFD_CREATE=no])
+
+AC_COMPILE_IFELSE(
+[AC_LANG_PROGRAM([], [[
+#include <sys/syscall.h>
+int main() { return SYS_memfd_create; }
+]])],
+have_memfd_nr=yes; AC_MSG_RESULT(yes),
+AC_MSG_RESULT(no))
+AM_CONDITIONAL(HAVE_MEMFD_CREATE, test "x$have_memfd_nr" = xyes)
 
 AC_MSG_CHECKING([whether strtod has locale support])
 AC_LINK_IFELSE([AC_LANG_SOURCE([[
@@ -2900,7 +2909,7 @@ if test "x$enable_llvm" = xyes; then
     fi
 
     dnl The gallium-xlib GLX and gallium OSMesa targets directly embed the
-    dnl swr/llvmpipe driver into the final binary.  Adding LLVM_LIBS results in 
+    dnl swr/llvmpipe driver into the final binary.  Adding LLVM_LIBS results in
     dnl the LLVM library propagated in the Libs.private of the respective .pc
     dnl file which ensures complete dependency information when statically
     dnl linking.
diff --git a/meson.build b/meson.build
index 7d12af3d510..73a004b77a1 100644
--- a/meson.build
+++ b/meson.build
@@ -960,7 +960,7 @@ elif cc.has_header_symbol('sys/mkdev.h', 'major')
   pre_args += '-DMAJOR_IN_MKDEV'
 endif
 
-foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h', 'endian.h']
+foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h', 'endian.h', 'sys/memfd.h']
   if cc.compiles('#include <@0@>'.format(h), name : '@0@'.format(h))
     pre_args += '-DHAVE_ at 0@'.format(h.to_upper().underscorify())
   endif
diff --git a/src/intel/Makefile.tools.am b/src/intel/Makefile.tools.am
index b00cc8cc2cb..16cc1095f62 100644
--- a/src/intel/Makefile.tools.am
+++ b/src/intel/Makefile.tools.am
@@ -19,8 +19,12 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
+if HAVE_MEMFD_CREATE
+noinst_PROGRAMS += \
+	tools/aubinator
+endif
+
 noinst_PROGRAMS += \
-	tools/aubinator \
 	tools/aubinator_error_decode
 
 tools_aubinator_SOURCES = \
diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
index 8989d558b66..a7b8697960a 100644
--- a/src/intel/tools/aubinator.c
+++ b/src/intel/tools/aubinator.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/mman.h>
+#include <sys/syscall.h>
 
 #include "util/list.h"
 #include "util/macros.h"
@@ -46,15 +47,11 @@
 #include "common/gen_gem.h"
 #include "intel_aub.h"
 
-#ifndef HAVE_MEMFD_CREATE
-#include <sys/syscall.h>
-
 static inline int
-memfd_create(const char *name, unsigned int flags)
+local_memfd_create(const char *name, unsigned int flags)
 {
    return syscall(SYS_memfd_create, name, flags);
 }
-#endif
 
 /* Below is the only command missing from intel_aub.h in libdrm
  * So, reuse intel_aub.h from libdrm and #define the
@@ -907,7 +904,7 @@ int main(int argc, char *argv[])
    if (isatty(1) && pager)
       setup_pager();
 
-   mem_fd = memfd_create("phys memory", 0);
+   mem_fd = local_memfd_create("phys memory", 0);
 
    list_inithead(&maps);
 
diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build
index 705a353f26a..bf1db7c4542 100644
--- a/src/intel/tools/meson.build
+++ b/src/intel/tools/meson.build
@@ -18,16 +18,26 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-aubinator = executable(
-  'aubinator',
-  files('aubinator.c', 'intel_aub.h'),
-  dependencies : [dep_expat, dep_zlib, dep_dl, dep_thread, dep_m],
-  include_directories : [inc_common, inc_intel],
-  link_with : [libintel_common, libintel_compiler, libintel_dev, libmesa_util],
-  c_args : [c_vis_args, no_override_init_args],
-  build_by_default : with_tools.contains('intel'),
-  install : with_tools.contains('intel'),
-)
+has_memfd_create = cc.compiles('''#include <sys/syscall.h>
+                                  int main() {
+                                     return SYS_memfd_create;
+                                  }''',
+                               name : 'memfd create')
+
+if has_memfd_create
+  aubinator = executable(
+    'aubinator',
+    files('aubinator.c', 'intel_aub.h'),
+    dependencies : [dep_expat, dep_zlib, dep_dl, dep_thread, dep_m],
+    include_directories : [inc_common, inc_intel],
+    link_with : [libintel_common, libintel_compiler, libintel_dev, libmesa_util],
+    c_args : [c_vis_args, no_override_init_args],
+    build_by_default : with_tools.contains('intel'),
+    install : with_tools.contains('intel'),
+  )
+else
+  warning('''aubinator can't be built without memfd_create() support''')
+endif
 
 aubinator_error_decode = executable(
   'aubinator_error_decode',
diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index ab01d46cbeb..0805d992a29 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -109,13 +109,11 @@ struct anv_mmap_cleanup {
 
 #define ANV_MMAP_CLEANUP_INIT ((struct anv_mmap_cleanup){0})
 
-#ifndef HAVE_MEMFD_CREATE
 static inline int
-memfd_create(const char *name, unsigned int flags)
+local_memfd_create(const char *name, unsigned int flags)
 {
    return syscall(SYS_memfd_create, name, flags);
 }
-#endif
 
 static inline uint32_t
 ilog2_round_up(uint32_t value)
@@ -255,7 +253,7 @@ anv_block_pool_init(struct anv_block_pool *pool,
 
    anv_bo_init(&pool->bo, 0, 0);
 
-   pool->fd = memfd_create("block pool", MFD_CLOEXEC);
+   pool->fd = local_memfd_create("block pool", MFD_CLOEXEC);
    if (pool->fd == -1)
       return vk_error(VK_ERROR_INITIALIZATION_FAILED);
 
-- 
2.18.0



More information about the mesa-dev mailing list