Message ID | CAOyqgcWNyv_NAk+y_5SKd7SV2aVUg4898H94QigpEc5M83ecKQ@mail.gmail.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp841389dyb; Thu, 29 Feb 2024 19:48:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVjngmKB+uPPipmiZOETvL1sP3aF4VAKu+2UNEHS+cIJDC7iBiqhR3Sp7QurAI1lw5xcXtCAsv/YBkNqv7HdDYPRuvZxA== X-Google-Smtp-Source: AGHT+IFJbhNsc7zOVLS6+OVeX0SMJHb59lY2upowfgUFxID0inGDKhfgCz84PzojUV9H40TbTPXg X-Received: by 2002:a0c:e909:0:b0:690:2164:d977 with SMTP id a9-20020a0ce909000000b006902164d977mr539248qvo.36.1709264886379; Thu, 29 Feb 2024 19:48:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709264886; cv=pass; d=google.com; s=arc-20160816; b=rr5aT3cPfWq+v5nJKjYwgGhPRmFreGT9aUrol7zwPCfL4Ab4G253hBgfpZTQ2yrTgC G031LaKC1iHIHxD6kdFHe6NLJpJeP76H/GhI8rM5uyOpe/7r9OsJUItPtcC3g988agiI I82iN/ehtwy5i5TeUryWupJP4t0xINdbra+x8P910pcvlSHtVooLYw3dj38W+5NaitgT GrGjUZIn0O8k4T6b8bb9tFq8x5Uzywqma0RLKsQWGXOBpXS0Df7OFEZY8pBkannsGS4E YjFqcZxEHupFp8QU49hMyoqUsG4PdFaWeH119ZXXDKJNxN8zKvZIGFp/LjbjyJTkyov3 ttwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=W8yOpiZwCndH9J2+eiWVHGGRzURU1RZsoDJmFw1i85g=; fh=8G0fvw9kezX2+yjwifXgHvTII1omy92vRpR1R+rFCOA=; b=K4bABV1Nawmk7ih3FoGGIrmtFsq/iuR1LkYBdP4hY0ZM4MGbkWnvI4Ez/hFUl1VTso cwhNDlprUY/L/5D7H1wPLXmIOia52eABFOGRnduL9kcO5jyBFOjwxot53Yu3fPsw5rmj Uc1KrAqO7F7ioiXgIUFdjP9vG1NiqeZekKGaAT6aokVAh6PORrI3ytWG8nDKYBHrUjz/ ASv26j6VRue2OVP7u4IRDYC597LbiuZwELAojssGen6c8iv51NHgBl7N0WWctzMSbT27 hZOmkfEUrgVOAoUFoQ54ONDYDDqdbPI7odW5m6+ofVsabNkXtNfn+HPb8NOU2YCSgD0e d8LA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=eaICYlxU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r13-20020a0562140c8d00b0068fb2374efbsi2740579qvr.127.2024.02.29.19.48.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 19:48:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=eaICYlxU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18D1E3858409 for <ouuuleilei@gmail.com>; Fri, 1 Mar 2024 03:48:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by sourceware.org (Postfix) with ESMTPS id DFD223858D34 for <gcc-patches@gcc.gnu.org>; Fri, 1 Mar 2024 03:47:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFD223858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=golang.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DFD223858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709264843; cv=none; b=Hi3BZiZ9WZuC6r1FtY0CKsFCT4HXIU45MbYSK7BHNBQWleyLPdAxDCPhETooVlk2vUiKIE/WNnwzcag4SsEymcMDsjEgQ3f9x/AVHVIe+KEtIKfW7/v8WpB1cZBpRlXaITLcW0++7nPTgfDjMn2cTXLq3kgeOeQTx4dfqLsVMdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709264843; c=relaxed/simple; bh=914ppJWHI/1aKIG6gm5RB95RGELRus5gFrvxjhyrviQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ujU5FPvK/4rT1bFyVsE9ICF9KLVuDVrWasA50ZDaJLB/Yx0HgP/rmYKKdMGRfXfEBt++8BM4mt9l9UskAqEXAvhNxYDVVPvtplo7MgysYhecftR7OEmlVXm43ISnYzhkKFsvB+bpo4oFOcXfndBDQWFKbwob+roXr13kcGIM4H0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-6095dfcb461so16180947b3.2 for <gcc-patches@gcc.gnu.org>; Thu, 29 Feb 2024 19:47:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20230601.gappssmtp.com; s=20230601; t=1709264841; x=1709869641; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=W8yOpiZwCndH9J2+eiWVHGGRzURU1RZsoDJmFw1i85g=; b=eaICYlxU0xk5R05CjH3IG2edWblKU7hvIC9noayoAVWjh5OAKVZOSeE9BMtcF1XHye HelT5z9jplzMtxK+Zv3zDRhN4yPUMjx+hKWNYTRl1zdfw9IfYMXcBIVcbsGzLwCrbgRD M1cX8lnw0AfhZWSPsS3KmUpqhUv0zVUXS8GTLy0sPUmVAo16N4/Q8T01d4oC0E0UiDbW BsFlF8JpswoD0cQRSu+VT0oDrU8yiZP5nUlmWrjrkV7JU/dEqZMuqEL3UAIJY/z2VddJ A2m8vC+5Av3OjNdgFoETevoWtBlSCiiRCx6vJPs7x8ba33U4wZFcKz1WnXcVyuKovNmw pexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709264841; x=1709869641; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=W8yOpiZwCndH9J2+eiWVHGGRzURU1RZsoDJmFw1i85g=; b=ZpdVpXUfEiPQQXPMgexxieevtG31czWjvkQT2Sh6xXZMCiJ5DXGoxlbC0BZzOj02yk actnEUGyTQHjYEb6j66ODt/SDet8phGr0swVfQ6iRifK6zhwSaOwYzbf9VNkyPMaqwim 7fbU/9FoY5HZYhjOEtXvSFeTonOpN0U3UjfXgkUtdqZQ6KecM0ySzVvRt7RHJ184N2w7 jvbtnco7yYhMSH/20g2H583kDXkzbo1VPbVeYoQxPAj/83Gn2ZCTgbfhya/8mA9p/OjV FZ1Nj8XRQWD2f6gyaCuLZeGQrN1B4qJ61CbV1zYIA24P4D8VvbzHWvfBwVOcOG9Jm6tj GHpg== X-Gm-Message-State: AOJu0YwttCSI0yTFWqnJWQ+AowTYgcHJFqcGxobInse/SG8bvkxQbNtz R2WEF653sUcs4ao0snQBDTuwN2RfTvalrQQGYYL2AX40T0oFJovjKGpu24vAh2/ehVgGJs9uXTI Gky3APB90aWK/MtPc66nJKAFJERD5B2mh0HFLRW4Pm/MIk9TwaOM= X-Received: by 2002:a25:ab47:0:b0:dc6:c2b2:c039 with SMTP id u65-20020a25ab47000000b00dc6c2b2c039mr353996ybi.41.1709264840797; Thu, 29 Feb 2024 19:47:20 -0800 (PST) MIME-Version: 1.0 From: Ian Lance Taylor <iant@golang.org> Date: Thu, 29 Feb 2024 19:47:09 -0800 Message-ID: <CAOyqgcWNyv_NAk+y_5SKd7SV2aVUg4898H94QigpEc5M83ecKQ@mail.gmail.com> Subject: libbacktrace patch committed: Read symbol table of debuginfo file To: gcc-patches <gcc-patches@gcc.gnu.org> Content-Type: multipart/mixed; boundary="000000000000a9d7a60612913bd5" X-Spam-Status: No, score=-12.0 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792294137576374248 X-GMAIL-MSGID: 1792294137576374248 |
Series |
libbacktrace patch committed: Read symbol table of debuginfo file
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Ian Lance Taylor
March 1, 2024, 3:47 a.m. UTC
This patch to libbacktrace reads symbol tables from debuginfo files. These become another symbol table to search. This is needed if people use --strip-all rather than --strip-debug when adding a debuglink section. This fixes https://github.com/ianlancetaylor/libbacktrace/issues/113. Bootstrapped and ran libbacktrace and libgo tests on x86_64-pc-linux-gnu. Committed to mainline. Ian * elf.c (elf_add): Add the symbol table from a debuginfo file. * Makefile.am (MAKETESTS): Add buildidfull and gnudebuglinkfull variants of buildid and gnudebuglink tests. (%_gnudebuglinkfull, %_buildidfull): New patterns. * Makefile.in: Regenerate. 24810fbf7b0ce274dfa46cc362305ac77ee5a72c
Comments
On Thu, Feb 29, 2024 at 7:47 PM Ian Lance Taylor <iant@golang.org> wrote: > > This patch to libbacktrace reads symbol tables from debuginfo files. > These become another symbol table to search. This is needed if people > use --strip-all rather than --strip-debug when adding a debuglink > section. This fixes > https://github.com/ianlancetaylor/libbacktrace/issues/113. > Bootstrapped and ran libbacktrace and libgo tests on > x86_64-pc-linux-gnu. Committed to mainline. This introduced a bug on the PPC v1 ABI, where libbacktrace uses the .opd section to convert from a function descriptor address to a code address. The .opd section is missing from a debuginfo file. This patch changes the code to use the original .opd section if it is missing. Checked on powerpc64-linux-gnu and x86_64-pc-linux-gnu. Committed to mainline. Ian PR libbacktrace/114201 * elf.c (elf_add): Add caller_opd parameter. Change all callers. Release opd data after all recursive calls. f692b338cd27a4e0d38fcb5af3d416cd66fbf814 diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 664937e1438..f4527e2477d 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -6501,8 +6501,9 @@ backtrace_uncompress_lzma (struct backtrace_state *state, static int elf_add (struct backtrace_state *state, const char *filename, int descriptor, const unsigned char *memory, size_t memory_size, - uintptr_t base_address, backtrace_error_callback error_callback, - void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf, + uintptr_t base_address, struct elf_ppc64_opd_data *caller_opd, + backtrace_error_callback error_callback, void *data, + fileline *fileline_fn, int *found_sym, int *found_dwarf, struct dwarf_data **fileline_entry, int exe, int debuginfo, const char *with_buildid_data, uint32_t with_buildid_size) { @@ -6557,6 +6558,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, struct elf_view split_debug_view[DEBUG_MAX]; unsigned char split_debug_view_valid[DEBUG_MAX]; struct elf_ppc64_opd_data opd_data, *opd; + int opd_view_valid; struct dwarf_sections dwarf_sections; if (!debuginfo) @@ -6584,6 +6586,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, debug_view_valid = 0; memset (&split_debug_view_valid[0], 0, sizeof split_debug_view_valid); opd = NULL; + opd_view_valid = 0; if (!elf_get_view (state, descriptor, memory, memory_size, 0, sizeof ehdr, error_callback, data, &ehdr_view)) @@ -6867,9 +6870,15 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, opd->addr = shdr->sh_addr; opd->data = (const char *) opd_data.view.view.data; opd->size = shdr->sh_size; + opd_view_valid = 1; } } + // A debuginfo file may not have a useful .opd section, but we can use the + // one from the original executable. + if (opd == NULL) + opd = caller_opd; + if (symtab_shndx == 0) symtab_shndx = dynsym_shndx; if (symtab_shndx != 0) @@ -6948,9 +6957,9 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, elf_release_view (state, &debuglink_view, error_callback, data); if (debugaltlink_view_valid) elf_release_view (state, &debugaltlink_view, error_callback, data); - ret = elf_add (state, "", d, NULL, 0, base_address, error_callback, - data, fileline_fn, found_sym, found_dwarf, NULL, 0, - 1, NULL, 0); + ret = elf_add (state, "", d, NULL, 0, base_address, opd, + error_callback, data, fileline_fn, found_sym, + found_dwarf, NULL, 0, 1, NULL, 0); if (ret < 0) backtrace_close (d, error_callback, data); else if (descriptor >= 0) @@ -6965,12 +6974,6 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, buildid_view_valid = 0; } - if (opd) - { - elf_release_view (state, &opd->view, error_callback, data); - opd = NULL; - } - if (debuglink_name != NULL) { int d; @@ -6985,9 +6988,9 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, elf_release_view (state, &debuglink_view, error_callback, data); if (debugaltlink_view_valid) elf_release_view (state, &debugaltlink_view, error_callback, data); - ret = elf_add (state, "", d, NULL, 0, base_address, error_callback, - data, fileline_fn, found_sym, found_dwarf, NULL, 0, - 1, NULL, 0); + ret = elf_add (state, "", d, NULL, 0, base_address, opd, + error_callback, data, fileline_fn, found_sym, + found_dwarf, NULL, 0, 1, NULL, 0); if (ret < 0) backtrace_close (d, error_callback, data); else if (descriptor >= 0) @@ -7013,7 +7016,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, { int ret; - ret = elf_add (state, filename, d, NULL, 0, base_address, + ret = elf_add (state, filename, d, NULL, 0, base_address, opd, error_callback, data, fileline_fn, found_sym, found_dwarf, &fileline_altlink, 0, 1, debugaltlink_buildid_data, debugaltlink_buildid_size); @@ -7050,7 +7053,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, if (ret) { ret = elf_add (state, filename, -1, gnu_debugdata_uncompressed, - gnu_debugdata_uncompressed_size, base_address, + gnu_debugdata_uncompressed_size, base_address, opd, error_callback, data, fileline_fn, found_sym, found_dwarf, NULL, 0, 0, NULL, 0); if (ret >= 0 && descriptor >= 0) @@ -7059,6 +7062,13 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, } } + if (opd_view_valid) + { + elf_release_view (state, &opd->view, error_callback, data); + opd_view_valid = 0; + opd = NULL; + } + /* Read all the debug sections in a single view, since they are probably adjacent in the file. If any of sections are uncompressed, we never release this view. */ @@ -7305,7 +7315,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, if (split_debug_view_valid[i]) elf_release_view (state, &split_debug_view[i], error_callback, data); } - if (opd) + if (opd_view_valid) elf_release_view (state, &opd->view, error_callback, data); if (descriptor >= 0) backtrace_close (descriptor, error_callback, data); @@ -7369,7 +7379,7 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, return 0; } - if (elf_add (pd->state, filename, descriptor, NULL, 0, info->dlpi_addr, + if (elf_add (pd->state, filename, descriptor, NULL, 0, info->dlpi_addr, NULL, pd->error_callback, pd->data, &elf_fileline_fn, pd->found_sym, &found_dwarf, NULL, 0, 0, NULL, 0)) { @@ -7398,9 +7408,9 @@ backtrace_initialize (struct backtrace_state *state, const char *filename, fileline elf_fileline_fn = elf_nodebug; struct phdr_data pd; - ret = elf_add (state, filename, descriptor, NULL, 0, 0, error_callback, data, - &elf_fileline_fn, &found_sym, &found_dwarf, NULL, 1, 0, NULL, - 0); + ret = elf_add (state, filename, descriptor, NULL, 0, 0, NULL, error_callback, + data, &elf_fileline_fn, &found_sym, &found_dwarf, NULL, 1, 0, + NULL, 0); if (!ret) return 0;
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am index 16a72d2abf7..750ed80ed05 100644 --- a/libbacktrace/Makefile.am +++ b/libbacktrace/Makefile.am @@ -257,7 +257,7 @@ b2test_LDFLAGS = -Wl,--build-id b2test_LDADD = libbacktrace_elf_for_test.la check_PROGRAMS += b2test -MAKETESTS += b2test_buildid +MAKETESTS += b2test_buildid b2test_buildidfull if HAVE_DWZ @@ -267,7 +267,7 @@ b3test_LDFLAGS = -Wl,--build-id b3test_LDADD = libbacktrace_elf_for_test.la check_PROGRAMS += b3test -MAKETESTS += b3test_dwz_buildid +MAKETESTS += b3test_dwz_buildid b3test_dwz_buildidfull endif HAVE_DWZ @@ -443,12 +443,16 @@ endif HAVE_PTHREAD if HAVE_OBJCOPY_DEBUGLINK -MAKETESTS += btest_gnudebuglink +MAKETESTS += btest_gnudebuglink btest_gnudebuglinkfull %_gnudebuglink: % $(OBJCOPY) --only-keep-debug $< $@.debug $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@ +%_gnudebuglinkfull: % + $(OBJCOPY) --only-keep-debug $< $@.debug + $(OBJCOPY) --strip-all --add-gnu-debuglink=$@.debug $< $@ + endif HAVE_OBJCOPY_DEBUGLINK %_buildid: % @@ -457,6 +461,12 @@ endif HAVE_OBJCOPY_DEBUGLINK $< $(OBJCOPY) --strip-debug $< $@ +%_buildidfull: % + ./install-debuginfo-for-buildid.sh \ + "$(TEST_BUILD_ID_DIR)" \ + $< + $(OBJCOPY) --strip-all $< $@ + if HAVE_COMPRESSED_DEBUG ctestg_SOURCES = btest.c testlib.c diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index c506cc29fe1..664937e1438 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -6872,7 +6872,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, if (symtab_shndx == 0) symtab_shndx = dynsym_shndx; - if (symtab_shndx != 0 && !debuginfo) + if (symtab_shndx != 0) { const b_elf_shdr *symtab_shdr; unsigned int strtab_shndx;