commit aa25119

hovercats  ·  2024-05-13 10:18:26 +0000 UTC
parent af48921
cairo: fetch patch from kiss-xorg, fixing build.
5 files changed,  +455, -26
+12, -26
 1@@ -1,31 +1,17 @@
 2 #!/bin/sh -e
 3 
 4-export DESTDIR="$1"
 5-
 6-# Disable building 'cairo-sphinx'.
 7-sed -e "s/\(BUILD_SPHINX_TRUE=\)/\1'#'/" \
 8-    -e "s/\(BUILD_SPHINX_FALSE=\)'#'/\1=/" \
 9-    configure > _
10-mv -f _ configure
11+patch -p1 < 0001-util-remove-malloc-stats.patch
12 
13-# Disable building tests and documentation.
14-sed 's/boilerplate test perf//g;s/src doc/src/g' Makefile.in > _
15-mv -f _ Makefile.in
16+export DESTDIR="$1"
17 
18-sh ./configure \
19-    --prefix=/usr \
20-    --disable-static \
21-    --enable-tee \
22-    --enable-gl \
23-    --enable-egl \
24-    --enable-xlib-xcb \
25-    --enable-xcb \
26-    --enable-xlib-xrender \
27-    --enable-xlib \
28-    --disable-trace \
29-    --disable-valgrind \
30-    --disable-gtk-doc-html \
31-    ax_cv_c_float_words_bigendian=no
32+meson setup \
33+	-Dprefix=/usr \
34+	-Dtee=enabled \
35+	-Dxcb=enabled \
36+	-Dxlib=enabled \
37+	-Dxlib-xcb=enabled \
38+	-Dtests=disabled \
39+	output
40 
41-make
42-make install
43+samu -C output
44+samu -C output install
+1, -0
1@@ -1 +1,2 @@
2 55b4b6406668e08dd6b816beba82c86df8e9a5468352c66597badb4f6583930e6a
3+b95ab8fb2d9901bff460ae7440811a35067f0ca833894c8ad44c4df6686132bf66
+1, -0
1@@ -5,6 +5,7 @@ libXext
2 libXrender
3 libpng
4 mesa
5+meson   make
6 pixman
7 pkgconf make
8 zlib
+440, -0
  1@@ -0,0 +1,440 @@
  2+From 377f3b5caf0a53590162047e03f1e8803592917b Mon Sep 17 00:00:00 2001
  3+From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= <tim@centricular.com>
  4+Date: Thu, 28 Sep 2023 11:21:53 +0200
  5+Subject: [PATCH] util: remove malloc-stats
  6+
  7+Not really cairo-related and has now been moved into a
  8+separate repository at https://github.com/behdad/malloc-stats
  9+
 10+Fixes #640
 11+---
 12+ util/README         |  16 --
 13+ util/malloc-stats.c | 376 --------------------------------------------
 14+ util/meson.build    |   4 -
 15+ 3 files changed, 396 deletions(-)
 16+ delete mode 100644 util/malloc-stats.c
 17+
 18+diff --git a/util/README b/util/README
 19+index b75ae43..90e1f7f 100644
 20+--- a/util/README
 21++++ b/util/README
 22+@@ -3,22 +3,6 @@ Cairo Utilities
 23+ 
 24+ There are a varieties of utilities we use with cairo.
 25+ 
 26+-
 27+-malloc-stats
 28+-------------
 29+-
 30+-This is a small shared library designed to be preloaded by the
 31+-linker and its purpose is to make the malloc_stats() function
 32+-of glibc produce more useful information.
 33+-
 34+-Build by:
 35+-
 36+-	make malloc-stats.so
 37+-
 38+-and use by:
 39+-
 40+-	LD_PRELOAD=$(blddir)/util/libmalloc-stats.so app-to-run
 41+-
 42+ cairo-trace
 43+ -----------
 44+ 
 45+diff --git a/util/malloc-stats.c b/util/malloc-stats.c
 46+deleted file mode 100644
 47+index a086b05..0000000
 48+--- a/util/malloc-stats.c
 49++++ /dev/null
 50+@@ -1,376 +0,0 @@
 51+-/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
 52+-/*
 53+- * Copyright © 2007 Red Hat, Inc.
 54+- *
 55+- * Permission to use, copy, modify, distribute, and sell this software
 56+- * and its documentation for any purpose is hereby granted without
 57+- * fee, provided that the above copyright notice appear in all copies
 58+- * and that both that copyright notice and this permission notice
 59+- * appear in supporting documentation, and that the name of
 60+- * Red Hat, Inc. not be used in advertising or publicity pertaining to
 61+- * distribution of the software without specific, written prior
 62+- * permission. Red Hat, Inc. makes no representations about the
 63+- * suitability of this software for any purpose.  It is provided "as
 64+- * is" without express or implied warranty.
 65+- *
 66+- * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 67+- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 68+- * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
 69+- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 70+- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 71+- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 72+- * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 73+- *
 74+- * Author: Behdad Esfahbod <behdad@behdad.org>
 75+- */
 76+-
 77+-/* A simple malloc wrapper that prints out statistics on termination */
 78+-
 79+-#ifndef _GNU_SOURCE
 80+-#define _GNU_SOURCE
 81+-#endif
 82+-
 83+-#include <stdlib.h>
 84+-#include <stdio.h>
 85+-#include <stdint.h>
 86+-
 87+-/* caller-logging */
 88+-
 89+-#include <string.h>
 90+-
 91+-struct alloc_stat_t {
 92+-	unsigned int num;
 93+-	unsigned long long size;
 94+-};
 95+-
 96+-struct alloc_stats_t {
 97+-	struct alloc_stat_t malloc, realloc, total;
 98+-};
 99+-
