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 1E6BBC43334 for ; Mon, 11 Jul 2022 20:36:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BE31584059; Mon, 11 Jul 2022 22:36:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="devE5NhF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB60F8402A; Mon, 11 Jul 2022 22:36:00 +0200 (CEST) Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (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 CFA258405F for ; Mon, 11 Jul 2022 22:35:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.bossman075@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id d18so6816927qtw.8 for ; Mon, 11 Jul 2022 13:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:in-reply-to :content-transfer-encoding; bh=/idrtpIroVsNS9lY00/X1VoU3hVUfh5gOVj9IV97Gr8=; b=devE5NhFcq4DWSuTCI9Caa9Gt6+QxyJUPWhsmodqorn4whao2lhc41xMc77bkXDrEs FyLfKeDmjyBg3/tz7H8CocOeZZxuX1UGV6PZt+aIKF3xussdPSZeKRbHYM5fHSQdHjVP sg21QghKYlQWDlSQJ7FSFOWbADnnz+c1m/Iyy0C0l9MX+It6nd9oVhu0rRa1FqaHQFwB SavMJCWit2TEVsvClH2kOggzK0h03CS9ljQz6/EXySU7U6n1AF1MPm/Zw5KrAtA60nNM 5cQeElKOTOdTpIr2YrB8GdZbQKdwK577U9x3OpImjbJUsnWA3yuP6oJ640Y8WeZx2ItG wK3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:in-reply-to :content-transfer-encoding; bh=/idrtpIroVsNS9lY00/X1VoU3hVUfh5gOVj9IV97Gr8=; b=U+h1y8eNwvL3rEbd27OYKfmSinXwQgXnKyP6gZ7Q+amrIopayTPSUbbI0g0snVQHmE yYUBI2uIT9Q/nZT74yo4pD6G7LYBRdw+5I2okIVvK7p1EbF42knlCpkdu1FdB2qU1DIf 9/aV49LfYKladbY8qM9QlMM6rPvk1lz+Rhp1GS5gALH8V2aOz9J/8ZUTyJMXfGslK6Yl nFWcvbDUXLmkxFD8NKVK85137BQTVlNvtYsMyfON7NwbqpgPUKfzcm33KW5zq29BNsK3 0MsLQn45gfDLIhEp9kW3j0dsVF96uWS4GM5U5k692VYkahkycnwkRsBK/Qw+I/rfhSgs OJzQ== X-Gm-Message-State: AJIora+1QAtQR7fPxB0uKYYCBAlqyVA3Uef/WoV3Vi1oq4YS8URwuwkT QBOMhvd2C0rt46rae0qWj14= X-Google-Smtp-Source: AGRyM1t/NH2trL2/WSwOwQ1PkZhXnOHau62JaidKnuT8Tc108DugWRMNXsK3Igx4A5OZR4bTJNf6Fw== X-Received: by 2002:a05:622a:1893:b0:31e:b5f5:b446 with SMTP id v19-20020a05622a189300b0031eb5f5b446mr4690210qtc.296.1657571756553; Mon, 11 Jul 2022 13:35:56 -0700 (PDT) Received: from ?IPV6:2607:fb91:2d42:8476:e1c1:f539:5be4:e16e? ([2607:fb91:2d42:8476:e1c1:f539:5be4:e16e]) by smtp.gmail.com with ESMTPSA id bm12-20020a05620a198c00b006b2849cdd37sm7311225qkb.113.2022.07.11.13.35.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Jul 2022 13:35:56 -0700 (PDT) From: Jesse Taube X-Google-Original-From: Jesse Taube Message-ID: <1632a1c9-60a1-7744-af9f-9d260a563ab7@gmail.com> Date: Mon, 11 Jul 2022 16:35:46 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1] arm: relocate: Replace ADR instruction with non-pseudo-instruction Content-Language: en-US To: Andre Przywara Cc: u-boot@lists.denx.de, trini@konsulko.com, sbabic@denx.de, festevam@gmail.com, festevam@denx.de, giulio.benetti@benettiengineering.com, sjg@chromium.org References: <20220710070953.933688-1-Mr.Bossman075@gmail.com> <20220711135740.0eb67b22@donnerap.cambridge.arm.com> <20220711151113.78856e4b@donnerap.cambridge.arm.com> <20220711151953.64695228@donnerap.cambridge.arm.com> In-Reply-To: <20220711151953.64695228@donnerap.cambridge.arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 7/11/22 10:19, Andre Przywara wrote: > On Mon, 11 Jul 2022 15:11:13 +0100 > Andre Przywara wrote: > >> On Mon, 11 Jul 2022 13:57:40 +0100 >> Andre Przywara wrote: >> >> Hi, >> >>> On Sun, 10 Jul 2022 03:09:53 -0400 >>> Jesse Taube wrote: >>> >>> Hi Jesse, >>> >>>> In Binutils 2.37 the ADR instruction has changed >>>> use alternate instructions. >>> >>> Can you elaborate on this? What has changed exactly, and why? Looking at >>> the commit you mention below I don't see an immediate problem that would >>> require code changes? Also it speaks of forward references, but this one >>> is not one? >>> And I didn't spot any difference between 2.38 and 2.35, at least not in my >>> isolated test (but I didn't bother to compile a whole stage 1 GCC with >>> newer binutils yet). >> >> OK, so digging a bit deeper I think I have an idea: >> With as 2.35 I get: >> 080007cc : >> 80007cc: f2af 0304 subw r3, pc, #4 >> >> whereas with 2.38 it's: >> 080007cc : >> 80007cc: f2af 0303 subw r3, pc, #3 >> >> the latter looks correct since we compile relocate.S with -mthumb >> -mthumb-interwork, so the lowest bit of the *function* address should be >> set, to indicate this is a Thumb function. And "ENTRY(relocate_code)" >> clearly tells the assembler that relocate_code is a function entry point, >> so should carry the instruction set flag in bit 0. >> However we don't use the result of "adr" as an argument for a bx call >> later, but to calculate some relocation offset, so the bit is getting in >> the way. >> Without thinking too much about this, wouldn't it help to just always >> clear bit 0 in r3? >> Or probably better: to have an additional label, which is not marked as a >> function entry point? > > Does that fix it? > > diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S > index 14b7f61c1a..5102bfabde 100644 > --- a/arch/arm/lib/relocate.S > +++ b/arch/arm/lib/relocate.S > @@ -78,7 +78,8 @@ ENDPROC(relocate_vectors) > */ > > ENTRY(relocate_code) > - adr r3, relocate_code > +relocate_base: > + adr r3, relocate_base > ldr r1, _image_copy_start_ofs > add r1, r3 /* r1 <- Run &__image_copy_start */ > subs r4, r0, r1 /* r4 <- Run to copy offset */ > > Seems to generate the same code with both gas 2.35 and gas 2.38. Works thanks. Do you want to submit it or. Sorry about me not knowing Assembly for arm very well... Thanks, Jesse > Cheers, > Andre > >> >> Cheers, >> Andre >> >>>> The change causes armv7-m to not boot. >>> >>> What does "causes armv7-m to not boot" mean? It compiles fine, but hangs >>> or crashes? >>> Can you show the relevant disassembly from both binutils versions? >>> >>> And from trying to reproduce this minimally, do we need a ".syntax unified" >>> in the .S file? >>> >>>> Signed-off-by: Jesse Taube >>>> --- >>>> arch/arm/lib/relocate.S | 8 +++++++- >>>> 1 file changed, 7 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/arch/arm/lib/relocate.S b/arch/arm/lib/relocate.S >>>> index 14b7f61c1a..22c419534f 100644 >>>> --- a/arch/arm/lib/relocate.S >>>> +++ b/arch/arm/lib/relocate.S >>>> @@ -78,7 +78,13 @@ ENDPROC(relocate_vectors) >>>> */ >>>> >>>> ENTRY(relocate_code) >>>> - adr r3, relocate_code >>>> +/* >>>> + * Binutils doesn't comply with the arm docs for adr in thumb2 >>>> + * from commit d3e52e120b68bf19552743fbc078e0a759f48cb7 onward >>>> + * to remove ambiguity explicitly define the pseudo-instruction >>>> + */ >>>> + mov r3, pc >>>> + subs r3, #4 >>> >>> But this will break ARM, won't it? Because it would require to subtract #8? >>> I mean there is a reason for this adr instruction, because this offset >>> calculation is best left to the assembler. Not to speak of the fragility >>> of assuming that the relocate_code label is pointing to the very first >>> instruction. The ENTRY macro could also insert instructions. >>> >>> Cheers, >>> Andre >>> >>>> ldr r1, _image_copy_start_ofs >>>> add r1, r3 /* r1 <- Run &__image_copy_start */ >>>> subs r4, r0, r1 /* r4 <- Run to copy offset */ >>> >> >