From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id E42C8386F465 for ; Sat, 6 Mar 2021 00:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E42C8386F465 Received: by mail-pg1-x52c.google.com with SMTP id x29so2429948pgk.6 for ; Fri, 05 Mar 2021 16:11:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mD+Kkx1uiKLcwS7rO/v4hGE53ABq8JdITMHIst7QgCw=; b=d2gH7b2TWGLeEbef/txVSud8JPa5c1mPvQwH1YEvOC98OrYBLvnWtcbs5pcvL7cXLo Oma8uZIThQeDO7N9wfV9+BDh6O132EVNRJ3cEo4M2Eeafa5s0regMBGXfA29X2RIYfa/ 4jqjBsxCiQsW50z6uUYFnpRwj0BE5z9gL2aUGKtsBEkAyX55f4D5SW2ATvgehuZeHdw2 fzzdiqMwQ/la0ApNMx0c2EXOa2HOpx9dpR/2ibRKEu2UdRnwS58v+A6Sd3c5pzAHjyxz YQGCDIB0bqT+hQ7pQvbKcYy3aacNzM0HJtk9pynEbeJnTcDLM/Rc5heo5aAftkKMAQnp yN3Q== X-Gm-Message-State: AOAM532K6WahHN+l059mXmpBvwXboJr9Qg9rNwOP1DyaeIAxHbecnTlq /rkNe9+2kIU9zNPjNOvUeEmLPfDj4uSNYA== X-Google-Smtp-Source: ABdhPJy4XgKsIozvoSPOWJxTPzDtCB7qevDKQkFFPMQuC7j13aJS2w1m89nWl/eZtjJse2E6MAPfDQ== X-Received: by 2002:a63:2164:: with SMTP id s36mr11005808pgm.268.1614989518120; Fri, 05 Mar 2021 16:11:58 -0800 (PST) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id w18sm3091062pjh.19.2021.03.05.16.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 16:11:57 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id DB151417FB; Sat, 6 Mar 2021 10:41:53 +1030 (ACDT) Date: Sat, 6 Mar 2021 10:41:53 +1030 From: Alan Modra To: "H.J. Lu" Cc: Jan Beulich , Binutils Subject: Re: [PATCH v5] elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASE Message-ID: <20210306001153.GF6042@bubble.grove.modra.org> References: <20210225020926.GR6042@bubble.grove.modra.org> <20210301121926.GF6042@bubble.grove.modra.org> <20210304131448.GV6042@bubble.grove.modra.org> <20210305051714.GZ6042@bubble.grove.modra.org> <20210305135715.GC6042@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-3034.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Mar 2021 00:12:00 -0000 On Fri, Mar 05, 2021 at 10:26:35AM -0800, H.J. Lu wrote: > On Fri, Mar 5, 2021 at 5:57 AM Alan Modra wrote: > > This doesn't look like the right place to set up a reference to > > __executable_start. Doing so in a new check_relocs in pei-x86_64.c > > that tests for an ELF output would be better. I'm not suggesting that > > you run over relocs looking for R_AMD64_IMAGEBASE, that could be done > > but seems unnecessary. > > check_relocs is too late. We need to do it in load_symbols (). Otherwise, > __executable_start won't be defined. I added pex64_link_add_symbols to > do it. Ah, I was forgetting that check_relocs now runs much later. Even so, I would have thought that the PROVIDE would define the symbol? The question is academic, I'm happy with pex64_link_add_symbols. > Here is the v5 patch. OK for master? OK with three further changes. 1) The R_AMD64_IMAGEBASE handling should to be inside the output_bfd == NULL block. It is wrong to apply the image base adjustment to the section for relocatable linking. Doing so would effectively change the reloc addend. 2) I worry about the abort, which I think you might hit if trying to link PE objects into a pie. One possible fix would be to change the bfd_link_pde in pex64_link_add_symbols to !bfd_link_relocatable. That might just be sweeping a problem under the rug, so an alternative fix would be to remove the abort and instead return with bfd_reloc_dangerous. Either fix is fine with me. 3) No need to check for bfd_target_elf_flavour in set_output_arch. -- Alan Modra Australia Development Lab, IBM