From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id E8B583858D20 for ; Sun, 19 May 2024 21:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8B583858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8B583858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.83.234.184 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716152764; cv=none; b=qVUyf7MSw+0BQbAveKXCZU5Ic7Dsry56k5rDl2pwbC5JqBSH3PA+nm3+tHOIDM//x5q2tadN3d68aI7aStbxuYiktDyQDPEOK4Wo5Oz9e3pI8EfAI5YpwBlwaZYmShJ+h5JiVrF+pKCWOsRB0gZBEHR7o+kFiY0HY80FDnBsR1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716152764; c=relaxed/simple; bh=RVTGSmVXlXsaAvZENGnUH387nyPevb+a0wFgULzojXQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JF47liW3bhCDfWFbLYnb1q4IqW+Dh0o59JLwwn+sIqZYTomZq5QWNUqY0byjReoHb4EBx5qsobi4Q8p1Prct9PkijxsHjwCrC2QBFO4iPD2TuxVkUcSXjGtFcuqtFw0OLHkkUeIJre2y8EXKMY/n552GkaXiCTx8X9ojzZ6H/2Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mwielaar-thinkpadp1gen3.rmtnl.csb (deer0x03.wildebeest.org [172.31.17.133]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id DB6A83031F64; Sun, 19 May 2024 23:06:00 +0200 (CEST) Received: by mwielaar-thinkpadp1gen3.rmtnl.csb (Postfix, from userid 10916) id C6241815EB; Sun, 19 May 2024 23:06:00 +0200 (CEST) From: Mark Wielaard To: debugedit@sourceware.org Cc: Mark Wielaard Subject: [PATCH 2/2] debugedit: Handle DW_MACRO_{define,undef}_strx Date: Sun, 19 May 2024 23:05:47 +0200 Message-ID: <20240519210548.183878-2-mark@klomp.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240519210548.183878-1-mark@klomp.org> References: <20240519210548.183878-1-mark@klomp.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,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 List-Id: For DW_MACRO_{define,undef}_strx we need to record the string index of the macro. Since this is read through the .debug_str_offets we need to know the relevant str_offsets_base of the CU associated with the macro table. Add a macros_offs field to struct CU. Set this in when seeing a DW_AT_macros. And make sure relocations against .debug_macros are resolved when handling ET_REL files. Now all (macro) tests pass with CC=clang even when clang defaults to -gdwarf-5. The .debug_types tests are skipped because clang doesn't emit that section. Signed-off-by: Mark Wielaard --- tools/debugedit.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/debugedit.c b/tools/debugedit.c index 6f93fb702876..6bdb3f7f1d63 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -199,6 +199,8 @@ struct CU int cu_version; /* The offset into the .debug_str_offsets section for this CU. */ uint32_t str_offsets_base; + /* The offset into the .debug_macros section for this CU (DW_AT_macros). */ + uint32_t macros_offs; struct CU *next; }; @@ -615,13 +617,14 @@ setup_relbuf (DSO *dso, debug_section *sec) if (dso->shdr[i].sh_type == SHT_REL && sym.st_value == 0) continue; /* Only consider relocations against .debug_str, - .debug_str_offsets, .debug_line, .debug_line_str, and - .debug_abbrev. */ + .debug_str_offsets, .debug_line, .debug_line_str, + .debug_macro and .debug_abbrev. */ if (sym.st_shndx == 0 || (sym.st_shndx != debug_sections[DEBUG_STR].sec && sym.st_shndx != debug_sections[DEBUG_STR_OFFSETS].sec && sym.st_shndx != debug_sections[DEBUG_LINE].sec && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec + && sym.st_shndx != debug_sections[DEBUG_MACRO].sec && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec)) continue; rela.r_addend += sym.st_value; @@ -2338,6 +2341,9 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase, } } + if (t->attr[i].attr == DW_AT_macros) + cu->macros_offs = do_read_32_relocated (ptr, debug_sec); + /* DW_AT_comp_dir is the current working directory. */ if (t->attr[i].attr == DW_AT_comp_dir) { @@ -2778,6 +2784,20 @@ update_str_offsets (DSO *dso) } } +static struct CU * +find_macro_cu (DSO *dso, uint32_t macros_offs) +{ + struct CU *cu = dso->cus; + while (cu != NULL) + { + if (cu->macros_offs == macros_offs) + return cu; + cu = cu->next; + } + + return dso->cus; /* Not found, assume first CU. */ +} + static int edit_dwarf2 (DSO *dso) { @@ -3073,11 +3093,13 @@ edit_dwarf2 (DSO *dso) endsec = ptr + macro_sec->size; int op = 0, macro_version, macro_flags; int offset_len = 4, line_offset = 0; + struct CU *cu = NULL; while (ptr < endsec) { if (!op) { + cu = find_macro_cu (dso, ptr - macro_sec->data); macro_version = read_16 (ptr); macro_flags = read_8 (ptr); if (macro_version < 4 || macro_version > 5) @@ -3149,6 +3171,19 @@ edit_dwarf2 (DSO *dso) case DW_MACRO_GNU_transparent_include: ptr += offset_len; break; + case DW_MACRO_define_strx: + case DW_MACRO_undef_strx: + read_uleb128 (ptr); + if (phase == 0) + { + size_t idx; + idx = do_read_str_form_relocated (dso, DW_FORM_strx, + ptr, macro_sec, + cu); + record_existing_string_entry_idx (false, dso, idx); + } + read_uleb128 (ptr); + break; default: error (1, 0, "Unhandled DW_MACRO op 0x%x", op); break; -- 2.45.1