Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at fix-function-merge 115 lines 3.8 kB view raw
1From 2ceaa9bc8a9a0c8a02806a92e19bd21b3fccf3a0 Mon Sep 17 00:00:00 2001 2From: Jan Tojnar <jtojnar@gmail.com> 3Date: Sat, 24 Dec 2022 16:46:18 +0100 4Subject: [PATCH 2/4] libbacktrace: Allow configuring debug dir 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9On platforms that do not use FHS like NixOS or GNU Guix, 10the build-id directories are not under `/usr/lib/debug`. 11 12Let’s add `--with-separate-debug-dir` configure flag so that 13the path can be changed. The same flag is supported by gdb: 14 15https://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(-) 21 22diff --git a/Makefile.am b/Makefile.am 23index 06ccf3f..6304faa 100644 24--- a/Makefile.am 25+++ b/Makefile.am 26@@ -33,7 +33,8 @@ ACLOCAL_AMFLAGS = -I config 27 28 AM_CPPFLAGS = 29 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)\" 33 34 include_HEADERS = backtrace.h backtrace-supported.h 35 36@@ -134,7 +135,7 @@ libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD) 37 if HAVE_ELF 38 if HAVE_OBJCOPY_DEBUGLINK 39 40-TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/ 41+TEST_DEBUG_DIR=$(abs_builddir)/usr/lib/debug 42 43 check_LTLIBRARIES += libbacktrace_elf_for_test.la 44 45@@ -143,8 +144,8 @@ libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \ 46 $(VIEW_FILE) $(ALLOC_FILE) 47 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 57 58 %_buildid: % 59 ./install-debuginfo-for-buildid.sh \ 60- "$(TEST_BUILD_ID_DIR)" \ 61+ "$(TEST_DEBUG_DIR)/.build-id" \ 62 $< 63 $(OBJCOPY) --strip-debug $< $@ 64 65 %_buildidfull: % 66 ./install-debuginfo-for-buildid.sh \ 67- "$(TEST_BUILD_ID_DIR)" \ 68+ "$(TEST_DEBUG_DIR)/.build-id" \ 69 $< 70 $(OBJCOPY) --strip-all $< $@ 71 72diff --git a/configure.ac b/configure.ac 73index 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]) 79 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]) 84+ 85+SEPARATE_DEBUG_DIR=$separate_debug_dir 86+AC_SUBST(SEPARATE_DEBUG_DIR) 87+ 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. 91diff --git a/elf.c b/elf.c 92index 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, 96 } 97 } 98 99-#define SYSTEM_BUILD_ID_DIR "/usr/lib/debug/.build-id/" 100+#define BUILD_ID_DIR "/.build-id/" 101 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) 107 { 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); 113-- 1142.43.1 115