100+-struct func_stat_t {
101+-	struct func_stat_t *next;
102+-
103+-	const void *addr;
104+-	const char *name;
105+-
106+-	struct alloc_stats_t stat;
107+-};
108+-
109+-static struct alloc_stats_t total_allocations;
110+-static struct func_stat_t *func_stats[31627];
111+-static int func_stats_num;
112+-
113+-#ifndef ARRAY_LENGTH
114+-#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
115+-#endif
116+-static void
117+-alloc_stats_add (struct alloc_stats_t *stats, int is_realloc, size_t size)
118+-{
119+-	struct alloc_stat_t *stat = is_realloc ? &stats->realloc : &stats->malloc;
120+-
121+-	stats->total.num++;
122+-	stats->total.size += size;
123+-
124+-	stat->num++;
125+-	stat->size += size;
126+-}
127+-
128+-#include <execinfo.h>
129+-
130+-static void *
131+-_perm_alloc (size_t size)
132+-{
133+-    static uint8_t *ptr;
134+-    static size_t rem;
135+-
136+-    void *ret;
137+-
138+-#define SUPERBLOCK_SIZE (1<<23)
139+-#define align(x, y) (((x) + ((y)-1)) & ~((y)-1))
140+-
141+-    size = align (size, 2 * sizeof (void *));
142+-    if (size > rem || rem == 0) {
143+-	ptr = malloc (SUPERBLOCK_SIZE);
144+-	if (ptr == NULL)
145+-	    exit (1);
146+-	rem = SUPERBLOCK_SIZE;
147+-    }
148+-
149+-#undef SUPERBLOCK_SIZE
150+-#undef align
151+-
152+-    ret = ptr;
153+-    rem -= size;
154+-    ptr += size;
155+-
156+-    return ret;
157+-}
158+-
159+-static void
160+-resolve_addrs (struct func_stat_t *func_stats, int num)
161+-{
162+-	int i;
163+-	void **addrs;
164+-	char **strings;
165+-
166+-	addrs = malloc (num * sizeof (void *));
167+-	for (i = 0; i < num; i++)
168+-		addrs[i] = (void *) func_stats[i].addr;
169+-
170+-	strings = backtrace_symbols (addrs, num);
171+-
172+-	for (i = 0; i < num; i++) {
173+-		char *p;
174+-		char *name;
175+-		int len;
176+-
177+-		p = strchr (strings[i], '\t');
178+-		if (p)
179+-			p++;
180+-		else
181+-			p = strings[i];
182+-
183+-		len = strlen (p) + 1;
184+-		name = _perm_alloc (len);
185+-		memcpy (name, p, len);
186+-		func_stats[i].name = name;
187+-	}
188+-
189+-	free (strings);
190+-	free (addrs);
191+-}
192+-
193+-static void
194+-func_stats_add (const void *caller, int is_realloc, size_t size)
195+-{
196+-	int i;
197+-	struct func_stat_t *elt;
198+-
199+-	alloc_stats_add (&total_allocations, is_realloc, size);
200+-
201+-	i = ((uintptr_t) caller ^ 1215497) % ARRAY_LENGTH (func_stats);
202+-	for (elt = func_stats[i]; elt != NULL; elt = elt->next) {
203+-		if (elt->addr == caller)
204+-			break;
205+-	}
206+-
207+-	if (elt == NULL) {
208+-		func_stats_num++;
209+-
210+-		elt = _perm_alloc (sizeof (struct func_stat_t));
211+-		elt->next = func_stats[i];
212+-		func_stats[i] = elt;
213+-		elt->addr = caller;
214+-		elt->name = NULL;
215+-		memset (&elt->stat, 0, sizeof (struct alloc_stats_t));
216+-	}
217+-
218+-	alloc_stats_add (&elt->stat, is_realloc, size);
219+-}
220+-
221+-/* wrapper stuff */
222+-
223+-#include <dlfcn.h>
224+-
225+-static void *(*old_malloc)(size_t);
226+-static void *(*old_calloc)(size_t, size_t);
227+-static void *(*old_realloc)(void *, size_t);
228+-static int enable_hook = 0;
229+-
230+-static void init(void);
231+-
232+-void *
233+-malloc(size_t size)
234+-{
235+-    if (!old_malloc)
236+-      init ();
237+-
238+-    if (enable_hook) {
239+-	enable_hook = 0;
240+-	void *caller = __builtin_return_address(0);
241+-	func_stats_add (caller, 0, size);
242+-	enable_hook = 1;
243+-    }
244+-
245+-    return old_malloc (size);
246+-}
247+-
248+-void *
249+-calloc(size_t nmemb, size_t size)
250+-{
251+-    if (!old_calloc)
252+-      init ();
253+-
254+-    if (enable_hook) {
255+-	enable_hook = 0;
256+-	void *caller = __builtin_return_address(0);
257+-	func_stats_add (caller, 0, nmemb * size);
258+-	enable_hook = 1;
259+-    }
260+-
261+-    return old_calloc (nmemb, size);
262+-}
263+-
264+-void *
265+-realloc(void *ptr, size_t size)
266+-{
267+-    if (!old_malloc)
268+-      init ();
269+-
270+-    if (enable_hook) {
271+-	enable_hook = 0;
272+-	void *caller = __builtin_return_address(0);
273+-	func_stats_add (caller, 1, size);
274+-	enable_hook = 1;
275+-    }
276+-
277+-    return old_realloc (ptr, size);
278+-}
279+-
280+-static void
281+-init(void)
282+-{
283+-    old_malloc = dlsym(RTLD_NEXT, "malloc");
284+-    if (!old_malloc) {
285+-	fprintf(stderr, "%s\n", dlerror());
286+-	exit(1);
287+-    }
288+-    old_calloc = dlsym(RTLD_NEXT, "calloc");
289+-    if (!old_calloc) {
290+-	fprintf(stderr, "%s\n", dlerror());
291+-	exit(1);
292+-    }
293+-    old_realloc = dlsym(RTLD_NEXT, "realloc");
294+-    if (!old_realloc) {
295+-	fprintf(stderr, "%s\n", dlerror());
296+-	exit(1);
297+-    }
298+-    enable_hook = 1;
299+-}
300+-
301+-/* reporting */
302+-
303+-#include <locale.h>
304+-
305+-static void
306+-add_alloc_stats (struct alloc_stats_t *a, struct alloc_stats_t *b)
307+-{
308+-	a->total.num += b->total.num;
309+-	a->total.size += b->total.size;
310+-	a->malloc.num += b->malloc.num;
311+-	a->malloc.size += b->malloc.size;
312+-	a->realloc.num += b->realloc.num;
313+-	a->realloc.size += b->realloc.size;
314+-}
315+-
316+-static void
317+-dump_alloc_stats (struct alloc_stats_t *stats, const char *name)
318+-{
319+-	printf ("%8u %'11llu %8u %'11llu %8u %'11llu %s\n",
320+-		stats->total.num, stats->total.size,
321+-		stats->malloc.num, stats->malloc.size,
322+-		stats->realloc.num, stats->realloc.size,
323+-		name);
324+-}
325+-
326+-static int
327+-compare_func_stats_name (const void *pa, const void *pb)
328+-{
329+-	const struct func_stat_t *a = pa, *b = pb;
330+-	int i;
331+-
332+-	i = strcmp (a->name, b->name);
333+-	if (i)
334+-		return i;
335+-
336+-	return ((char *) a->addr - (char *) b->addr);
337+-}
338+-
339+-static int
340+-compare_func_stats (const void *pa, const void *pb)
341+-{
342+-	const struct func_stat_t *a = pa, *b = pb;
343+-
344+-	if (a->stat.total.num != b->stat.total.num)
345+-		return (a->stat.total.num - b->stat.total.num);
346+-
347+-	if (a->stat.total.size != b->stat.total.size)
348+-		return (a->stat.total.size - b->stat.total.size);
349+-
350+-	return compare_func_stats_name (pa, pb);
351+-}
352+-
353+-static int
354+-merge_similar_entries (struct func_stat_t *func_stats, int num)
355+-{
356+-	int i, j;
357+-
358+-	j = 0;
359+-	for (i = 1; i < num; i++) {
360+-		if (i != j && 0 == strcmp (func_stats[i].name, func_stats[j].name)) {
361+-			add_alloc_stats (&func_stats[j].stat, &func_stats[i].stat);
362+-		} else {
363+-			j++;
364+-			if (i != j)
365+-				func_stats[j] = func_stats[i];
366+-		}
367+-	}
368+-	j++;
369+-
370+-	return j;
371+-}
372+-
373+-__attribute__ ((destructor))
374+-static void
375+-malloc_stats (void)
376+-{
377+-	unsigned int i, j;
378+-	struct func_stat_t *sorted_func_stats;
379+-
380+-	enable_hook = 0;
381+-
382+-	if (! func_stats_num)
383+-		return;
384+-
385+-	sorted_func_stats = malloc (sizeof (struct func_stat_t) * (func_stats_num + 1));
386+-	if (sorted_func_stats == NULL)
387+-		return;
388+-
389+-	j = 0;
390+-	for (i = 0; i < ARRAY_LENGTH (func_stats); i++) {
391+-		struct func_stat_t *elt;
392+-		for (elt = func_stats[i]; elt != NULL; elt = elt->next)
393+-			sorted_func_stats[j++] = *elt;
394+-	}
395+-
396+-	resolve_addrs (sorted_func_stats, j);
397+-
398+-	/* merge entries with same name */
399+-	qsort (sorted_func_stats, j,
400+-	       sizeof (struct func_stat_t), compare_func_stats_name);
401+-	j = merge_similar_entries (sorted_func_stats, j);
402+-
403+-	qsort (sorted_func_stats, j,
404+-	       sizeof (struct func_stat_t), compare_func_stats);
405+-
406+-	/* add total */
407+-	sorted_func_stats[j].next = NULL;
408+-	sorted_func_stats[j].addr = (void *) -1;
409+-	sorted_func_stats[j].name = "(total)";
410+-	sorted_func_stats[j].stat = total_allocations;
411+-	j++;
412+-
413+-	setlocale (LC_ALL, "");
414+-
415+-	printf ("          TOTAL                MALLOC              REALLOC\n");
416+-	printf ("     num        size      num        size      num        size\n");
417+-
418+-	for (i = 0; i < j; i++) {
419+-		dump_alloc_stats (&sorted_func_stats[i].stat,
420+-				  sorted_func_stats[i].name);
421+-	}
422+-
423+-	/* XXX free other stuff? */
424+-
425+-	free (sorted_func_stats);
426+-}
427+diff --git a/util/meson.build b/util/meson.build
428+index d64dbad..1e186bf 100644
429+--- a/util/meson.build
430++++ b/util/meson.build
431+@@ -41,7 +41,3 @@ foreach util : cairo_utils
432+     dependencies: deps + util_deps + [libcairo_dep, libcairoscript_dep],
433+   )
434+ endforeach
435+-
436+-if conf.get('CAIRO_HAS_DLSYM', 0) == 1 and cc.has_header('execinfo.h')
437+-  libmallocstats = library('malloc-stats', 'malloc-stats.c', dependencies : dl_dep)
438+-endif
439+-- 
440+2.44.0
441+
+1, -0
1@@ -1 +1,2 @@
2 https://cairographics.org/releases/cairo-1.18.0.tar.xz
3+patches/0001-util-remove-malloc-stats.patch