From patchwork Fri Mar 7 14:23:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 107509 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 993F43858D39 for ; Fri, 7 Mar 2025 14:25:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 993F43858D39 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=PYTuMBQH X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id A178D3858CD9 for ; Fri, 7 Mar 2025 14:23:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A178D3858CD9 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 A178D3858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741357399; cv=none; b=b1zs0VKUGM3PshcEA7FOMRKrOLtVUsEmZPX/FekN8Zx2S36KEFD8y7bGndGpJJVzP+iV2+0DeNg2NHsUHg1E7eVeDER8/Bzf176Ha2gRdnRjE7EnCgVUOgUmYSbmPxBfWO9aRWY68ZVsHG5joa8zTxX3zKf3+dukpEoItbIGSDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741357399; c=relaxed/simple; bh=q/TWLxSzBojP9gAXuFeb2WQO4cXSPHt9kavFNpQH7qQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=l+dDhTNMFC6W/4N7loEaW36OvmB21QWz+OQA8+5G6kt68MurLVAliWs1ftsHTM5LQSAvS0uAgeUraKEtCfO5+rFI0ZRUtrZeyv+h5+qpNbBvcX8kQRwJM+m+2bSaS7RXDufWlTeu45rF6ERcEae8PAbHovRTUXjIaU7SNkSlNTg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A178D3858CD9 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43bd87f7c2eso10964445e9.3 for ; Fri, 07 Mar 2025 06:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1741357397; x=1741962197; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zXecwx2fqXzBHenVh3pYpidh8mc7E3+AmMpkiawGJV4=; b=PYTuMBQHzf79Q/uUkdAsoT/Tde1BPsyXDc+gchOvecj/vbLmqdyZO8KROH2FPp9aHg vr+SXddswAnjl1S/kJ6zPXiZiZxJEaSDSK48aFBxgYzzCqUPn8gRUTAhHFjjQWVR24Pw FMyCmUuWX/sv9lfMu33RAYR3AAf7P9MxMtAz4kB1pv58nSMbl706JJMQXKG8SqnHXc6D O8V27knBPZ0x2HBErAfoqIAXJ/bBLAqzaZTrG4yJa3GviZeSBb3E85taL7HiTf0Gqo2w JtSBSDBqGwYhkWr4DfXviJX3NEeU1odYpdouzI/HDFqqZOc42OZxwNyyJruwRfEXn2oq itWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741357397; x=1741962197; h=content-transfer-encoding:in-reply-to:autocrypt: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=zXec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:b0:43a:ed4d:716c with SMTP id 5b1f17b1804b1-43c5a631741mr23534145e9.22.1741357397047; Fri, 07 Mar 2025 06:23:17 -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-43bd4293250sm81835885e9.16.2025.03.07.06.23.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Mar 2025 06:23:16 -0800 (PST) Message-ID: <3245e758-3165-4355-baf5-6eb10955cd50@suse.com> Date: Fri, 7 Mar 2025 15:23:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/5] gas: include .cfi_* generated data in listing From: Jan Beulich To: Binutils References: Content-Language: en-US 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 In-Reply-To: X-Spam-Status: No, score=-3021.5 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 These are data generating directives not overly different from e.g. .byte and .long. Whatever (directly) results from should also be represented in the listing, if one was requested. It's just that the output data is generated much later than the parsing of the directive arguments. --- a/gas/config/tc-alpha.c +++ b/gas/config/tc-alpha.c @@ -4059,7 +4059,8 @@ alpha_elf_md_finish (void) function symbol. This prevents problems with globals. */ cfi_new_fde (symbol_temp_new (S_GET_SEGMENT (p->func_sym), symbol_get_frag (p->func_sym), - S_GET_VALUE (p->func_sym))); + S_GET_VALUE (p->func_sym)), + false); cfi_set_sections (); cfi_set_return_column (p->ra_regno); --- a/gas/dw2gencfi.c +++ b/gas/dw2gencfi.c @@ -440,16 +440,25 @@ alloc_cfi_insn_data (void) *cur_fde_data->last = insn; cur_fde_data->last = &insn->next; SET_CUR_SEG (insn, is_now_linkonce_segment ()); +#ifndef NO_LISTING + insn->listing_ctxt = cur_fde_data->listing_ctxt ? listing_tail : NULL; +#endif return insn; } /* Construct a new FDE structure that begins at LABEL. */ void -cfi_new_fde (symbolS *label) +cfi_new_fde (symbolS *label, bool do_listing) { struct fde_entry *fde = alloc_fde_entry (); fde->start_address = label; + if (do_listing) + { +#ifndef NO_LISTING + fde->listing_ctxt = listing_tail; +#endif + } frchain_now->frch_cfi_data->last_address = label; } @@ -458,7 +467,12 @@ cfi_new_fde (symbolS *label) void cfi_end_fde (symbolS *label) { - frchain_now->frch_cfi_data->cur_fde_data->end_address = label; + struct fde_entry *cur_fde_data = frchain_now->frch_cfi_data->cur_fde_data; + + cur_fde_data->end_address = label; +#ifndef NO_LISTING + cur_fde_data->listing_end = cur_fde_data->listing_ctxt ? listing_tail : NULL; +#endif frchain_now->frch_cfi_data = NULL; } @@ -1279,7 +1293,7 @@ dot_cfi_startproc (int ignored ATTRIBUTE return; } - cfi_new_fde (symbol_temp_new_now ()); + cfi_new_fde (symbol_temp_new_now (), listing & LISTING_LISTING); SKIP_WHITESPACE (); if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"') @@ -2058,7 +2072,19 @@ output_fde (struct fde_entry *fde, struc for (; first; first = first->next) if (CUR_SEG (first) == CUR_SEG (fde)) - output_cfi_insn (first); + { +#ifndef NO_LISTING + if (eh_frame) + listing_override_tail (first->listing_ctxt); +#endif + output_cfi_insn (first); + } + +#ifndef NO_LISTING + /* Associate any padding with .cfi_endproc. */ + if (eh_frame) + listing_override_tail (fde->listing_end); +#endif frag_align (align, DW_CFA_nop, 0); symbol_set_value_now (end_address); @@ -2305,6 +2331,12 @@ cfi_finish (void) segT cfi_seg, ccseg; struct fde_entry *fde; struct cfi_insn_data *first; +#ifndef NO_LISTING + /* We may temporarily replace listing_tail, which otherwise isn't supposed + to be changing anymore. Play safe and restore the original value + afterwards. */ + struct list_info_struct *saved_listing_tail = NULL; +#endif int save_flag_traditional_format, seek_next_seg; if (all_fde_data == 0) @@ -2387,6 +2419,16 @@ cfi_finish (void) fde->end_address = fde->start_address; } +#ifndef NO_LISTING + { + struct list_info_struct *listing_prev + = listing_override_tail (fde->listing_ctxt); + + if (!saved_listing_tail) + saved_listing_tail = listing_prev; + } +#endif + cie = select_cie_for_fde (fde, true, &first, 2); fde->eh_loc = symbol_temp_new_now (); output_fde (fde, cie, true, first, @@ -2593,6 +2635,11 @@ cfi_finish (void) htab_delete (dwcfi_hash); dwcfi_hash = NULL; } + +#ifndef NO_LISTING + if (saved_listing_tail) + listing_tail = saved_listing_tail; +#endif } #else /* TARGET_USE_CFIPOP */ --- a/gas/dw2gencfi.h +++ b/gas/dw2gencfi.h @@ -52,7 +52,7 @@ extern void dot_cfi_sections (int); extern void cfi_finish (void); /* Entry points for backends to add unwind information. */ -extern void cfi_new_fde (struct symbol *); +extern void cfi_new_fde (struct symbol *, bool); extern void cfi_end_fde (struct symbol *); extern void cfi_set_last_fde (struct fde_entry *fde); extern void cfi_set_return_column (unsigned); @@ -106,6 +106,9 @@ struct cfi_insn_data #if MULTIPLE_FRAME_SECTIONS segT cur_seg; #endif +#ifndef NO_LISTING + struct list_info_struct *listing_ctxt; +#endif int insn; union { @@ -193,6 +196,10 @@ struct fde_entry symbolS *end_address; struct cfi_insn_data *data; struct cfi_insn_data **last; +#ifndef NO_LISTING + struct list_info_struct *listing_ctxt; + struct list_info_struct *listing_end; +#endif unsigned char per_encoding; unsigned char lsda_encoding; int personality_id; --- a/gas/scfidw2gen.c +++ b/gas/scfidw2gen.c @@ -133,7 +133,7 @@ scfi_dot_cfi_startproc (const symbolS *s return; } - cfi_new_fde ((symbolS *)start_sym); + cfi_new_fde ((symbolS *)start_sym, false); cfi_set_sections (); --- a/gas/listing.c +++ b/gas/listing.c @@ -431,6 +431,51 @@ listing_newline (char *ps) #endif } +/* Set listing context back to where it was when input was parsed, to allow + associating late code/data emission to segments with their origin. */ + +struct list_info_struct *listing_override_tail (struct list_info_struct *info) +{ + struct list_info_struct *prev = listing_tail; + const fragS *frag; + + if (!info) + return NULL; + + listing_tail = info; + + /* The first frag created by listing_newline() is still associated with the + earlier line. For the adjustment done below this property doesn't hold, + though. */ + frag = info->frag; + if (frag->line != info) + frag = frag->fr_next; + + /* Check whether there's any other output data already for this line. Replace + info->frag only if there's none. This is to cover for contributions to + multiple sections from a single line not being properly represented in the + listing, at the time of writing. Prefer the listing to show any "ordinary" + code/data contributions over any .eh_frame ones. (This way multiple .cfi_* + on a single line will also have all their contributions listed, rather + than just those from the last such directive.) */ + for (; frag; frag = frag->fr_next) + if (frag->line != info + || (frag->fr_type != rs_dummy + && (frag->fr_type != rs_fill + || frag->fr_fix + || (frag->fr_var && frag->fr_offset)))) + break; + + if (!frag || frag->line != info) + { + new_frag (); + info->frag = frag_now; + new_frag (); + } + + return prev; +} + /* Attach all current frags to the previous line instead of the current line. This is called by the MIPS backend when it discovers that it needs to add some NOP instructions; the added NOP --- a/gas/listing.h +++ b/gas/listing.h @@ -47,6 +47,7 @@ void listing_error (const char *message) void listing_file (const char *name); void listing_list (int on); void listing_newline (char *ps); +struct list_info_struct *listing_override_tail (struct list_info_struct *); void listing_prev_line (void); void listing_print (char *, char **); void listing_psize (int); --- a/gas/testsuite/gas/cfi/cfi.exp +++ b/gas/testsuite/gas/cfi/cfi.exp @@ -116,6 +116,11 @@ if { [istarget "i*86-*-*"] || [istarget run_list_test "cfi-diag-1" "" +# ARC and HPPA use ';' as comment char rather than as statement separator. +if { ![istarget "arc*-*-*"] && ![istarget "hppa*-*"] } then { + run_list_test "listing" "-aln --listing-cont-lines=1" +} + # HPPA64 uses 64-bit relocations, which results in all of the dump # offset numbers not matching up. if { ![istarget "hppa64*-*"] } then { --- /dev/null +++ b/gas/testsuite/gas/cfi/listing.l @@ -0,0 +1,27 @@ +[ ]*[0-9]*[ ]+\.text +[ ]*[0-9]*[ ]+func: +[ ]*[0-9]*[ ]+0000 (1[04]00 ?0000|0000 ?001[04])[ ]+\.cfi_startproc +[ ]*[0-9]*[ ]+0000 ?0000 * +[ ]*[0-9]*[ ]+[0-9a-f]{4} 0A[ ]+\.cfi_remember_state +[ ]*[0-9]*[ ]+0000 .*[ ]\.nop +[ ]*[0-9]*[ ]+[0-9a-f]{4} 4.0A[ ]+\.cfi_escape 0x0a +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+[0-9a-f]{4} 4.02 ?0002[ ]+\.cfi_escape 0x02, 0x00, 0x02, 0x00 +[ ]*[0-9]*[ ]+00 +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+[0-9a-f]{4} 4.03 ?0000[ ]+\.cfi_escape 0x03; .cfi_escape 0x00, 0x00 +[ ]*[0-9]*[ ]+[0-9a-f]{4} 0400 ?0000[ ]+\.cfi_escape 0x04; .cfi_escape 0x00, 0x00, 0x00, 0x00 +[ ]*[0-9]*[ ]+00 +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+[0-9a-f]{4} 4.0B[ ]+\.cfi_escape 0x0b +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+[0-9a-f]{4} 4.0B[ ]+\.cfi_restore_state +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+([0-9a-f]{4} [0 ]+)?\.cfi_endproc +[ ]*[0-9]*[ ]* +[ ]*[0-9]*[ ]+func2: +[ ]*[0-9]*[ ]+[0-9a-f]{4} (1[048]00 ?0000|0000 ?001[048])[ ]+\.cfi_startproc +[ ]*[0-9]*[ ]+(4[048]00 ?0000|0000 ?004[048]) * +[ ]*[0-9]*[ ]+[0-9a-f]{4} .*[ ]\.nop +[ ]*[0-9]*[ ]+([0-9a-f]{4} [0 ]+)?\.cfi_endproc +#pass --- /dev/null +++ b/gas/testsuite/gas/cfi/listing.s @@ -0,0 +1,22 @@ + .text +func: + .cfi_startproc + .cfi_remember_state + .nop + .cfi_escape 0x0a + .nop + .cfi_escape 0x02, 0x00, 0x02, 0x00 + .nop + .cfi_escape 0x03; .cfi_escape 0x00, 0x00 + .cfi_escape 0x04; .cfi_escape 0x00, 0x00, 0x00, 0x00 + .nop + .cfi_escape 0x0b + .nop + .cfi_restore_state + .nop + .cfi_endproc + +func2: + .cfi_startproc + .nop + .cfi_endproc