From patchwork Tue Jun 8 15:18:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1489477 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=K59yvOjk; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fzv6F3ZRkz9sSn for ; Wed, 9 Jun 2021 01:19:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 454AE83AA2; Tue, 8 Jun 2021 15:19:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YuTf9hQgOInJ; Tue, 8 Jun 2021 15:19:14 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id 90B6683134; Tue, 8 Jun 2021 15:19:13 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 5DDF31BF867 for ; Tue, 8 Jun 2021 15:18:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 56F5540117 for ; Tue, 8 Jun 2021 15:18:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n93_ezv36Nsg for ; Tue, 8 Jun 2021 15:18:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by smtp2.osuosl.org (Postfix) with ESMTPS id 3225C402B5 for ; Tue, 8 Jun 2021 15:18:49 +0000 (UTC) Received: by mail-ed1-x531.google.com with SMTP id w21so24874891edv.3 for ; Tue, 08 Jun 2021 08:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2d/Fe+KLYF7s0h3d3ZrNZJ90zKFpbIYxbf8wqdG1Ca8=; b=K59yvOjkENzAz+2ubTjkfVsUfUrZqn6dXHetsRY3X0D+TDgMP9q+2s3BOP8nIiBhXP vkovJsI3zjEDABzk6QBV4lUmvj7yBYAnyDaq1s8BypoI77lihmlR1dormqJ28QCAYNL+ ZhNKn64mAPL9ih66NLSPaMlDDKFeNsL+G3p90mD072h6f6tcTa7BrXlvMM8jvLFSPm54 jYZktRnEHIhBa5kZq+OX4tdBcvi7Hwst2b5YokLwXUaKrELEO+WH99uNmyY1CEk6fRwB e2mLnyUQKRCDiNtBKiMxRcx6afVcM7W3vcdNNejry5G0pONAPBpzfShzovzK0Z3MrPdZ 17fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2d/Fe+KLYF7s0h3d3ZrNZJ90zKFpbIYxbf8wqdG1Ca8=; b=jwo7irRnGiAdL1jXM/pRqRdB/PPioZa1//kROEy0jz7WfjYtw18mmDVr+knBjEqe5U yL44yKpLmlQPKUn18mplR/GS1JdBdVNXFTyTelM7QFx+ogS/lsmNPnSz7LMQsRQKNeXF OKKPUTUltPRCvGt4cbXwkSPmaBSWMM9fT1YRa2MbMKySTFoLy08zTNjUaGY7rG85pnSX MY9Ps3o5ME13TzkMx+bepxNsmb0ElWeOpdL/JINvkMMK5t9zOFDiL43hRc2OhZAkKeAh VJJthiqTKjb37GhC8OyQ5BJiQU8wumQWin40ckUboEo5LeohkFdmB6OW3afDVo0u2+uf VOgw== X-Gm-Message-State: AOAM5305oDQx7YFZ0z55UJFB5rfpSapSybq/na0IFyHINLzKfGoqf76x BwF04b72vkcnVFgaOGGEbtUnIioE6u8ORngR X-Google-Smtp-Source: ABdhPJySxC4Pln14x67G+znKUUPM0N77UBEFCRaBHMq468CjH5uRKo53Xuq3fQq5OXHI2LJ8RiK7zQ== X-Received: by 2002:aa7:ca1a:: with SMTP id y26mr25831605eds.314.1623165527317; Tue, 08 Jun 2021 08:18:47 -0700 (PDT) Received: from localhost (ptr-5gw9tx0z7f066xyxzn.18120a2.ip6.access.telenet.be. [2a02:1810:510:3800:124:6af2:167b:d993]) by smtp.gmail.com with ESMTPSA id w17sm19538edd.44.2021.06.08.08.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 08:18:46 -0700 (PDT) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 8 Jun 2021 17:18:38 +0200 Message-Id: <20210608151840.20917-3-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210608151840.20917-1-patrickdepinguin@gmail.com> References: <20210608151840.20917-1-patrickdepinguin@gmail.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCHv2 2/3] toolchain/toolchain-external: fixup gdb pretty-printer loader for libstdcxx X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Thomas Petazzoni , Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Thomas De Schampheleire gcc installs a libstdcxx-...so-gdb.py file that gdb will load automatically when it loads libstdcxx.so, via the mechanism described at [1]. However, the auto-load file installed by gcc contains hardcoded paths referring to the location where the (external) toolchain was built, which are normally not available. Fix up the paths in the load file so that the pretty printers can be loaded automatically. Note that gdb will only auto-load the file if its location is marked as 'safe'. A subsequent commit will take care of that. Technically, there could be more than one load file, e.g. in lib and usr/lib, so fix them all. This was for example observed in BR2_TOOLCHAIN_EXTERNAL_ARM_AARCH64. In a very specific case with a local custom toolchain, there were actually two 'python' directories, which would break the sed command, so arbitrarily limit to the first one encountered. [1] https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html Signed-off-by: Thomas De Schampheleire --- .../pkg-toolchain-external.mk | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk index 6d91cb5d1e..d7fb93ee20 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -485,6 +485,26 @@ define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT fi endef +# GCC installs a libstdcxx-...so-gdb.py file that gdb will load automatically, +# but it contains hardcoded paths referring to the location where the (external) +# toolchain was built. Fix up these paths so that the pretty printers can be +# loaded automatically. +# By default, the pretty printers are installed in +# $(datadir)/gcc-$(gcc_version)/python but this could have been overwritten with +# the gcc configure option: --with-python-dir. We thus have to search the +# correct path first. +define TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER + $(Q)loadfiles=$$(find $(STAGING_DIR) -name 'libstdc++.so*-gdb.py' 2>/dev/null); \ + pythondir=$$(find $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR) -path '*/libstdcxx/__init__.py' 2>/dev/null | xargs dirname | xargs dirname | head -n1); \ + if [ -n "$$loadfiles" ] && [ -n "$$pythondir" ]; then \ + echo "Fixing up hardcoded paths in GDB pretty-printer auto-load file(s) for libstdcxx: $$loadfiles"; \ + sed -ri \ + -e 's%^libdir\s*=.*%libdir = "$(STAGING_DIR)/lib"%' \ + -e "s%^pythondir\s*=.*%pythondir = '$$pythondir'%" \ + $$loadfiles; \ + fi +endef + # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not # patched specifically for uClibc-ng, so it continues to generate # binaries that expect the dynamic loader to be named ld-uClibc.so.0, @@ -589,6 +609,7 @@ define $(2)_INSTALL_STAGING_CMDS $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS) $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER) $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT) + $$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER) endef # Even though we're installing things in both the staging, the host