This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
mesa-use-build-id.patch
141 lines (133 loc) · 3.57 KB
/
mesa-use-build-id.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
diff -ur mesa.old/src/util/disk_cache.c mesa/src/util/disk_cache.c
--- mesa.old/src/util/disk_cache.c 2018-07-27 15:52:17.000000000 +0200
+++ mesa/src/util/disk_cache.c 2018-09-01 21:43:23.820241362 +0200
@@ -37,6 +37,8 @@
#include <pwd.h>
#include <errno.h>
#include <dirent.h>
+#include <elf.h>
+#include <link.h>
#include "zlib.h"
#include "util/crc32.h"
@@ -1279,4 +1281,81 @@
cache->blob_get_cb = get;
}
+bool
+disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
+{
+ int fd = -1;
+ struct stat st;
+ char *elf_start = MAP_FAILED;
+ Dl_info info;
+ struct link_map *ln;
+
+ if (!dladdr1(ptr, &info, (void**)&ln, RTLD_DL_LINKMAP) || !info.dli_fname) {
+ goto cleanup;
+ }
+
+ if (ln->l_name == NULL) {
+ goto cleanup;
+ }
+
+ fd = open(ln->l_name, O_RDONLY);
+ if (fd == -1) {
+ goto cleanup;
+ }
+
+ if (0 != fstat(fd, &st)) {
+ goto cleanup;
+ }
+
+ elf_start = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (elf_start == MAP_FAILED) {
+ goto cleanup;
+ }
+
+ ElfW(Ehdr) *elf = (ElfW(Ehdr) *)elf_start;
+ if (elf->e_shentsize != sizeof(ElfW(Shdr))) {
+ goto cleanup;
+ }
+
+ ElfW(Shdr)* section_table = (ElfW(Shdr)*)(elf_start + elf->e_shoff);
+
+ if (elf->e_shstrndx >= elf->e_shnum) {
+ goto cleanup;
+ }
+
+ ElfW(Shdr)* string_header = section_table + elf->e_shstrndx;
+ char* stringsdata = (char*)elf + string_header->sh_offset;
+
+ for (ElfW(Half) i = 0; i < elf->e_shnum; ++i) {
+ ElfW(Shdr)* header = section_table + i;
+
+ if (header->sh_name >= string_header->sh_size) {
+ goto cleanup;
+ }
+ char *name = stringsdata + header->sh_name;
+ if ((SHT_NOTE == header->sh_type) &&
+ (0 == strncmp(name, ".note.gnu.build-id", 18))) {
+ char *note = (char*)elf + header->sh_offset;
+ ElfW(Nhdr)* note_header = (ElfW(Nhdr)*)note;
+ if (note_header->n_type != NT_GNU_BUILD_ID)
+ continue ;
+ char* note_data = note + sizeof(ElfW(Nhdr)) + note_header->n_namesz;
+ *timestamp = util_hash_crc32(note_data, note_header->n_descsz);
+ munmap((void*)elf_start, st.st_size);
+ close(fd);
+ return true;
+ }
+ }
+
+
+ cleanup:
+ if (elf_start != MAP_FAILED) {
+ munmap((void*)elf_start, st.st_size);
+ }
+ if (fd != -1) {
+ close(fd);
+ }
+ return false;
+}
+
#endif /* ENABLE_SHADER_CACHE */
diff -ur mesa.old/src/util/disk_cache.h mesa/src/util/disk_cache.h
--- mesa.old/src/util/disk_cache.h 2018-07-27 15:52:17.000000000 +0200
+++ mesa/src/util/disk_cache.h 2018-09-01 21:36:56.795907626 +0200
@@ -88,22 +88,8 @@
return buf;
}
-#ifdef HAVE_DLFCN_H
-static inline bool
-disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
-{
- Dl_info info;
- struct stat st;
- if (!dladdr(ptr, &info) || !info.dli_fname) {
- return false;
- }
- if (stat(info.dli_fname, &st)) {
- return false;
- }
- *timestamp = st.st_mtime;
- return true;
-}
-#endif
+bool
+disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp);
/* Provide inlined stub functions if the shader cache is disabled. */
diff -up mesa-7/src/util/Makefile.am.foo mesa-7/src/util/Makefile.am
--- mesa-7/src/util/Makefile.am.foo 2018-09-04 15:10:59.735305261 +0200
+++ mesa-7/src/util/Makefile.am 2018-09-04 15:11:31.365886150 +0200
@@ -32,6 +32,7 @@ noinst_LTLIBRARIES = \
AM_CPPFLAGS = \
$(PTHREAD_CFLAGS) \
+ $(DLOPEN_CFLAGS) \
-I$(top_srcdir)/include
libmesautil_la_CPPFLAGS = \
@@ -54,6 +55,7 @@ libmesautil_la_LIBADD = \
$(PTHREAD_LIBS) \
$(CLOCK_LIB) \
$(ZLIB_LIBS) \
+ $(DLOPEN_LIBS) \
$(LIBATOMIC_LIBS)
libxmlconfig_la_SOURCES = $(XMLCONFIG_FILES)