From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 570DC3861877 for ; Wed, 27 Sep 2023 18:21:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 570DC3861877 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-x62d.google.com with SMTP id d9443c01a7336-1c3bd829b86so94276005ad.0 for ; Wed, 27 Sep 2023 11:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20230601.gappssmtp.com; s=20230601; t=1695838878; x=1696443678; 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=Xn0pfAlU+hWxPIfinZ1//zNzCqx95KOWLj9zm1tqzKM=; b=CpYg1IC1KAOrPoEZ2RUhQ61P9aQPWUVdxeDlxunxzTB62Xip1JExIFmT6Gk3hTLht3 qZMPWaRE/mKdXKRoLtXfgdnKp6dU/KWTzhx7JaNRAT0CizWXkOL0/G8kGjyw85hgcifK PZcdD7+chyOYDNqrgvrc6sRgcIqvlyWIqviOx5SnOIKThDP8kOT0OmJruPg5xmqPci+A sBnOA8tpu4GA6jwaXHQl94NAXgG+x0TBHpOoR6soFbtD+fiUKAhwfOWzQb0K5Ptoemxo y338iSDeqgNW1W43ZIMcVwgvOrCtr1c2ZwSwqQ5Ska1tXKa0LT51T5kAv0pBBy5puKNm +6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695838878; x=1696443678; 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=Xn0pfAlU+hWxPIfinZ1//zNzCqx95KOWLj9zm1tqzKM=; b=ItLVtY1woXVMflIEsew7JXPAzkrZrd+fthjerhn961OTpmwosnh/3N+NaHV+76ye5R cm6ErpLDpiO4IkjpnyMEy4SRxZ19MxZPYR2Nj3AcueP7aVj3289VO6MvcoVFKIFQbJKm wjaHUHXZyZgIfHQyhv749Vr2qejAwrwkXmyt5BI1LeZWdqnC8bTNCc9R7Ca0D+RkPWbG ibBEwWrLAySpXUsEa3fEENLOB9KyNmPCuKMJauru/SI9DXPmmGxKllJntOcHlWQ9OvCh 1f8rxBpURhld/+45SJk2/z5iJX5DlmX24ADCk2+gUVwZrcPYdLSDXa3Fp+NXxBLREsZo gqNw== X-Gm-Message-State: AOJu0YyoomnBfso+EaYeSz9rt2MuppqLlgt4D706dcsqIoY5dubwq8tw OkiB6tczhsDJwpQT88Nvk3J1nF7KOeHz4fYN4Evb+A== X-Google-Smtp-Source: AGHT+IEUyALadBT6VvTK3HiBy3/e4Nl732iCENVc2L0ACFrmDdyReYT9LoQxBJ/dEOWMY3CP8t7/5w== X-Received: by 2002:a17:902:efcf:b0:1c3:749f:6a5c with SMTP id ja15-20020a170902efcf00b001c3749f6a5cmr2495493plb.12.1695838878086; 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.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:21:17 -0700 (PDT) From: Omar Sandoval To: elfutils-devel@sourceware.org Subject: [PATCH 05/14] libdw: Fix dwarf_macro_getsrcfiles for DWARF 5 Date: Wed, 27 Sep 2023 11:20:54 -0700 Message-ID: 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=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_NUMSUBJECT,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 Dwarf_Macro_Op_Table::is_64bit conflates the address size and the offset size: for .debug_macinfo, it is initialized based on the compilation unit's address size, but for .debug_macro, it is initialized based on the macro unit's offset size. is_64bit is used to determine the address size to pass to __libdw_getsrclines. For a 64-bit architecture using DWARF 5 with 32-bit offsets (the common case), this fails because read_srclines checks that the given address size matches the address size from the line number program header. Fix it by splitting is_64bit into separate address_size and offset_size members. Fixes: fb90bf3f84b5 ("Support .debug_macro") Signed-off-by: Omar Sandoval --- libdw/ChangeLog | 11 +++++++++++ libdw/dwarf_getmacros.c | 17 ++++++++++++++--- libdw/dwarf_macro_getsrcfiles.c | 3 +-- libdw/libdwP.h | 3 ++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 7528c093..d3f36cc8 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -7,6 +7,17 @@ * dwarf_macro_param2.c (dwarf_macro_param2): Change form condition to switch statement and add DW_FORM_line_strp, DW_FORM_strp_sup, 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. + (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. + * libdwP.h (Dwarf_Macro_Op_Table): Replace is_64bit with address_size + and offset_size. 2023-02-22 Mark Wielaard diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c index fd929669..b7d98af4 100644 --- a/libdw/dwarf_getmacros.c +++ b/libdw/dwarf_getmacros.c @@ -134,7 +134,8 @@ get_macinfo_table (Dwarf *dbg, Dwarf_Word macoff, Dwarf_Die *cudie) table->offset = macoff; table->sec_index = IDX_debug_macinfo; table->line_offset = line_offset; - table->is_64bit = cudie->cu->address_size == 8; + table->address_size = cudie->cu->address_size; + table->offset_size = cudie->cu->offset_size; table->comp_dir = __libdw_getcompdir (cudie); return table; @@ -182,6 +183,15 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff, return NULL; } + uint8_t address_size; + if (cudie != NULL) + address_size = cudie->cu->address_size; + else + { + char *ident = elf_getident (dbg->elf, NULL); + address_size = ident[EI_CLASS] == ELFCLASS32 ? 4 : 8; + } + /* """The macinfo entry types defined in this standard may, but might not, be described in the table""". @@ -258,7 +268,8 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff, .line_offset = line_offset, .header_len = readp - startp, .version = version, - .is_64bit = is_64bit, + .address_size = address_size, + .offset_size = is_64bit ? 8 : 4, /* NULL if CUDIE is NULL or DW_AT_comp_dir is absent. */ .comp_dir = __libdw_getcompdir (cudie), @@ -368,7 +379,7 @@ read_macros (Dwarf *dbg, int sec_index, .dbg = dbg, .sec_idx = sec_index, .version = table->version, - .offset_size = table->is_64bit ? 8 : 4, + .offset_size = table->offset_size, .str_off_base = str_offsets_base_off (dbg, (cudie != NULL ? cudie->cu: NULL)), .startp = (void *) startp + offset, diff --git a/libdw/dwarf_macro_getsrcfiles.c b/libdw/dwarf_macro_getsrcfiles.c index 3b1794b1..4e8deeeb 100644 --- a/libdw/dwarf_macro_getsrcfiles.c +++ b/libdw/dwarf_macro_getsrcfiles.c @@ -72,8 +72,7 @@ dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, will be broken. */ if (__libdw_getsrclines (dbg, line_offset, table->comp_dir, - table->is_64bit ? 8 : 4, - NULL, &table->files) < 0) + table->address_size, NULL, &table->files) < 0) table->files = (void *) -1; } diff --git a/libdw/libdwP.h b/libdw/libdwP.h index 5cbdc279..c3fe9f93 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -526,7 +526,8 @@ typedef struct Dwarf_Half header_len; uint16_t version; - bool is_64bit; + uint8_t address_size; + uint8_t offset_size; uint8_t sec_index; /* IDX_debug_macro or IDX_debug_macinfo. */ /* Shows where in TABLE each opcode is defined. Since opcode 0 is -- 2.41.0