From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2068.outbound.protection.outlook.com [40.107.105.68]) by sourceware.org (Postfix) with ESMTPS id D863A385DC03 for ; Fri, 24 Nov 2023 09:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D863A385DC03 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 D863A385DC03 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.105.68 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700816613; cv=pass; b=EBDRvdw1d5grsa9x10xLyniYV8ltYOre18d22vb9ulDJ1vd+TGkBlJbDpaiYCIKoRS5j72wE9tDBUFYqOxP3DK0gBCdV9lqjYap01CTjF1ot7/rSBn+fn22ySTKzvzVgHouUbvmjG+AIIT07tJg5CPohvKIkbCHyFWm+Pf+jcqs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700816613; c=relaxed/simple; bh=NnZ3rO6A7uWfmexUMjXFcPtvjJkZNqzQ6RiuT8eY0pY=; h=DKIM-Signature:Message-ID:Date:Subject:From:To:MIME-Version; b=cL2XUij+XDgz267cuwniAwirebaLYvZm57CfqMpA+/YDvSUrvl/INT9LzPRycISR8fHbiCKkED2tLCgcEdbPIiON8T0b4xZawHrkf1lp8+IjlOwT3uN9peG7YjQAHHDo7elDVYsk2Cv0byP0rfCnb1q91i18sNO0w11kwMhECrY= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XTzIsLs+xoUcY4WE21Ls6p/0YaqNL+qZHgcdIlmAjL1QZ33N/z1PXXxKyKR8OhtRD1+WZDPD8utwM8B/t22NWcBH1S3ze+leEzn3L8T0a4KJhQ+aYSPRjnZtjLynFa9kJrY/kIVBjNLSZAWMgteJSys0aE2NNax8rZ9gyRU9E/4lS18UMjCz+xjVRZu0b8wQVNQ9fANNr8mznJeHY1GPoKVWbe4ntU1pfHOlM8m5tfXWazAVzRU74LcmJJ0c1hkIXFMg1/5Y7DZp6y4kXiiNofCB7LsYYtI75sJp6uNaa8GPVeL2f67QT9XVkg5CoXHF87BFKXHRwMZqnwh3hHFULw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W6gI19wzPsy41sy4+PVmnvhUJtJ8ONUTxnW/gbnYpyA=; b=ByR6Rg+Q/d9tlB1BaD3G1CN/pKvWuENcNIGAeFR3Ici+BHhTZTmycbTWfq9kmecUdnZ2U9JtmPwJuWlSFR5tySWU6QkYUWscraUDE8CcSU+/qVKDXBY+07wuDc4lOCBBqofD6P73r+hFkoUD158/M1syPUPDu25Tte2KrRWjC+fhxQdzU8P+YVCYRy9WEYBKnDRaEIz0FnMCccoPtvOIemNX4xv/m3srUHUMYRGO2f2oG8SGoUm7j9ZMlyTC0+JgW1AENGMP35wYtnTO+1q12s+y/mLn5Hj1KN+CjHpnetClwJ79yFg+L6DtOLrHQ4A7REpGGetnOvHTeUTFA7ECYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W6gI19wzPsy41sy4+PVmnvhUJtJ8ONUTxnW/gbnYpyA=; b=rtIzU79mJwH2BuJZ4wNF34Qx81z7iqJIEKEnZtkbl8pAYVQdk6HdySz9UGnuWW/zHRtvNRwSIqU9NF0savdqkvwemkQekJQpho/3iuuzpH+mbkPBQz38fN3OB8vU0iQNj5ne9LeqslvsI9vAzTt18QFerQCEHMMGWFlnpCotee9onBN62aRSHzdtQdHWL52GBBffRygk64mIV4+vXAyT8KzvQIDPeM9WwwDJp8sjPgOkkdCzaRsxSXIT8qFOwX1fWUlyG8CwgyTIPtqqXcnz+RNkPo+DWPzmvS3/WQG+vcLF09e5EqGTzfLLT3QIl/dAMqgn3UVHqT9wcEzuQKDiKg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DB9PR04MB8090.eurprd04.prod.outlook.com (2603:10a6:10:240::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.13; Fri, 24 Nov 2023 09:03:27 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7046.012; Fri, 24 Nov 2023 09:03:27 +0000 Message-ID: <94626e2b-0e73-4267-9c80-cb25e1dbab9b@suse.com> Date: Fri, 24 Nov 2023 10:03:26 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/6] x86: last-insn recording should be per-section Content-Language: en-US From: Jan Beulich To: Binutils Cc: "H.J. Lu" References: Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz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fGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR5P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f3::10) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DB9PR04MB8090:EE_ X-MS-Office365-Filtering-Correlation-Id: 11177b89-5a1d-4884-8267-08dbeccc38d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wqIpm3f2rWPu3JVEeqCCZ/Jrm8REV4UV2HTTNtaRETbHa+8f932i2Rz6gdZrYONLUAmyH42TULTnh+pjGDSntVpzTW8XtWJEQtGpZwrCiRApZHfaVoA4cMRag4wgft113vPpyae8rjDreOOkKbIjRdIDeixx7IVMtls88x6Vg5B0GdrP4FSbz/5DrQsxX1+GpbpNpuqZ7ge29aVulHJopduAdkPhdpk7cSnKSdtF/pQpwNm4b1nsX3BkSjtsJbFM4BIUWDKNWf7VUwWMj83/7KgT3jmofZj+fec/pylrVFBgXL2BuyiNN+xZfvqxNtu4rMr2Zzik2xJ4xQRGXkFUsO/1EbSOn2pMnYPc3oJP9O0L6hj3NRiWBueNPBVSrMrXxYfQwrDlTUevV6wKVBjaA319PLzqAlVLYf7u6U5MLvVm+Oj4Q9TRsF74ySTLbIapNUCjGNvsubkeeDKpUtrsnHOfUA+zdpdBPrIqgj18wjY0CjNfSSTmIrCGwAoKL89jx8ZAMhjRVEA+owNS/CgWFaKgM2FHl28EQBuphedPDWvXXsXikxFhqu/pydFB/6qiKBTLi9PIVnERKS/0BfqSOJfFcbqsXMGSRBb2BJCrUTfagyawVScdVa5Zo6imHEHpO5h1Gh0TFoV3QLdrTjAA9FYWredIsxdHUb/ynFiCVGyzRP6zw9QO+p0ux7AyyqgQ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(376002)(39860400002)(346002)(366004)(230273577357003)(230173577357003)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(41300700001)(30864003)(2906002)(5660300002)(6486002)(8936002)(31686004)(8676002)(4326008)(478600001)(6506007)(36756003)(6512007)(26005)(2616005)(83380400001)(86362001)(31696002)(66556008)(316002)(66476007)(66946007)(6916009)(38100700002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cEd4bHdSY2ZVS29LOWtQRHpOVy9iY2lCWGdEK3ZBeC9iejJrSUxKUThVODlH?= =?utf-8?B?RVpjQ0FmckJjMmc2WGs1SkJNMDB0cmc5SEhxKzhjaGRWNDV2WTVFY0JNbXNG?= =?utf-8?B?aDFkWHFpMGswUS9kK0d0cDRDa0JXRHVTOHBNZzhBMEFTSjNST2ZteEtTMFR3?= =?utf-8?B?WnFwOVhJMk5YbWlRdFhYSkRQR0ttdWZRRmo2M1lmcDNJZnJVVjZ6eUIvNFQw?= =?utf-8?B?dk9aeEROMkRDNldnMEJveHZsMms4MTN5VjhvMW0yblpRMDc0bkhMR0xCMHdw?= =?utf-8?B?cDdsZUNjSlo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TG9qWmZUYkdmaVBDeGhDaTRT?= =?utf-8?Q?2ScbuFcRqCHomQGFaGLf3XHfB?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11177b89-5a1d-4884-8267-08dbeccc38d5 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2023 09:03:27.5104 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9LCYzQQqXz3tEKf1AO0YYzw8HlCKUdUWhUE85TxB2V2BRpzpk6lvlL7evyl3ouYsz++k7srtTimockFYIpipqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8090 X-Spam-Status: No, score=-3026.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 List-Id: Otherwise intermediate section switches result in inconsistent behavior. Note, however, that intermediate sub-section switches will continue to result in inconsistent or even inappropriate behavior. While there also add recording of state to s_insn(). --- i386_cons_align() qualifying the recording on SEC_CODE seems suspicious, too: md_assemble() isn't constrained to emitting instructions to only text sections. For sub-sections the best I can think of that we could do is warn when now_subseg is nonzero wherever we already warn based on last_insn state (and similarly bail rather than inserting any code). That would have not really intended effects in subsequent patches, though: We'd then generally suppress optimizations outside of subseg 0, and we'd also prefix plain old NOPs there (in i386_generate_nops()). For .insn I'm not entirely decided: We might also assume that only proper insns are constructed this way, and hence record last_insn_other in s_insn(). --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -178,7 +178,7 @@ static int check_word_reg (void); static int finalize_imm (void); static int process_operands (void); static const reg_entry *build_modrm_byte (void); -static void output_insn (void); +static void output_insn (const struct last_insn *); static void output_imm (fragS *, offsetT); static void output_disp (fragS *, offsetT); #ifndef I386COFF @@ -677,21 +677,6 @@ static enum lfence_before_ret_kind } lfence_before_ret; -/* Types of previous instruction is .byte or prefix. */ -static struct - { - segT seg; - const char *file; - const char *name; - unsigned int line; - enum last_insn_kind - { - last_insn_other = 0, - last_insn_directive, - last_insn_prefix - } kind; - } last_insn; - /* 1 if the assembler should generate relax relocations. */ static int generate_relax_relocations @@ -4971,7 +4956,7 @@ insert_lfence_after (void) /* Output lfence, 0xfaee8, before instruction. */ static void -insert_lfence_before (void) +insert_lfence_before (const struct last_insn *last_insn) { char *p; @@ -5007,12 +4992,11 @@ insert_lfence_before (void) else return; - if (last_insn.kind != last_insn_other - && last_insn.seg == now_seg) + if (last_insn->kind != last_insn_other) { - as_warn_where (last_insn.file, last_insn.line, + as_warn_where (last_insn->file, last_insn->line, _("`%s` skips -mlfence-before-indirect-branch on `%s`"), - last_insn.name, insn_name (&i.tm)); + last_insn->name, insn_name (&i.tm)); return; } @@ -5027,12 +5011,11 @@ insert_lfence_before (void) if (lfence_before_ret != lfence_before_ret_none && (i.tm.base_opcode | 1) == 0xc3) { - if (last_insn.kind != last_insn_other - && last_insn.seg == now_seg) + if (last_insn->kind != last_insn_other) { - as_warn_where (last_insn.file, last_insn.line, + as_warn_where (last_insn->file, last_insn->line, _("`%s` skips -mlfence-before-ret on `%s`"), - last_insn.name, insn_name (&i.tm)); + last_insn->name, insn_name (&i.tm)); return; } @@ -5129,6 +5112,8 @@ md_assemble (char *line) const char *end, *pass1_mnem = NULL; enum i386_error pass1_err = 0; const insn_template *t; + struct last_insn *last_insn + = &seg_info(now_seg)->tc_segment_info_data.last_insn; /* Initialize globals. */ current_templates.end = current_templates.start = NULL; @@ -5682,23 +5667,21 @@ md_assemble (char *line) if (i.rex != 0) add_prefix (REX_OPCODE | i.rex); - insert_lfence_before (); + insert_lfence_before (last_insn); /* We are ready to output the insn. */ - output_insn (); + output_insn (last_insn); insert_lfence_after (); - last_insn.seg = now_seg; - if (i.tm.opcode_modifier.isprefix) { - last_insn.kind = last_insn_prefix; - last_insn.name = insn_name (&i.tm); - last_insn.file = as_where (&last_insn.line); + last_insn->kind = last_insn_prefix; + last_insn->name = insn_name (&i.tm); + last_insn->file = as_where (&last_insn->line); } else - last_insn.kind = last_insn_other; + last_insn->kind = last_insn_other; } /* The Q suffix is generally valid only in 64-bit mode, with very few @@ -9667,7 +9650,8 @@ maybe_fused_with_jcc_p (enum mf_cmp_kind /* Return 1 if a FUSED_JCC_PADDING frag should be generated. */ static int -add_fused_jcc_padding_frag_p (enum mf_cmp_kind* mf_cmp_p) +add_fused_jcc_padding_frag_p (enum mf_cmp_kind *mf_cmp_p, + const struct last_insn *last_insn) { /* NB: Don't work with COND_JUMP86 without i386. */ if (!align_branch_power @@ -9678,13 +9662,12 @@ add_fused_jcc_padding_frag_p (enum mf_cm if (maybe_fused_with_jcc_p (mf_cmp_p)) { - if (last_insn.kind == last_insn_other - || last_insn.seg != now_seg) + if (last_insn->kind == last_insn_other) return 1; if (flag_debug) - as_warn_where (last_insn.file, last_insn.line, + as_warn_where (last_insn->file, last_insn->line, _("`%s` skips -malign-branch-boundary on `%s`"), - last_insn.name, insn_name (&i.tm)); + last_insn->name, insn_name (&i.tm)); } return 0; @@ -9693,7 +9676,7 @@ add_fused_jcc_padding_frag_p (enum mf_cm /* Return 1 if a BRANCH_PREFIX frag should be generated. */ static int -add_branch_prefix_frag_p (void) +add_branch_prefix_frag_p (const struct last_insn *last_insn) { /* NB: Don't work with COND_JUMP86 without i386. Don't add prefix to PadLock instructions since they include prefixes in opcode. */ @@ -9709,14 +9692,13 @@ add_branch_prefix_frag_p (void) if (!i.operands || i.tm.opcode_modifier.isprefix) return 0; - if (last_insn.kind == last_insn_other - || last_insn.seg != now_seg) + if (last_insn->kind == last_insn_other) return 1; if (flag_debug) - as_warn_where (last_insn.file, last_insn.line, + as_warn_where (last_insn->file, last_insn->line, _("`%s` skips -malign-branch-boundary on `%s`"), - last_insn.name, insn_name (&i.tm)); + last_insn->name, insn_name (&i.tm)); return 0; } @@ -9725,7 +9707,8 @@ add_branch_prefix_frag_p (void) static int add_branch_padding_frag_p (enum align_branch_kind *branch_p, - enum mf_jcc_kind *mf_jcc_p) + enum mf_jcc_kind *mf_jcc_p, + const struct last_insn *last_insn) { int add_padding; @@ -9799,13 +9782,12 @@ add_branch_padding_frag_p (enum align_br } if (add_padding - && last_insn.kind != last_insn_other - && last_insn.seg == now_seg) + && last_insn->kind != last_insn_other) { if (flag_debug) - as_warn_where (last_insn.file, last_insn.line, + as_warn_where (last_insn->file, last_insn->line, _("`%s` skips -malign-branch-boundary on `%s`"), - last_insn.name, insn_name (&i.tm)); + last_insn->name, insn_name (&i.tm)); return 0; } @@ -9813,7 +9795,7 @@ add_branch_padding_frag_p (enum align_br } static void -output_insn (void) +output_insn (const struct last_insn *last_insn) { fragS *insn_start_frag; offsetT insn_start_off; @@ -9943,7 +9925,7 @@ output_insn (void) insn_start_frag = frag_now; insn_start_off = frag_now_fix (); - if (add_branch_padding_frag_p (&branch, &mf_jcc)) + if (add_branch_padding_frag_p (&branch, &mf_jcc, last_insn)) { char *p; /* Branch can be 8 bytes. Leave some room for prefixes. */ @@ -10029,7 +10011,7 @@ output_insn (void) if (branch) /* Skip if this is a branch. */ ; - else if (add_fused_jcc_padding_frag_p (&mf_cmp)) + else if (add_fused_jcc_padding_frag_p (&mf_cmp, last_insn)) { /* Make room for padding. */ frag_grow (MAX_FUSED_JCC_PADDING_SIZE); @@ -10045,7 +10027,7 @@ output_insn (void) fragP->tc_frag_data.branch_type = align_branch_fused; fragP->tc_frag_data.max_bytes = MAX_FUSED_JCC_PADDING_SIZE; } - else if (add_branch_prefix_frag_p ()) + else if (add_branch_prefix_frag_p (last_insn)) { unsigned int max_prefix_size = align_branch_prefix_size; @@ -10948,6 +10930,7 @@ s_insn (int dummy ATTRIBUTE_UNUSED) unsigned int j; valueT val; bool vex = false, xop = false, evex = false; + struct last_insn *last_insn; init_globals (); @@ -11701,7 +11684,11 @@ s_insn (int dummy ATTRIBUTE_UNUSED) else if (i.rex != 0) add_prefix (REX_OPCODE | i.rex); - output_insn (); + last_insn = &seg_info(now_seg)->tc_segment_info_data.last_insn; + output_insn (last_insn); + last_insn->kind = last_insn_directive; + last_insn->name = ".insn directive"; + last_insn->file = as_where (&last_insn->line); done: *saved_ilp = saved_char; @@ -15496,13 +15483,15 @@ s_bss (int ignore ATTRIBUTE_UNUSED) void i386_cons_align (int ignore ATTRIBUTE_UNUSED) { - if (last_insn.kind != last_insn_directive + struct last_insn *last_insn + = &seg_info(now_seg)->tc_segment_info_data.last_insn; + + if (last_insn->kind != last_insn_directive && (bfd_section_flags (now_seg) & SEC_CODE)) { - last_insn.seg = now_seg; - last_insn.kind = last_insn_directive; - last_insn.name = "constant directive"; - last_insn.file = as_where (&last_insn.line); + last_insn->kind = last_insn_directive; + last_insn->name = "constant directive"; + last_insn->file = as_where (&last_insn->line); if (lfence_before_ret != lfence_before_ret_none) { if (lfence_before_indirect_branch != lfence_branch_none) --- a/gas/config/tc-i386.h +++ b/gas/config/tc-i386.h @@ -281,6 +281,23 @@ extern enum i386_flag_code { CODE_64BIT } i386_flag_code; +struct i386_segment_info { + /* Type of previous "instruction", e.g. .byte or stand-alone prefix. */ + struct last_insn { + const char *file; + const char *name; + unsigned int line; + enum last_insn_kind + { + last_insn_other = 0, + last_insn_directive, + last_insn_prefix + } kind; + } last_insn; +}; + +#define TC_SEGMENT_INFO_TYPE struct i386_segment_info + struct i386_tc_frag_data { union --- /dev/null +++ b/gas/testsuite/gas/i386/lfence-section.d @@ -0,0 +1,19 @@ +#as: -mlfence-before-indirect-branch=all +#warning_output: lfence-section.e +#objdump: -dw +#name: -mlfence-before-indirect-branch=all w/ section switches + +.*: +file format .* + + +Disassembly of section .text: + +0+ <_start>: + +[a-f0-9]+: f3 ff d0 repz call \*%eax + +[a-f0-9]+: f3 c3 repz ret + +[a-f0-9]+: cc int3 + +[a-f0-9]+: cc int3 + +[a-f0-9]+: cc int3 + +Disassembly of section \.text2: +#pass --- /dev/null +++ b/gas/testsuite/gas/i386/lfence-section.e @@ -0,0 +1,3 @@ +.*: Assembler messages: +.*:3: Warning: `rep` skips -mlfence-before-indirect-branch on `call` +.*:11: Warning: `rep` skips -mlfence-before-ret on `ret` --- /dev/null +++ b/gas/testsuite/gas/i386/lfence-section.s @@ -0,0 +1,19 @@ + .text +_start: + rep + + .section .text2, "ax" +aux1: + nop + + .text + call *%eax + rep + + .section .text2, "ax" +aux2: + nop + + .text + ret + .p2align 2, 0xcc --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -642,6 +642,17 @@ if [gas_32_check] then { run_dump_test "lfence-ret-c" run_dump_test "lfence-ret-d" run_dump_test "lfence-byte" + # This test uses the .section directive, which only ELF and COFF/PE support. + if {[is_elf_format] + || [istarget "*-*-vxworks*"] + || [istarget "*-*-coff*"] + || [istarget "*-*-pe*"] + || [istarget "*-*-cygwin*"] + || [istarget "*-*-mingw*"] + } then { + run_dump_test "lfence-section" + } + run_dump_test "branch" # These tests require support for 8 and 16 bit relocs,