From patchwork Wed Sep 28 11:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 58106 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D2623857C4A for ; Wed, 28 Sep 2022 11:53:13 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by sourceware.org (Postfix) with ESMTPS id 8D47A3858C83 for ; Wed, 28 Sep 2022 11:52:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D47A3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f50.google.com with SMTP id n10so19351773wrw.12 for ; Wed, 28 Sep 2022 04:52:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date; bh=9S4k/C807XrYYS/Hly7UEzm6ICQjQSpjG4VpaJv+BQw=; b=DkEx83x5mN6ZqLD1E3BZGpSfAiVejpCugJQCzIBiN3xp7Rlkd60rV0UHvYwn7Hg7d8 Rmh7hRdz8+wUQic7aqZpMvzwoYodTpxpIShvZP7aQzTipsNAFRAGrZOBDtiwrzQs9BSZ ZxyjNcY7wP6L74HHxExI/WfjZjaHau3WL//lSg8Nw/kZ0auEV+B/e2aGQlRHCMwxUPD6 hxbnBd/c+ZV5I36DLHnZ5QadT8CGciHPkBuPDG0IV0d3vpDiRbO3x74HND0C6fHewU1/ ISpei+emwyWQ0f/hI4RERmsvx1th0aYhKgchhApbpFIcmb3Oohl1L9CpQnuKWLumYugR YA/Q== X-Gm-Message-State: ACrzQf212XTHdcGM4fACgEbswmA1jvOQqOjM0a5CUpvZhm62xFBjGyMT jDj0G+N2qLyZpPVTsT0baf3xjkvK2mI= X-Google-Smtp-Source: AMsMyM7TC6GrE5fMC5y2GhhfQg/4a6eDCcwpSULQjcpHFOgW8GNKy4DlLv2TVWYHdg1MNq2mM4z1Pw== X-Received: by 2002:a5d:6da1:0:b0:22b:774:52c3 with SMTP id u1-20020a5d6da1000000b0022b077452c3mr20909745wrs.172.1664365976730; Wed, 28 Sep 2022 04:52:56 -0700 (PDT) Received: from ?IPv6:2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653? ([2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653]) by smtp.gmail.com with ESMTPSA id m67-20020a1c2646000000b003a342933727sm1553330wmm.3.2022.09.28.04.52.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 04:52:55 -0700 (PDT) Subject: [PATCH] Fix GDB build: ELF support check & -lzstd (was: Re: [PATCH v3] binutils, gdb: support zstd compressed debug sections) To: Fangrui Song , Tom Tromey References: <20220923040837.550160-1-maskray@google.com> <87o7v0zo4b.fsf@tromey.com> From: Pedro Alves Message-ID: Date: Wed, 28 Sep 2022 12:52:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fangrui Song via Gdb-patches Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" [-binutils] On 2022-09-27 7:53 p.m., Fangrui Song via Binutils wrote: > On Tue, Sep 27, 2022 at 11:08 AM Tom Tromey wrote: >> >>>>>>> Fangrui Song via Gdb-patches writes: >> >>> PR29397 PR29563: The new configure option --with-zstd defaults to auto. >>> If pkgconfig/libzstd.pc is found, define HAVE_ZSTD and support zstd >>> compressed debug sections for most tools. >> >>> * bfd: for addr2line, objdump --dwarf, gdb, etc >>> * gas: support --compress-debug-sections=zstd >>> * ld: support ELFCOMPRESS_ZSTD input and --compress-debug-sections=zstd >>> * objcopy: support ELFCOMPRESS_ZSTD input for >>> --decompress-debug-sections and --compress-debug-sections=zstd >>> * gdb: support ELFCOMPRESS_ZSTD input. The bfd change references zstd >>> symbols, so gdb has to link against -lzstd in this patch. >> >> This also needs some change to the sims. >> I see failures like this with git master: >> >> make[4]: Entering directory '/home/tromey/gdb/build/sim/bpf' >> CCLD run >> ../../bfd/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'ZSTD_decompress' >> ../../bfd/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'ZSTD_isError' >> (unknown):176: error: undefined reference to 'ZSTD_compress' >> (unknown):179: error: undefined reference to 'ZSTD_isError' >> collect2: error: ld returned 1 exit status >> >> You'll see them all if you do a build with all sims enabled. >> >> thanks, >> Tom > > Thanks for the report and Tom's IRC chat with me about the > `../../configure --enable-targets --enable-sim; make all-gdb` build. > Tom confirmed that the latest commit `sim: Link ZSTD_LIBS` has fixed > the problem. > Hi! I'm running into a similar gdb build/link failure with current master. See patch below. -- >8 -- From a461b259690b62906978450533688b71ec939310 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 28 Sep 2022 11:33:30 +0100 Subject: [PATCH] Fix GDB build: ELF support check & -lzstd GDB fails to build for me, on Ubuntu 20.04. I get: ... CXXLD gdb /usr/bin/ld: linux-tdep.o: in function `linux_corefile_thread(thread_info*, linux_corefile_thread_data*)': /home/pedro/gdb/binutils-gdb/src/gdb/linux-tdep.c:1831: undefined reference to `gcore_elf_build_thread_register_notes(gdbarch*, thread_info*, gdb_signal, bfd*, std::unique_ptr >*, int*)' /usr/bin/ld: linux-tdep.o: in function `linux_make_corefile_notes(gdbarch*, bfd*, int*)': /home/pedro/gdb/binutils-gdb/src/gdb/linux-tdep.c:2117: undefined reference to `gcore_elf_make_tdesc_note(bfd*, std::unique_ptr >*, int*)' collect2: error: ld returned 1 exit status make[2]: *** [Makefile:2149: gdb] Error 1 make[2]: Leaving directory '/home/pedro/gdb/binutils-gdb/build/gdb' make[1]: *** [Makefile:11847: all-gdb] Error 2 make[1]: Leaving directory '/home/pedro/gdb/binutils-gdb/build' make: *** [Makefile:1004: all] Error 2 Those undefined functions exist in gdb/gcore-elf.c, which is only included in the build if GDB's configure thinks that the target you're configuring for is an ELF target. GDB's configure thinks my system isn't ELF, which is incorrect. For the ELF support check, gdb/config.log shows: configure:17387: checking for ELF support in BFD configure:17407: gcc -o conftest -I/home/pedro/gdb/binutils-gdb/src/gdb/../include -I../bfd -I/home/pedro/gdb/binutils-gdb/src/gdb/../bfd -g3 -O0 -L../bfd -L../libiberty -lzstd conftest.c -lbfd -liberty -lz -lncursesw -lm -ldl >&5 /usr/bin/ld: ../bfd/libbfd.a(compress.o): in function `decompress_contents': /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:42: undefined reference to `ZSTD_decompress' /usr/bin/ld: /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:44: undefined reference to `ZSTD_isError' /usr/bin/ld: ../bfd/libbfd.a(compress.o): in function `bfd_compress_section_contents': /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:195: undefined reference to `ZSTD_compress' /usr/bin/ld: /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:198: undefined reference to `ZSTD_isError' collect2: error: ld returned 1 exit status configure:17407: $? = 1 ... configure:17417: result: no Note how above, in the gcc command line, "-lzstd" appears before "-lbfd". That explain the link failure. It should appear after, like -lz does. This commit fixes it, by moving ZSTD_LIBS from LDFLAGS to LIBS, next to -lz, in GDB_AC_CHECK_BFD, and regenerating gdb/configure. Change-Id: I1f4128dde634e8ea04c9002904f1005a8b3a6863 --- gdb/acinclude.m4 | 4 ++-- gdb/configure | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) base-commit: 67d1991b785bdfef1d70cddfa0202b99b43ccce9 diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4 index 28846119dcb..62fa66c7af3 100644 --- a/gdb/acinclude.m4 +++ b/gdb/acinclude.m4 @@ -234,9 +234,9 @@ AC_DEFUN([GDB_AC_CHECK_BFD], [ # always want our bfd. CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS" ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'` - LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $ZSTD_LIBS $LDFLAGS" + LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS" intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'` - LIBS="-lbfd -liberty -lz $intl $LIBS" + LIBS="-lbfd -liberty -lz $ZSTD_LIBS $intl $LIBS" AC_CACHE_CHECK( [$1], [$2], diff --git a/gdb/configure b/gdb/configure index 238b66f3c60..33677262783 100755 --- a/gdb/configure +++ b/gdb/configure @@ -17412,9 +17412,9 @@ WIN32LIBS="$WIN32LIBS $WIN32APILIBS" # always want our bfd. CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS" ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'` - LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $ZSTD_LIBS $LDFLAGS" + LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS" intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'` - LIBS="-lbfd -liberty -lz $intl $LIBS" + LIBS="-lbfd -liberty -lz $ZSTD_LIBS $intl $LIBS" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ELF support in BFD" >&5 $as_echo_n "checking for ELF support in BFD... " >&6; } if ${gdb_cv_var_elf+:} false; then : @@ -17527,9 +17527,9 @@ fi # always want our bfd. CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS" ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'` - LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $ZSTD_LIBS $LDFLAGS" + LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS" intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'` - LIBS="-lbfd -liberty -lz $intl $LIBS" + LIBS="-lbfd -liberty -lz $ZSTD_LIBS $intl $LIBS" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Mach-O support in BFD" >&5 $as_echo_n "checking for Mach-O support in BFD... " >&6; } if ${gdb_cv_var_macho+:} false; then :