Message ID | bf7adb97-b1bc-4268-a8c7-246f2d4a01e6@suse.com |
---|---|
Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> 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 93D803856DD1 for <patchwork@sourceware.org>; Tue, 14 Jan 2025 13:20:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93D803856DD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=WYv9Sw0w X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id ACA523856DC1 for <binutils@sourceware.org>; Tue, 14 Jan 2025 13:18:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACA523856DC1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ACA523856DC1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736860685; cv=none; b=JmZRE7rlZ1aVt/ZnBnB5TWKgiKWhjpZxBzbtKjSXg/Wbr/PpLdjgVCtFeZXOmZEEHYm/CW4MnbVhpX+IWonVJN6FgI83qxwJIK/k67SOx0Kh2mXRuDaIENUzOGsY2zyOT7DDFGO+7kCUbgmJWZSbLTI9o6VxxHemMXLOQgyAHcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736860685; c=relaxed/simple; bh=ygfPkEvySo78+9s/TtDK8JVkSl4q28bO7j+dP00kBWE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=ZttmvuwIfll6Drmjt3ERhywlBAiZu+5Slpf2a+eT6rs5PmHCckPyfySaM839lNZ5w3Uf1TE6JCIcXMXWm9mRZXWZAnoIuX4g2NnL2AFjVPjQP75rSg6r7MDhACeZoLKikw9PgoeSbtcWdnA59+oAdiV95Yql1qfMCj0cHqN2J2Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACA523856DC1 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-385e06af753so2770215f8f.2 for <binutils@sourceware.org>; Tue, 14 Jan 2025 05:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1736860682; x=1737465482; darn=sourceware.org; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=cOtfhTv5XCKZ0DUbgcKv3gEgKIXrqh52i2XsDe0HjtA=; b=WYv9Sw0w0zUz+zYZIIkehtqh/SLpZ0we8GMwTwfsHVD7hQi33fo7fHsqrsmS2w2Ojd YGA0zvg7XnqyeCjLmkaMg9S9uzGLPFDWUn/A3GUeITPHIgmnlXLerfwZNHIr3XqiuWWy lqu/Rl6Gg/A4qxUMcu+jk+svPF3UKwHMlxwyF4Q2U2Yr8ONNw4y5JbzM4M65oSusVXWR 7g7o0/PnsE4sEzBCecadFnVFMvQxa+eW8iqSj5DQiJRwDAGGMTmLCahr0674Vh+Wf8NR vva9nQ2+013AJhokFqw13cEQcp20GY9XLecSxG7DQhBy/fuOkMykevDxEx21U3rcnex0 DgmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736860682; x=1737465482; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cOtfhTv5XCKZ0DUbgcKv3gEgKIXrqh52i2XsDe0HjtA=; b=u2kHxRSqMBUiR0s9ofZKSKfG4ZUdxwKqPkbYb4kimBIjT1C3hHO2PiVYLQphha2zT9 1xMDWoRA9kT/YlRGMQn9WgYs4cChguOraJkP2Y7IwjY/q3T9sSESNqu44t7KvdVVKyzm yWfUpuHnw8HnsLd7H4at4Zk/WavGPscfLAgtMaSnb5iPjoJKAdSrz9nXixTbfahQM63Y YOAQ59X98m8btE/NTWpd+Qi1CZmWoPrSKWda8ALTX0RScYuAcTTIFEyiWrZKhuGRN3p8 z/nGvwPDy54oMt0MtI1ckcpQ294hL6fgBD9JO2tR+e3I/xtrHtNO91uGqdGWkn+HyYo+ UfOw== X-Gm-Message-State: AOJu0Yy5xQN3f+oaMG3Avbe6EPIdiM5SU9COh/RjHuc0j9BDlYoScIaL cFvj4HXE5eN042uecxNI4GQZkP58rxxaJ/6VJKDBM63mpWKgGP3lVT38ny8/+vWQfKCu+2XBpu8 = X-Gm-Gg: ASbGnctoJFMLrhE3DjW6iWDrGVyXzUEnhZ0xgx6eja5yvOjhxOsPv1zJi6xmxgK7NEa cQpJ1iFsPji1FVJM9n7xp2IX6Hfi/OTxszLEwVSIUaSUdKBZJhs1EH8Ovdm6nfcNYgTrBgoH4ND FOc7i97L2BKhnZemMl34DdXjZAAOySFLpyzCzzU0FqcTL5azuXnmAOEfq/0fnZBPSTK4BY5YhIM M76Tbjpw9RQ6kZejpod0Xy225Z0t3RSLaeAlsYVekXjplb+li28km8R4uu+NbkC0koLrQOBK3X5 QZ9cuf5UINL7LVtIF8OcJxnw1DyK2UxpRDmv+ddA/w== X-Google-Smtp-Source: AGHT+IFlD4WC3+qhjgOKacpCkHjCnH7okQ6hfFg0gGcqnhdKt2lUmmZgOUNZFSblsVMklzXb9B82iA== X-Received: by 2002:a5d:5985:0:b0:386:3f3e:ab11 with SMTP id ffacd0b85a97d-38a87312e0dmr22761802f8f.34.1736860682554; Tue, 14 Jan 2025 05:18:02 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e9d8fc67sm177078175e9.8.2025.01.14.05.18.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2025 05:18:02 -0800 (PST) Message-ID: <bf7adb97-b1bc-4268-a8c7-246f2d4a01e6@suse.com> Date: Tue, 14 Jan 2025 14:18:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Binutils <binutils@sourceware.org> Cc: "H.J. Lu" <hjl.tools@gmail.com> From: Jan Beulich <jbeulich@suse.com> Subject: [PATCH 0/2] x86-64: enhancements to GOTPCREL / GOTTPOFF handling Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3022.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
Series |
x86-64: enhancements to GOTPCREL / GOTTPOFF handling
|
|
Message
Jan Beulich
Jan. 14, 2025, 1:18 p.m. UTC
While investigating a more fundamental issue (see below) I came to notice shortcomings with GOTPCREL handling when it comes to APX. Furthermore, with the advent of MOVRS accessing the GOT is going to be a primary use case for this new insn (more generally: accessing anything that effectively is never written to). Therefore the first patch here extends support for GOTPCREL to EVEX-encoded arithmetic insns plus MOVRS, while at the same time extending GOTTPOFF support to MOVRS as well. This in turn raises a further question: If arithmetic insns like ADC are deemed okay to use with a @gotpcrel operand (I can see possible use with ADD; I'm already having a harder time seeing use with, say, SUB and CMP), why would other arithmetic insns not be okay to use (and then relax to their immediate operand forms under the right conditions). That would be primarily IMUL. Going from there and seeing that MOV really is the primary insn to use with these relocation types, I'd then further wonder why PUSH wouldn't also be eligible (which is also possible to relax). In the course of figuring how existing code work I further noticed that certain checks are overly lax. I've adjusted right away what can easily be in the new code cloned from the original one. The 2nd patch then mirrors this back to pre-existing code. Now on to the original issue, where the investigation started: I can't help the impression that what the linker does is too aggressive. In particular it appears to assume that @gotpcrel can only be used in small model or x32 code, building upon addresses of resolved symbols being within the low 4Gb (or within ±2Gb for PIC code). Relocation overflows can result otherwise, which the linker then converts to the suggestion to use --no-relax. That suggestion has two problems: For one I think the linker ought to work correctly and reliably without special command line options. And then --no-relax suppresses more of the relaxation than strictly necessary: For the specific purpose of building the Xen hypervisor we'd want the (PIC-specific) MOV->LEA transformation (no issue with the resulting PC-relative relocations), but we'd need to avoid the memory operand -> immediate operand conversions resulting in relocation overflows, for being absolute relocs. These overflows are simply a result of us linking the binary to a base address in the upper half of address space. And no, linking with -shared or -pie is not an option, for the linker then refusing to process other relocations that we use (R_X86_64_32 in particular). The root of the problem, however, is an apparent compiler limitation: While we build with -fpic and while we force all our own symbols to be hidden (to permit respective relaxation), we can't control visibility of compiler declared symbols. Thus the attempt to use -fstack-protector -mstack-protector-guard=global will result in @gotpcrel accesses to __stack_chk_guard. Without --no-relax the linking of that code will fail (see above), while with --no-relax there'll be a non-empty .got, which we deliberately reject by way of a linker script assertion, for being inefficient. I've been trying, with no success, to derive a strategy to overcome the linker issue. The main problem appears to be that at the time the decision is taken whether to relax certain insns (and into which alternative forms), we don't know yet whether the replacement relocs would end up overflowing. Thus, unless the whole determination can be moved (much?) later, the only choice would look to be to undo the transformations (perhaps just partly, i.e. after initially converting to MOV-from-immediate, replace that by the less restrictive RIP- relative LEA; nothing similar is of course possible for arithmetic insns we convert). Which would of course require there to be enough information to restore what had been there originally. 1: x86/APX: widen @gotpcrel and @gottpoff support (incl to MOVRS) 2: x86-64: tighten convert-load-reloc checking Quite likely something will also need doing about the two relocations remaining with the code thus commented: /* These relocations are added only for completeness and aren't be used. */ Simply dropping relocations on the floor without failing the linking process can't be quite right: The diagnostic issued may not be noticed by people, while the resulting binary is almost certainly going to be malfunctioning. Jan