Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89773C352A1 for ; Tue, 6 Dec 2022 21:44:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A9CA980708; Tue, 6 Dec 2022 22:44:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="YO/6t3Qk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3BC2384C4B; Tue, 6 Dec 2022 22:44:00 +0100 (CET) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2CAA680431 for ; Tue, 6 Dec 2022 22:43:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-wr1-x433.google.com with SMTP id f18so25434421wrj.5 for ; Tue, 06 Dec 2022 13:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ujXJtpuzwaWzNGj8BJ+2pqweh7lrzytzaTVf3XEbieI=; b=YO/6t3QkfxWS5MMY/ipbZ3c39Rapx1hI8/lSWnfjbhPuGggCNH8fcKrzPQE+Fy1sls pSuIoF6ccj+4FpdyLDCWw/HuP81PWCbx2Zq8BjxsyXXXqhUm6kRxTbkPakBCJYWNlde+ x5TYF8jMO3841gGes1Amh8VmZIH88VWuv3pOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ujXJtpuzwaWzNGj8BJ+2pqweh7lrzytzaTVf3XEbieI=; b=STqJ6bmWCG14xJQXr/XTqKHKbxtZPDax69nH/JmYnZHBPR3Q4U4d2yuZUN7bQSBH84 Z1a6Xqu7JvOC4fAuEtJVSMdraSVn2hByRASvWHavcBbOsi6K0voVK60r9zl387g2+0Ks WFYE/eEH+nFVG87LKMlEClb0SZjvkW2sBQ/3kmQboAYOQQnctLBp9wvI6b8o0WWjDNdq V8CZTo0cPZOAyz6UGUZko23473qpXMxtWnBEmBL3VWeWsYOracDtxQPmQGl/Ilt0/AL5 scEhxR+xZP1Ob8tnKjD/yomJOrKH/mhmb8vpYZQzlblt73Z/if/3hqIHxnL/Pc0S2jk0 1tqQ== X-Gm-Message-State: ANoB5pnXVpywe3aGnGevDx2laz9i3oYemJmpZZeeJPFbD0PkoX+c3wNf CrlhemXMTN3V4lO60xhg6O7ccO77ZGp/q3Xy X-Google-Smtp-Source: AA0mqf5iJjCKApWOXhcOSJBvbPNV419I9k3Bfgg8CEsODoRYU+lDLI5Ug8d0TqBwwMrYHdocLbONnw== X-Received: by 2002:a5d:452e:0:b0:242:9b0:5f3 with SMTP id j14-20020a5d452e000000b0024209b005f3mr30674575wra.590.1670363036657; Tue, 06 Dec 2022 13:43:56 -0800 (PST) Received: from bill-the-cat (2603-6081-7b00-6400-40ab-ff29-04a6-7f8f.res6.spectrum.com. [2603:6081:7b00:6400:40ab:ff29:4a6:7f8f]) by smtp.gmail.com with ESMTPSA id z2-20020a05600c220200b003cfd10a33afsm24886721wml.11.2022.12.06.13.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 13:43:56 -0800 (PST) Date: Tue, 6 Dec 2022 16:43:53 -0500 From: Tom Rini To: Pali =?iso-8859-1?Q?Roh=E1r?= Cc: u-boot@lists.denx.de Subject: Re: [PATCH 4/6] arm: Use the WEAK assembly entry point consistently Message-ID: <20221206214353.GO3787616@bill-the-cat> References: <20221122173158.2231821-1-trini@konsulko.com> <20221122173158.2231821-4-trini@konsulko.com> <20221123225059.4vjzixzmzjwvgfxi@pali> <20221123231517.GD3787616@bill-the-cat> <20221123234044.jtj4srfg7pk46wlk@pali> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="JEmpv92YMa79g021" Content-Disposition: inline In-Reply-To: <20221123234044.jtj4srfg7pk46wlk@pali> X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean --JEmpv92YMa79g021 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 24, 2022 at 12:40:44AM +0100, Pali Roh=E1r wrote: > On Wednesday 23 November 2022 18:15:17 Tom Rini wrote: > > On Wed, Nov 23, 2022 at 11:50:59PM +0100, Pali Roh=E1r wrote: > > > On Tuesday 22 November 2022 12:31:56 Tom Rini wrote: > > > > It is a bad idea, and more modern toolchains will fail, if you decl= are > > > > an assembly function to be global and then weak, instead of declari= ng it > > > > weak to start with. Update assorted assembly files to use the WEAK = macro > > > > directly. > > > >=20 > > > > Signed-off-by: Tom Rini > > >=20 > > > During debugging of Nokia N900 code I was looking at this and I > > > originally thought that this redefinition is the issue why N900 u-boot > > > did not work... (but as we now know, the n900 issue was somewhere els= e). > > >=20 > > > So I agree with this change, feel free to add my: > > >=20 > > > Reviewed-by: Pali Roh=E1r > > >=20 > > > ... but even after this change, linked u-boot.bin binary is > > > not-so-correct. It works but has an issue: In final u-boot.bin binary > > > there is both weak and non-weak version of every weak function. You c= an > > > verify it for example by looking at "save_boot_params" code (really > > > code, not just symbol) in u-boot ELF binary. > > >=20 > > > The reason for this is that linker (even LTO enabled) cannot eliminate > > > code for weak version of function because it does not know how to > > > "drop" it from binary/assembly code. So linker just set that non-weak > > > version of function is active and let non-weak version present in bin= ary > > > as probably dead code. > > >=20 > > > This is affected only by assembly files, not by C files, because gcc = is > > > called with -ffunction-sections -fdata-sections flags which cause that > > > every (weak) function is in its separate section (so C function > > > "int abc() { ... }" is put into the section ".text.abc" instead of > > > ".text") and linker's flag --gc-sections (or LTO optimization) then d= rop > > > all unreferenced sections. > > >=20 > > > I do not know how fix this issue in assembly files. But cannot be WEAK > > > macro modified to change section to ".text." to mimic C > > > compiler behavior? Would this cause any issues? > >=20 > > Yes, you're right about the cause, and potential solution. If you can > > come up with a way to get each assembly function put in to a separate > > .text.funcname section, that would be great and much appreciated. I > > think I tried this at one point a long long time ago and it did work, > > but I didn't have something clean, either. I think I was hoping that the > > linux kernel folks would solve it in time, but they decided the > > time/effort for --gc-sections wasn't worth it, in the end. >=20 > I quickly looked at this. If "as" is invoked with --sectname-subst flag > then it is possible to use '.section %S.' and '.previous' > directives. See documentation where is example of that: > https://sourceware.org/binutils/docs/as/Section.html#ELF-Version >=20 > I experimented with adding into include/linux/linkage.h: >=20 > #define WEAKSECT(name) \ > .section .text.name ASM_NL \ > WEAK(name) >=20 > #define ENDPROCSECT(name) \ > ENDPROC(name) ASM_NL \ > .previous >=20 > And then defining in arch/arm/cpu/armv7/start.S: >=20 > WEAKSECT(save_boot_params) > b save_boot_params_ret > ENDPROCSECT(save_boot_params) >=20 > (Note that n900 has custom non-weak save_boot_params) >=20 > Then I run: >=20 > make CROSS_COMPILE=3Darm-linux-gnueabi- nokia_rx51_defconfig u-boot.bin= KBUILD_LDFLAGS=3D"--print-gc-sections" >=20 > And it showed me: >=20 > ld: removing unused section '.text.save_boot_params' in file 'arch/arm/= cpu/armv7/start.o' >=20 > So seems that it is working. >=20 > For proper integration it would be needed to integrate --sectname-subst > flag support and then replace all usage by new macros. That's all good to know, thanks for digging more. It would be good to know if a quick and dirty experimental patch showed enough size savings to be worth a more full pursuit or if we really don't have many / any unused assembly functions or what we do have unused could be more easily handled with an ifdef or refactoring into multiple files. --=20 Tom --JEmpv92YMa79g021 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmOPt5gACgkQFHw5/5Y0 tyw9ogv/YyB9YW+u+PNyuk0RInhA5cxgj4gpqm8+pDn6rGIVuOHQQ048YM6nuK3c pxGjTChmFiQlDHdZ8R1qcF8fWNtnGXos2VrfxLpUZlfrthSvgYfiVucoMw7yX7rz LVCFB4sfLNEmfn0ygilNdoTIeTerzgBMr2uhx4KY7TAP+M/KId8zemzFL5C5d8SD LVaqXU5e3ZDvE1JsV7Q5OFWXHwv1MKu/hI3dv8d1/XiL2BX/aMKnKmirSynrypzJ YEfLbYteTCEiC/IGzcfYtcMw5TxtaNUmxId77gzE6t7Y9WcoJV66MSgaA4m4HUP2 a2MzXqIxIEsE0QRG+e/KoLtkWIwG2j7hC9nPKfzBpL08B7wNUtzUjtelC812K227 E7VUGRagslLmkb0mtxvIMDEOhHmDyZMqjXnZHRs/3bocFVzFj+SAccT2mfFbmzrS Hnh+yEcCk1RxA7gmvwJBpCm29x1sBY6mZC26HaMFBd7F8ocUM5OswNYieDT8wg32 bkAlTX24 =qpVP -----END PGP SIGNATURE----- --JEmpv92YMa79g021--