[Mesa-dev] [PATCH 2/2] anv: Use build-id for pipeline cache UUID.

Matt Turner mattst88 at gmail.com
Tue Feb 14 18:51:40 UTC 2017


The --build-id=... ld flag has been present since binutils-2.18,
released 28 Aug 2007.
---
 src/intel/vulkan/Makefile.am  |  1 +
 src/intel/vulkan/anv_device.c | 31 ++++++++++++-------------------
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
index 95f276e..4197b0e 100644
--- a/src/intel/vulkan/Makefile.am
+++ b/src/intel/vulkan/Makefile.am
@@ -165,6 +165,7 @@ libvulkan_intel_la_LDFLAGS = \
 	-module \
 	-no-undefined \
 	-avoid-version \
+	-Wl,--build-id=sha1 \
 	$(BSYMBOLIC) \
 	$(GC_SECTIONS) \
 	$(LD_NO_UNDEFINED)
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 91ee67f..f09fd23 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -21,18 +21,17 @@
  * IN THE SOFTWARE.
  */
 
-#include <dlfcn.h>
 #include <assert.h>
 #include <stdbool.h>
 #include <string.h>
 #include <sys/mman.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 
 #include "anv_private.h"
 #include "util/strtod.h"
 #include "util/debug.h"
+#include "util/build_id.h"
 
 #include "genxml/gen7_pack.h"
 
@@ -55,30 +54,24 @@ compiler_perf_log(void *data, const char *fmt, ...)
 }
 
 static bool
-anv_get_function_timestamp(void *ptr, uint32_t* timestamp)
+anv_device_get_cache_uuid(void *uuid)
 {
-   Dl_info info;
-   struct stat st;
-   if (!dladdr(ptr, &info) || !info.dli_fname)
+   const struct note *note = build_id_find_nhdr("libvulkan_intel.so");
+   if (!note)
       return false;
 
-   if (stat(info.dli_fname, &st))
+   unsigned len = build_id_length(note);
+   if (len < VK_UUID_SIZE)
       return false;
 
-   *timestamp = st.st_mtim.tv_sec;
-   return true;
-}
-
-static bool
-anv_device_get_cache_uuid(void *uuid)
-{
-   uint32_t timestamp;
-
-   memset(uuid, 0, VK_UUID_SIZE);
-   if (!anv_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
+   unsigned char *build_id = malloc(len);
+   if (!build_id)
       return false;
 
-   snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);
+   build_id_read(note, build_id);
+
+   memcpy(uuid, build_id, VK_UUID_SIZE);
+   free(build_id);
    return true;
 }
 
-- 
2.10.2



More information about the mesa-dev mailing list