about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libbacktrace/0002-libbacktrace-Allow-configuring-debug-dir.patch
blob: ee6063875091c2351de35c7024e8c59f18060831 (plain) (blame)
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
From 2ceaa9bc8a9a0c8a02806a92e19bd21b3fccf3a0 Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Sat, 24 Dec 2022 16:46:18 +0100
Subject: [PATCH 2/4] libbacktrace: Allow configuring debug dir
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On platforms that do not use FHS like NixOS or GNU Guix,
the build-id directories are not under `/usr/lib/debug`.

Let’s add `--with-separate-debug-dir` configure flag so that
the path can be changed. The same flag is supported by gdb:

https://github.com/bminor/binutils-gdb/blob/095f84c7e3cf85cd68c657c46b80be078f336bc9/gdb/configure.ac#L113-L115
---
 Makefile.am  | 13 +++++++------
 configure.ac |  8 ++++++++
 elf.c        |  4 ++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 06ccf3f..6304faa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,7 +33,8 @@ ACLOCAL_AMFLAGS = -I config
 
 AM_CPPFLAGS =
 
-AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
+AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG) \
+	-DSYSTEM_DEBUG_DIR=\"$(SEPARATE_DEBUG_DIR)\"
 
 include_HEADERS = backtrace.h backtrace-supported.h
 
@@ -134,7 +135,7 @@ libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
 if HAVE_ELF
 if HAVE_OBJCOPY_DEBUGLINK
 
-TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
+TEST_DEBUG_DIR=$(abs_builddir)/usr/lib/debug
 
 check_LTLIBRARIES += libbacktrace_elf_for_test.la
 
@@ -143,8 +144,8 @@ libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
 	$(VIEW_FILE) $(ALLOC_FILE)
 
 elf_for_test.c: elf.c
-	SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
-	REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
+	SEARCH='^#define BUILD_ID_DIR.*$$'; \
+	REPLACE='\0\n#undef SYSTEM_DEBUG_DIR\n#define SYSTEM_DEBUG_DIR "$(TEST_DEBUG_DIR)"'; \
 	$(SED) "s%$$SEARCH%$$REPLACE%" \
 		$< \
 		> $@.tmp
@@ -474,13 +475,13 @@ endif HAVE_OBJCOPY_DEBUGLINK
 
 %_buildid: %
 	./install-debuginfo-for-buildid.sh \
-	  "$(TEST_BUILD_ID_DIR)" \
+	  "$(TEST_DEBUG_DIR)/.build-id" \
 	  $<
 	$(OBJCOPY) --strip-debug $< $@
 
 %_buildidfull: %
 	./install-debuginfo-for-buildid.sh \
-	  "$(TEST_BUILD_ID_DIR)" \
+	  "$(TEST_DEBUG_DIR)/.build-id" \
 	  $<
 	$(OBJCOPY) --strip-all $< $@
 
diff --git a/configure.ac b/configure.ac
index 69304ea..aeb2ee9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,14 @@ AM_MAINTAINER_MODE
 AC_ARG_WITH(target-subdir,
 [  --with-target-subdir=SUBDIR      Configuring in a subdirectory for target])
 
+AC_ARG_WITH(separate-debug-dir,
+[  --with-separate-debug-dir=DEBUGDIR      Look for global separate debug info in this path @<:@LIBDIR/debug@:>@],
+[separate_debug_dir=$withval],
+[separate_debug_dir=$libdir/debug])
+
+SEPARATE_DEBUG_DIR=$separate_debug_dir
+AC_SUBST(SEPARATE_DEBUG_DIR)
+
 # We must force CC to /not/ be precious variables; otherwise
 # the wrong, non-multilib-adjusted value will be used in multilibs.
 # As a side effect, we have to subst CFLAGS ourselves.
diff --git a/elf.c b/elf.c
index 3ef07bb..21fbe4f 100644
--- a/elf.c
+++ b/elf.c
@@ -856,7 +856,7 @@ elf_readlink (struct backtrace_state *state, const char *filename,
     }
 }
 
-#define SYSTEM_BUILD_ID_DIR "/usr/lib/debug/.build-id/"
+#define BUILD_ID_DIR "/.build-id/"
 
 /* Open a separate debug info file, using the build ID to find it.
    Returns an open file descriptor, or -1.
@@ -870,7 +870,7 @@ elf_open_debugfile_by_buildid (struct backtrace_state *state,
 			       backtrace_error_callback error_callback,
 			       void *data)
 {
-  const char * const prefix = SYSTEM_BUILD_ID_DIR;
+  const char * const prefix = SYSTEM_DEBUG_DIR BUILD_ID_DIR;
   const size_t prefix_len = strlen (prefix);
   const char * const suffix = ".debug";
   const size_t suffix_len = strlen (suffix);
-- 
2.43.1