From patchwork Mon Oct 14 06:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 98831 Return-Path: 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 495B83858D29 for ; Mon, 14 Oct 2024 06:40:33 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 8D48E3858CDB for ; Mon, 14 Oct 2024 06:39:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D48E3858CDB 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 8D48E3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728887986; cv=none; b=RET5a2tyDWsdogAcOroEKyrgGACYO4CJfLkQPBZBLAIYoONOxDsy+REKQZl/0pfjQJfi+5H+Qajvae47euhimvDTxV43p+C5Dgs5nal6JtV1QSLgI2kRt4lkaZ6PubdM8qgJDEGREL5UmyuaJfd6cOWNTYurDsVC+SLzjIDbnO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728887986; c=relaxed/simple; bh=TdQxX/icqdLfm9pzOOT5jB+XWvuOCEhsMQ25D7ABL1k=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=ahXhg2El4V2dZwcYphUvA2MVaQ2GaWwqC4mALyRFDULz22C6jVwS7FGRiPqO3shu2jWHkUXdmr8waLdNZ6y3mdt9zDAQAafFT/CC0oD/UscSOFjfJWQwg0Hw2sqbgKfKIThRLPVdj2iR+zMGZN2OXLjKPwV06Hr7yPRMVWxlRas= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-37d4ba20075so2518762f8f.0 for ; Sun, 13 Oct 2024 23:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1728887980; x=1729492780; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:cc:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kxmxjt5GsxSIJWLD6NRgRGclBgf2Ursn8GH3AUhQWRA=; b=esDHVPh3Jghgn1NqwadCbCpqP1wz6TGLKlTt7VPVpvn+zdIM9LTpXPeHWCO5irsEAq Ih6VLOfT6EOhl/shzRFiJkx0tPtgYqHpUY5DeU/90a22v1cNcdXzE0ALWA0QzP+YVPlj TpHBv7fnlCzBXsHLQ6Vhfm/AYEOBgVzzK/kOGJo96MQwKdHVNccRzSPfXUtVmFbfir3c txrOWjGqeYAsZRTgB/nsEoni0aQz8lRE1pUBBGl5Z0b1gwNwVNgLp+gUYRwY1BNzPEpV jc3r+YQd/1b2b5A7n1oHvibr94mPo7UBAUpCjyudz7FDndnb0QLNpuOzt4rg/AP7MI15 H0xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728887980; x=1729492780; h=content-transfer-encoding:in-reply-to:autocrypt:cc:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kxmxjt5GsxSIJWLD6NRgRGclBgf2Ursn8GH3AUhQWRA=; b=i6jBDDbZUfMCxmlm7ALZ5yRd+kcZsEjj2Ocv8O+nSNamwqo8f6TG4p3Px2Zzxh3tLQ RXh8tq3NdwCTvqcYNsRdVl+c3/DKfxz+PvcMOsKDnBoh0ckhSI2tCQTMaT71GLVTHCkg M1DqkxoHmb9OpxtwKW+5u0QRBY72DhboIbvtqer3I0QMXPWHH2ba7M5XZMKPus65y5yC sNUvRNWIyf8fuR6ExdyLzs8Ubf0qmx//9+j0n+ivr8UkQOnOQ/rKyNQw1wXuZnB0A4pF WBQrwwYSPiTCV8sROA8Q7ChiLKNjSDrhxUmZFwupbsPBw7a81Y/uDEImydCVAzXG7yYi ijpw== X-Gm-Message-State: AOJu0Yzil1hKcHfo3RsIlxbkiTI8pamekSObUEC8ucF27JQ+b/ba5mmS F5AVXXmcrv2tRCn6Zku+dFdZnDVMCrwpnfoi2kk+XoZnF8c29NLy7WAkoCm2wELERTiatSCFuIw = X-Google-Smtp-Source: AGHT+IG4WArh0NXBu9BDe6Dw6sL0f6HTn2sk4GaWSUCHVjwhzXbbN900iFfx+0UTlHhiEzAvXMRjXg== X-Received: by 2002:a5d:55c9:0:b0:37c:cd71:2b96 with SMTP id ffacd0b85a97d-37d5529ba0dmr7029997f8f.36.1728887979741; Sun, 13 Oct 2024 23:39:39 -0700 (PDT) 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 ffacd0b85a97d-37d4b6cfb1dsm10507883f8f.50.2024.10.13.23.39.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 13 Oct 2024 23:39:39 -0700 (PDT) Message-ID: <2728e87c-67d4-4007-a632-eed27d31336f@suse.com> Date: Mon, 14 Oct 2024 08:39:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] x86: permit non-immediate offset operands with direct far branches From: Jan Beulich To: Binutils References: Content-Language: en-US Cc: "H.J. Lu" , Lili Cui , "Hu, Lin1" Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu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jv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: X-Spam-Status: No, score=-3023.2 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org While Intel syntax permits such already (as can be observed by there not being a need to prefix the respective operand with "offset"), AT&T syntax so far strictly insists on two immediate operands. Multiple (successive) immediate operands are somewhat problematic anyway, as it's never really clear what their order ought to be. While there's no apparent way of dealing with this for ENTER, EXTRQ, and INSERTQ, for LCALL and LJMP we can aid programmers by permitting alternative forms, with the offset operand being a "displacement" rather than an "immediate". The order of the two operands the doesn't matter; they're distinguished by type. Mark the new templates AT&T-only; the original ones really should have been so, too. For backwards compatibility reasons we can't really correct that mistake ... --- While the proper Intel syntax operand form is sel:offset, for some reason we also support two (comma separated) operands. The ambiguity there is being left alone, as the sel:offset form is enough to avoid it. --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -7061,13 +7061,16 @@ i386_assemble (char *line) swap_operands (); /* The order of the immediates should be reversed for 2-immediates EXTRQ - and INSERTQ instructions. Also UWRMSR wants its immediate to be in the - "canonical" place (first), despite it appearing last (in AT&T syntax, or - because of the swapping above) in the incoming set of operands. */ + and INSERTQ instructions. Also direct far branches and UWRMSR want their + immediate to be in the "canonical" place (first), despite it (possibly) + appearing last (in AT&T syntax, or because of the swapping above) in the + incoming set of operands. */ if ((i.imm_operands == 2 && (t->mnem_off == MN_extrq || t->mnem_off == MN_insertq)) - || (t->mnem_off == MN_uwrmsr && i.imm_operands - && i.operands > i.imm_operands)) + || (((t->opcode_modifier.jump == JUMP_INTERSEGMENT + && !operand_type_check (i.types[0], imm)) + || t->mnem_off == MN_uwrmsr) + && i.imm_operands && i.operands > i.imm_operands)) swap_2_operands (0, 1); if (i.imm_operands) @@ -11621,6 +11624,7 @@ output_interseg_jump (void) int size; int prefix; int code16; + const expressionS *exp1; code16 = 0; if (flag_code == CODE_16BIT) @@ -11659,9 +11663,11 @@ output_interseg_jump (void) *p++ = i.prefix[REX_PREFIX]; *p++ = i.tm.base_opcode; - if (i.op[1].imms->X_op == O_constant) + exp1 = operand_type_check (i.types[0], imm) ? i.op[1].imms + : i.op[1].disps; + if (exp1->X_op == O_constant) { - offsetT n = i.op[1].imms->X_add_number; + offsetT n = exp1->X_add_number; if (size == 2 && !fits_in_unsigned_word (n) @@ -11674,7 +11680,7 @@ output_interseg_jump (void) } else fix_new_exp (frag_now, p - frag_now->fr_literal, size, - i.op[1].imms, 0, reloc (size, 0, 0, i.reloc[1])); + exp1, 0, reloc (size, 0, 0, i.reloc[1])); p += size; if (i.op[0].imms->X_op == O_constant) --- a/gas/testsuite/gas/i386/jump.d +++ b/gas/testsuite/gas/i386/jump.d @@ -15,28 +15,32 @@ Disassembly of section .text: [ ]*[a-f0-9]+: 66 ff 2c bd 00 00 00 00 ljmpw \*0x0\(,%edi,4\) 1c: (R_386_)?(dir)?32 xxx [ ]*[a-f0-9]+: ff 2d 00 00 00 00 ljmp \*0x0 22: (R_386_)?(dir)?32 xxx [ ]*[a-f0-9]+: 66 ff 2d 00 00 00 00 ljmpw \*0x0 29: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: ea 00 00 00 00 34 12 ljmp \$0x1234,\$0x0 2e: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: e8 c7 ff ff ff call (0x0|0 <.text>) -[ ]*[a-f0-9]+: e8 ((fc|c2) ff ff ff|00 00 00 00) call (0x)?(0|3a|3e)( <.text(\+0x3e)?>)? 3a: (R_386_PC)?(DISP)?32 xxx -[ ]*[a-f0-9]+: ff 15 00 00 00 00 call \*0x0 40: (R_386_)?(dir)?32 xxx +[ ]*[a-f0-9]+: ea 00 00 00 00 34 12 ljmp \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: ea 00 00 00 00 34 12 ljmp \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: ea 00 00 00 00 34 12 ljmp \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: e8 b9 ff ff ff call (0x0|0 <.text>) +[ ]*[a-f0-9]+: e8 ((fc|b4) ff ff ff|00 00 00 00) call (0x)?(0|48|4c)( <.text(\+0x4c)?>)?[ ]+[a-f0-9]+: (R_386_PC|DISP)32 xxx +[ ]*[a-f0-9]+: ff 15 00 00 00 00 call \*0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx [ ]*[a-f0-9]+: ff d7 call \*%edi [ ]*[a-f0-9]+: ff 17 call \*\(%edi\) -[ ]*[a-f0-9]+: ff 1c bd 00 00 00 00 lcall \*0x0\(,%edi,4\) 4b: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: 66 ff 1c bd 00 00 00 00 lcallw \*0x0\(,%edi,4\) 53: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: ff 1d 00 00 00 00 lcall \*0x0 59: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: 66 ff 1d 00 00 00 00 lcallw \*0x0 60: (R_386_)?(dir)?32 xxx -[ ]*[a-f0-9]+: 9a 00 00 00 00 34 12 lcall \$0x1234,\$0x0 65: (R_386_)?(dir)?32 xxx +[ ]*[a-f0-9]+: ff 1c bd 00 00 00 00 lcall \*0x0\(,%edi,4\)[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: 66 ff 1c bd 00 00 00 00 lcallw \*0x0\(,%edi,4\)[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: ff 1d 00 00 00 00 lcall \*0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: 66 ff 1d 00 00 00 00 lcallw \*0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: 9a 00 00 00 00 34 12 lcall \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: 9a 00 00 00 00 34 12 lcall \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx +[ ]*[a-f0-9]+: 9a 00 00 00 00 34 12 lcall \$0x1234,\$0x0[ ]+[a-f0-9]+: (R_386_|dir)?32 xxx [ ]*[a-f0-9]+: 66 ff 13 callw \*\(%ebx\) [ ]*[a-f0-9]+: ff 13 call \*\(%ebx\) [ ]*[a-f0-9]+: ff 1b lcall \*\(%ebx\) [ ]*[a-f0-9]+: 66 ff 23 jmpw \*\(%ebx\) [ ]*[a-f0-9]+: ff 23 jmp \*\(%ebx\) [ ]*[a-f0-9]+: ff 2b ljmp \*\(%ebx\) -[ ]*[a-f0-9]+: eb 00 jmp (0x)?7b( <.text(\+0x7b)?>)? +[ ]*[a-f0-9]+: eb 00 jmp (0x)?97( <.text(\+0x97)?>)? [ ]*[a-f0-9]+: 90 nop -[ ]*[a-f0-9]+: e3 00 jecxz (0x)?7e( <.text(\+0x7e)?>)? +[ ]*[a-f0-9]+: e3 00 jecxz (0x)?9a( <.text(\+0x9a)?>)? [ ]*[a-f0-9]+: 90 nop -[ ]*[a-f0-9]+: eb 00 jmp (0x)?81( <.text(\+0x81)?>)? +[ ]*[a-f0-9]+: eb 00 jmp (0x)?9d( <.text(\+0x9d)?>)? [ ]*[a-f0-9]+: 90 nop [ ]*[a-f0-9]+: 9a 90 90 90 90 90 90 lcall \$0x9090,\$0x90909090 [ ]*[a-f0-9]+: 9a 90 90 90 90 90 90 lcall \$0x9090,\$0x90909090 --- a/gas/testsuite/gas/i386/jump.s +++ b/gas/testsuite/gas/i386/jump.s @@ -13,6 +13,8 @@ ljmp *xxx ljmpw *xxx ljmp $0x1234,$xxx + ljmp $0x1234,xxx + ljmp xxx,$0x1234 call 1b call xxx @@ -24,6 +26,8 @@ lcall *xxx lcallw *xxx lcall $0x1234,$xxx + lcall $0x1234,xxx + lcall xxx,$0x1234 .intel_syntax noprefix call word ptr [ebx] --- a/opcodes/i386-opc.tbl +++ b/opcodes/i386-opc.tbl @@ -494,6 +494,7 @@ call, 0x9a, No64, JumpInterSegment|Impli call, 0xff/3, 0, Amd64|Modrm|JumpAbsolute|ImplicitStackOp|DefaultSize|NoSuf, { Dword|Fword|BaseIndex } call, 0xff/3, x64, Intel64|Modrm|JumpAbsolute|ImplicitStackOp|NoSuf, { Dword|Fword|Tbyte|BaseIndex } lcall, 0x9a, No64, JumpInterSegment|DefaultSize|No_bSuf|No_sSuf|No_qSuf, { Imm16, Imm16|Imm32 } +lcall, 0x9a, No64, JumpInterSegment|DefaultSize|No_bSuf|No_sSuf|No_qSuf|ATTSyntax, { Imm16, Disp16|Disp32 } lcall, 0xff/3, 0, Amd64|Modrm|JumpAbsolute|DefaultSize|No_bSuf|No_sSuf|No_qSuf, { Unspecified|BaseIndex } lcall, 0xff/3, x64, Intel64|Modrm|JumpAbsolute|No_bSuf|No_sSuf, { Unspecified|BaseIndex } @@ -507,6 +508,7 @@ jmp, 0xea, No64, JumpInterSegment|No_bSu jmp, 0xff/5, 0, Amd64|Modrm|JumpAbsolute|NoSuf, { Dword|Fword|BaseIndex } jmp, 0xff/5, x64, Intel64|Modrm|JumpAbsolute|NoSuf, { Dword|Fword|Tbyte|BaseIndex } ljmp, 0xea, No64, JumpInterSegment|No_bSuf|No_sSuf|No_qSuf, { Imm16, Imm16|Imm32 } +ljmp, 0xea, No64, JumpInterSegment|No_bSuf|No_sSuf|No_qSuf|ATTSyntax, { Imm16, Disp16|Disp32 } ljmp, 0xff/5, 0, Amd64|Modrm|JumpAbsolute|No_bSuf|No_sSuf|No_qSuf, { Unspecified|BaseIndex } ljmp, 0xff/5, x64, Intel64|Modrm|JumpAbsolute|No_bSuf|No_sSuf, { Unspecified|BaseIndex }