From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 2FC54386192D for ; Wed, 27 Sep 2023 18:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2FC54386192D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=osandov.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=osandov.com Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c1ff5b741cso106072165ad.2 for ; Wed, 27 Sep 2023 11:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20230601.gappssmtp.com; s=20230601; t=1695838879; x=1696443679; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+CulrTyA7WNmu+8CDtxtGWhEllaLVylKPrXOTjjbe2U=; b=UH4eCJcJX+hVoHnYK2LTvTYBmloJNKJ6/RKoiMHSUXRY+CSUPbSsKhy1e+hPDu0Y3D j9MxOCYIxBS6rf3DOQt5c1l27Z9N8Rh2R0kKPVAZnpCG/ln41T9v4DE+S8tMETItVxbi M9iWxjOGOGyFixUeFaDAmjQIhmihDK8BeZ1rYwdTJwshRI46r9Rolr2cIEF4Q0sNu1GS fQ/UTUzttehG4EbUAZTyBNYtNskIBJ3SNOksJPCvSG3aHh3Rf+WFeY26vc2kdAVa7WyD smyEQy2F19hPtFqF41sAk7mhT1IcPJM6swASCa5sHZn8Z7L+umoSWTOzUueAaxjMJFel qrwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695838879; x=1696443679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+CulrTyA7WNmu+8CDtxtGWhEllaLVylKPrXOTjjbe2U=; b=LvtQn+XceJsmxhnrT4CvD6pNpB8JVDKTgCkLe8EZVdY5SSD+GoCwnEnIXGYOehfgUy 4l9dZd7HnWhCaymlcQ39ZieZYpcdq61UvYptU86/7CK0icMVbdnpzPSnENrL8yAudK7w Va9eVj9sg4/MgYjBAekRkrpqTalsNrSQi2+EIfou+pybm6Owywf7mUiXBRXjP/NscBrl qbqlNV3CBbIUgrL8WOER6x/6pQNrRnHC3av7FNQ0BUbY1glaAIuXAYurlogu28HRQ5h2 y4xPY3pvMbfDFe5dSG1hKQ242f5Dt+ZqL/O2TP5TYFnjAjw7pSYWsRf1RZ2LYb870A4b dy3Q== X-Gm-Message-State: AOJu0YwRNZPtBfpsS0EXIsMruOOsUtbni/Dp1z/XmjtGQCVfEQO9D6sj HywS24YKOmBFFWASTC3W+UjYKq/qP+co1MvQCYQ3Kg== X-Google-Smtp-Source: AGHT+IFAnFl2fvbt3ORw0uJ/dO2Br0FmZZsKTJuqQhN6UK78AzzZSsq5s1Bb2aWmODvrk39kp4NCWA== X-Received: by 2002:a17:902:d48f:b0:1bb:9b48:ea94 with SMTP id c15-20020a170902d48f00b001bb9b48ea94mr3076626plg.32.1695838878912; Wed, 27 Sep 2023 11:21:18 -0700 (PDT) Received: from telecaster.thefacebook.com ([2620:10d:c090:500::6:efab]) by smtp.gmail.com with ESMTPSA id u16-20020a170902e81000b001bf6ea340a9sm13397842plg.159.2023.09.27.11.21.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:21:18 -0700 (PDT) From: Omar Sandoval To: elfutils-devel@sourceware.org Subject: [PATCH 06/14] libdw: Handle split DWARF in dwarf_macro_getsrcfiles Date: Wed, 27 Sep 2023 11:20:55 -0700 Message-ID: <4d46a2bb0eba8e3aff5a33c045cd5a75342d596b.1695837512.git.osandov@fb.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,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 List-Id: From: Omar Sandoval Macro information references file names from the line number information table, which is tricky in split DWARF for a couple of reasons. First, the line number information for a macro unit comes from the .debug_line.dwo section in the split file, not the .debug_line section in the skeleton file. This was not specified in the GNU DebugFission design document [1] or the DWARF 5 standard, but it is how GCC and Clang behave in practice and was clarified in DWARF standard issue 200602.1 [2] for the upcoming DWARF 6 standard. dwarf_macro_getsrcfiles uses the line number information from whichever Dwarf handle it was passed. This is error-prone, since the most natural thing to do is to pass the skeleton Dwarf handle. Fix this by storing the appropriate Dwarf handle in Dwarf_Macro_Op_Table and using that one. Second, for .debug_macinfo.dwo in GNU DebugFission (generated by gcc -gdwarf-4 -gstrict-dwarf -gsplit-dwarf), the offset into .debug_line.dwo is implicitly 0. Again, this isn't in any specification, but it's how GCC behaves in practice (Clang never generates macro information for DWARF 4 split DWARF). Make get_macinfo_table default to 0 for split DWARF when it can't find DW_AT_stmt_list. 1: https://gcc.gnu.org/wiki/DebugFission 2: https://dwarfstd.org/issues/200602.1.html Signed-off-by: Omar Sandoval --- libdw/ChangeLog | 8 +++++--- libdw/dwarf_getmacros.c | 11 +++++++++-- libdw/dwarf_macro_getsrcfiles.c | 5 ++++- libdw/libdwP.h | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index d3f36cc8..be1e40bc 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -9,15 +9,17 @@ DW_FORM_strx, and DW_FORM_strx[1-4]. * dwarf_getmacros.c (get_macinfo_table): Replace assignment of table->is_64bit with assignments of table->address_size and - table->offset_size. + table->offset_size. Assume default DW_AT_stmt_list of 0 for split + DWARF. Set table->dbg. (get_table_for_offset): Ditto. (read_macros): Get fake CU offset_size from table->offset_size instead of table->is_64bit. * dwarf_macro_getsrcfiles.c (dwarf_macro_getsrcfiles): Get address_size for __libdw_getsrclines from table->address_size instead - of table->is_64bit. + of table->is_64bit. Get dbg for __libdw_getsrclines from table->dbg + instead of dbg parameter, which is now unused. * libdwP.h (Dwarf_Macro_Op_Table): Replace is_64bit with address_size - and offset_size. + and offset_size. Add dbg. 2023-02-22 Mark Wielaard diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c index b7d98af4..a3a78884 100644 --- a/libdw/dwarf_getmacros.c +++ b/libdw/dwarf_getmacros.c @@ -124,13 +124,19 @@ get_macinfo_table (Dwarf *dbg, Dwarf_Word macoff, Dwarf_Die *cudie) = INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list, &attr_mem); Dwarf_Off line_offset = (Dwarf_Off) -1; if (attr != NULL) - if (unlikely (INTUSE(dwarf_formudata) (attr, &line_offset) != 0)) - return NULL; + { + if (unlikely (INTUSE(dwarf_formudata) (attr, &line_offset) != 0)) + return NULL; + } + else if (cudie->cu->unit_type == DW_UT_split_compile + && dbg->sectiondata[IDX_debug_line] != NULL) + line_offset = 0; Dwarf_Macro_Op_Table *table = libdw_alloc (dbg, Dwarf_Macro_Op_Table, macinfo_data_size, 1); memcpy (table, macinfo_data, macinfo_data_size); + table->dbg = dbg; table->offset = macoff; table->sec_index = IDX_debug_macinfo; table->line_offset = line_offset; @@ -263,6 +269,7 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff, macop_table_size, 1); *table = (Dwarf_Macro_Op_Table) { + .dbg = dbg, .offset = macoff, .sec_index = IDX_debug_macro, .line_offset = line_offset, diff --git a/libdw/dwarf_macro_getsrcfiles.c b/libdw/dwarf_macro_getsrcfiles.c index 4e8deeeb..11c587af 100644 --- a/libdw/dwarf_macro_getsrcfiles.c +++ b/libdw/dwarf_macro_getsrcfiles.c @@ -36,6 +36,9 @@ int dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, Dwarf_Files **files, size_t *nfiles) { + /* This was needed before Dwarf_Macro_Op_Table stored the Dwarf handle. */ + (void)dbg; + /* macro is declared NN */ Dwarf_Macro_Op_Table *const table = macro->table; if (table->files == NULL) @@ -71,7 +74,7 @@ dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, the same unit through dwarf_getsrcfiles, and the file names will be broken. */ - if (__libdw_getsrclines (dbg, line_offset, table->comp_dir, + if (__libdw_getsrclines (table->dbg, line_offset, table->comp_dir, table->address_size, NULL, &table->files) < 0) table->files = (void *) -1; } diff --git a/libdw/libdwP.h b/libdw/libdwP.h index c3fe9f93..77959b3b 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -508,6 +508,8 @@ typedef struct /* Prototype table. */ typedef struct { + Dwarf *dbg; + /* Offset of .debug_macro section. */ Dwarf_Off offset; -- 2.41.0