From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id A4C40383F96F for ; Thu, 30 Jun 2022 17:51:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4C40383F96F Received: by mail-pj1-x102a.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so163562pji.4 for ; Thu, 30 Jun 2022 10:51:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wrMGOmCScnkYxjOzx9JaMK4VcT3vxqnHrCvYzOYItmM=; b=PjH4MJX7lXOhjib/n2ArLaUuGyP+szEij9brH+Ukliidy3naUoZ4/seRueGaBEUBGO GWBmgT0VflVDLxYaf1U6SVXtzceTmuHXas7m0YOkP4F3hO+tegDliAFW4RQzNd5Gi4Vk D2g2YtY0kva3YSqzVhdEz7UzbzikCrPDI1FjWOKQehkrlRBAA2VNJxGWMAl7oy0eKp/u 0jvCAK2P8CmMF9xCxmIU14D41emVqghJ+/WGwS6e0aqVXaq1E2K1cGOh9WrRVL7JhHQM /lreY83cBicr/ZEntzOs1OxCGbpyH59nHCzZaalqeaRN4dJNCP9i9YLR7wSjNyprodbN jY7w== X-Gm-Message-State: AJIora+U9XyWIWK/HjQJitwBiJyG3m+b6t9i5jtLIsTolvCiGWeX1ec0 jhlaJKDZtTpVmtWeZ1pWSbQiIW1rJbMM2xRuqpAaqdfH X-Google-Smtp-Source: AGRyM1tNhvORi0TArtPQ3jPAEmC+FY4dIkO+tvzQCZLMTewF/wPDymp0zoMIMdGooSZkP2iY03Fa1/e5WM5kdibx/Ag= X-Received: by 2002:a17:902:a502:b0:15e:c251:b769 with SMTP id s2-20020a170902a50200b0015ec251b769mr15748090plq.115.1656611468606; Thu, 30 Jun 2022 10:51:08 -0700 (PDT) MIME-Version: 1.0 References: <0806b8f1-b463-41e8-1980-b511bdb451ff@suse.com> In-Reply-To: From: "H.J. Lu" Date: Thu, 30 Jun 2022 10:50:32 -0700 Message-ID: Subject: Re: [PATCH 1/3] x86-64: improve handling of branches to absolute addresses To: Jan Beulich Cc: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3018.9 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 17:51:15 -0000 On Thu, Jun 30, 2022 at 5:08 AM Jan Beulich wrote: > > There are two related problems here: The use of "addr32" on a direct > branch would, besides causing a warning, result in operands to be > permitted which mistakenly are refused without "addr32". Plus at some > point not too long ago I'm afraid it may have been me who regressed the > relocation addends emitted for such branches. Correct both problems, > adding a testcase to guard against regressing this again. > --- > In principle things like "JECXZ " should be permitted as well, > I think. Whether the destination is within reach can only be determined > by the linker. But that likely being a more intrusive change, I guess we > can leave this as is until someone really needs it to work. > > If "ELF: emit symbol table when there are relocations" (submitted > earlier) goes in before this change, I'd be inclined to drop the label > again from the new testcase. The original lack of a label there was how > I noticed that other issue, so the testcase here could at once serve to > test that changed behavior as well. > > --- a/gas/config/tc-i386.c > +++ b/gas/config/tc-i386.c > @@ -4975,7 +4975,9 @@ md_assemble (char *line) > if (i.imm_operands) > optimize_imm (); > > - if (i.disp_operands && !want_disp32 (current_templates->start)) > + if (i.disp_operands && !want_disp32 (current_templates->start) > + && (!current_templates->start->opcode_modifier.jump > + || i.jumpabsolute || i.types[0].bitfield.baseindex)) > { > for (j = 0; j < i.operands; ++j) > { > @@ -5985,7 +5987,9 @@ optimize_disp (void) > /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */ > if ((i.types[op].bitfield.disp32 > || (flag_code == CODE_64BIT > - && want_disp32 (current_templates->start))) > + && want_disp32 (current_templates->start) > + && (!current_templates->start->opcode_modifier.jump > + || i.jumpabsolute || i.types[op].bitfield.baseindex))) > && fits_in_unsigned_long (op_disp)) > { > /* If this operand is at most 32 bits, convert > --- a/gas/testsuite/gas/i386/i386.exp > +++ b/gas/testsuite/gas/i386/i386.exp > @@ -1314,6 +1314,7 @@ if [gas_64_check] then { > run_dump_test "x86-64-branch-3" > run_list_test "x86-64-branch-4" "-al -mintel64" > run_list_test "x86-64-branch-5" "-al" > + run_dump_test "x86-64-branch-6" > > run_dump_test "x86-64-rip-2" > > --- /dev/null > +++ b/gas/testsuite/gas/i386/x86-64-branch-6.d > @@ -0,0 +1,21 @@ > +#objdump: -r > +#name: x86-64 branch 6 > +#warning_output: x86-64-branch-6.e > + > +.*: +file format .* > + > +RELOCATION RECORDS FOR \[\.text\]: > +OFFSET +TYPE +VALUE * > +0+01 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+11 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +0+21 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+31 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +0+07 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+0c R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+17 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +0+1c R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +0+27 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+2c R_X86_64_PC32 +\*ABS\*\+0x000000008765431d > +0+37 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +0+3c R_X86_64_PC32 +\*ABS\*\+0x000000087654320c > +#pass > --- /dev/null > +++ b/gas/testsuite/gas/i386/x86-64-branch-6.s > @@ -0,0 +1,18 @@ > + .text > + > +branch_6: > + call 0x87654321 > + je 0x87654321 > + jmp 0x87654321 > + > + call 0x876543210 > + je 0x876543210 > + jmp 0x876543210 > + > + addr32 call 0x87654321 > + addr32 je 0x87654321 > + addr32 jmp 0x87654321 > + > + addr32 call 0x876543210 > + addr32 je 0x876543210 > + addr32 jmp 0x876543210 > --- /dev/null > +++ b/gas/testsuite/gas/i386/x86-64-branch-6.e > @@ -0,0 +1,7 @@ > +.*: Assembler messages: > +.*:12: Warning: skipping prefixes on `call' > +.*:13: Warning: skipping prefixes on `je' > +.*:14: Warning: skipping prefixes on `jmp' > +.*:16: Warning: skipping prefixes on `call' > +.*:17: Warning: skipping prefixes on `je' > +.*:18: Warning: skipping prefixes on `jmp' > OK. Thanks. -- H.J.