gnome-podcasts: 0.7.1 -> 0.7.2 (#373846)
[NixPkgs.git] / pkgs / by-name / li / libbacktrace / 0002-libbacktrace-Allow-configuring-debug-dir.patch
blobee6063875091c2351de35c7024e8c59f18060831
1 From 2ceaa9bc8a9a0c8a02806a92e19bd21b3fccf3a0 Mon Sep 17 00:00:00 2001
2 From: Jan Tojnar <jtojnar@gmail.com>
3 Date: Sat, 24 Dec 2022 16:46:18 +0100
4 Subject: [PATCH 2/4] libbacktrace: Allow configuring debug dir
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 On platforms that do not use FHS like NixOS or GNU Guix,
10 the build-id directories are not under `/usr/lib/debug`.
12 Let’s add `--with-separate-debug-dir` configure flag so that
13 the path can be changed. The same flag is supported by gdb:
15 https://github.com/bminor/binutils-gdb/blob/095f84c7e3cf85cd68c657c46b80be078f336bc9/gdb/configure.ac#L113-L115
16 ---
17 Makefile.am | 13 +++++++------
18 configure.ac | 8 ++++++++
19 elf.c | 4 ++--
20 3 files changed, 17 insertions(+), 8 deletions(-)
22 diff --git a/Makefile.am b/Makefile.am
23 index 06ccf3f..6304faa 100644
24 --- a/Makefile.am
25 +++ b/Makefile.am
26 @@ -33,7 +33,8 @@ ACLOCAL_AMFLAGS = -I config
28 AM_CPPFLAGS =
30 -AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
31 +AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG) \
32 + -DSYSTEM_DEBUG_DIR=\"$(SEPARATE_DEBUG_DIR)\"
34 include_HEADERS = backtrace.h backtrace-supported.h
36 @@ -134,7 +135,7 @@ libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
37 if HAVE_ELF
38 if HAVE_OBJCOPY_DEBUGLINK
40 -TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
41 +TEST_DEBUG_DIR=$(abs_builddir)/usr/lib/debug
43 check_LTLIBRARIES += libbacktrace_elf_for_test.la
45 @@ -143,8 +144,8 @@ libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
46 $(VIEW_FILE) $(ALLOC_FILE)
48 elf_for_test.c: elf.c
49 - SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
50 - REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
51 + SEARCH='^#define BUILD_ID_DIR.*$$'; \
52 + REPLACE='\0\n#undef SYSTEM_DEBUG_DIR\n#define SYSTEM_DEBUG_DIR "$(TEST_DEBUG_DIR)"'; \
53 $(SED) "s%$$SEARCH%$$REPLACE%" \
54 $< \
55 > $@.tmp
56 @@ -474,13 +475,13 @@ endif HAVE_OBJCOPY_DEBUGLINK
58 %_buildid: %
59 ./install-debuginfo-for-buildid.sh \
60 - "$(TEST_BUILD_ID_DIR)" \
61 + "$(TEST_DEBUG_DIR)/.build-id" \
63 $(OBJCOPY) --strip-debug $< $@
65 %_buildidfull: %
66 ./install-debuginfo-for-buildid.sh \
67 - "$(TEST_BUILD_ID_DIR)" \
68 + "$(TEST_DEBUG_DIR)/.build-id" \
70 $(OBJCOPY) --strip-all $< $@
72 diff --git a/configure.ac b/configure.ac
73 index 69304ea..aeb2ee9 100644
74 --- a/configure.ac
75 +++ b/configure.ac
76 @@ -67,6 +67,14 @@ AM_MAINTAINER_MODE
77 AC_ARG_WITH(target-subdir,
78 [ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
80 +AC_ARG_WITH(separate-debug-dir,
81 +[ --with-separate-debug-dir=DEBUGDIR Look for global separate debug info in this path @<:@LIBDIR/debug@:>@],
82 +[separate_debug_dir=$withval],
83 +[separate_debug_dir=$libdir/debug])
85 +SEPARATE_DEBUG_DIR=$separate_debug_dir
86 +AC_SUBST(SEPARATE_DEBUG_DIR)
88 # We must force CC to /not/ be precious variables; otherwise
89 # the wrong, non-multilib-adjusted value will be used in multilibs.
90 # As a side effect, we have to subst CFLAGS ourselves.
91 diff --git a/elf.c b/elf.c
92 index 3ef07bb..21fbe4f 100644
93 --- a/elf.c
94 +++ b/elf.c
95 @@ -856,7 +856,7 @@ elf_readlink (struct backtrace_state *state, const char *filename,
99 -#define SYSTEM_BUILD_ID_DIR "/usr/lib/debug/.build-id/"
100 +#define BUILD_ID_DIR "/.build-id/"
102 /* Open a separate debug info file, using the build ID to find it.
103 Returns an open file descriptor, or -1.
104 @@ -870,7 +870,7 @@ elf_open_debugfile_by_buildid (struct backtrace_state *state,
105 backtrace_error_callback error_callback,
106 void *data)
108 - const char * const prefix = SYSTEM_BUILD_ID_DIR;
109 + const char * const prefix = SYSTEM_DEBUG_DIR BUILD_ID_DIR;
110 const size_t prefix_len = strlen (prefix);
111 const char * const suffix = ".debug";
112 const size_t suffix_len = strlen (suffix);
114 2.43.1