From patchwork Thu Jan 13 08:56:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 49950 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 A4088388A019 for ; Thu, 13 Jan 2022 08:57:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4088388A019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642064225; bh=JI5J0XXxayGS0zx9hDGseCjj9HYRVE2pYmj5a18mTPo=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=oxikx7SLsgjI4jZP2+mIGqwHtEvuaFsM+eS7IXJdVSjXpj/DGLdglU98zd0Sax+ml Q8gK0k3tT69oycnk5n7f52xdJcn57JbQ6CHlW/gISet5jakmCNhHWLuL8D80kxDskX 0fP3pQHJDwN4yIDxm0d8BhPiX4tNgfj5sJrBkIpM= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by sourceware.org (Postfix) with ESMTPS id 7E7313858D39 for ; Thu, 13 Jan 2022 08:56:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7E7313858D39 Received: by mail-ed1-x549.google.com with SMTP id x19-20020a05640226d300b003f8b80f5729so4694107edd.13 for ; Thu, 13 Jan 2022 00:56:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=JI5J0XXxayGS0zx9hDGseCjj9HYRVE2pYmj5a18mTPo=; b=kGQ9IAfkK39epnp/0aWAcnKcuOO+QO6o7UQv68zS68rWBx+hmJnu0WtAsbQvAaBGW8 GgEXHC9DDKpLRlGWc02t/v5N20ceNBDWRJ9T40pXGkly7HfYt5cDMfZU3sc0G59s1Ona NQH8omTVnDiFDvBBu1EqE4p2iQzZHf0rtdaN29+bMpvdEcYw2mqUuSreEIu9buqnH3hs Vq+VD+VBzuCe6UAUbx2RQjMCGaQWEGCVVfNrZu+tWgU0EbgjmXoEwgmyzGplKGz/PWoz 5yDgmFQekwkxoMzr6rJEmFQMwj/gO/h0tzglmu93oa/0DX9UAdu4IGPSsW9VcZzS5pOC 7m0A== X-Gm-Message-State: AOAM530wpQiCE80btmPluWBdQ/5HE7Vev/rWpg1YwayBwcjdjiP5S7UQ qdO94uOXTBKsxuLo/nhXzmuhPMg0GfLHkZHdY1CVZQYxuoAyka9/DRHuyo2mbs1AVPBO0xF4Isq c9Dmr0Xcmp3ZQtzBd+ebuKGZgNA0u1Lularf/wBSyoHyRPA0H0RxjBQIzfpWykNDMGHAH274= X-Google-Smtp-Source: ABdhPJyrdt+z/nhnMubdzRaspVSbmpk9KpYmPITXqXteclFjnCmCRl7tBWZMm1D+rnsiBWZGGaUpUSkcwTS5hg== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:1f99:5778:eb1:74fa]) (user=gprocida job=sendgmr) by 2002:a17:906:9743:: with SMTP id o3mr2786311ejy.162.1642064217335; Thu, 13 Jan 2022 00:56:57 -0800 (PST) Date: Thu, 13 Jan 2022 08:56:48 +0000 In-Reply-To: <20211119150138.2930800-1-gprocida@google.com> Message-Id: <20220113085648.3581287-1-gprocida@google.com> Mime-Version: 1.0 References: <20211119150138.2930800-1-gprocida@google.com> X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog Subject: [PATCH v4] Bug 28191 - Interpret DWARF 5 addrx locations To: libabigail@sourceware.org X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" This change uses libdw facilities to interpret location expressions instead of using libabigail's own mini-interpreter. With the fix for elfutils https://sourceware.org/bugzilla/show_bug.cgi?id=28220 in elfutils-0.186, abidw will correctly interpret Clang DWARF 5 symbol addresses. Without that fix many declarations will not be linked to their corresponding symbols due to the incorrect interpretation of location attribute data. * src/abg-dwarf-reader.cc (die_location_address): Use dwarf_attr_integrate, dwarf_getlocation and dwarf_getlocation_attr to decode addreses, instead of die_location_expr and eval_last_constant_dwarf_sub_expr. * tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi: Refresh test reference output; two more symbols have types. Signed-off-by: Giuliano Procida --- src/abg-dwarf-reader.cc | 23 +++-- .../PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi | 86 +++++++++++-------- 2 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 3f716944..7693a023 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -8858,18 +8858,31 @@ die_location_address(Dwarf_Die* die, uint64_t expr_len = 0; is_tls_address = false; - if (!die_location_expr(die, DW_AT_location, &expr, &expr_len)) + + if (!die) + return false; + + Dwarf_Attribute attr; + if (!dwarf_attr_integrate(const_cast(die), DW_AT_location, &attr)) return false; - int64_t addr = 0; - if (!eval_last_constant_dwarf_sub_expr(expr, expr_len, addr, is_tls_address)) + if (dwarf_getlocation(&attr, &expr, &expr_len)) + return false; + // Ignore location expressions where reading them succeeded but + // their length is 0. + if (expr_len == 0) return false; - address = addr; + Dwarf_Attribute result; + if (!dwarf_getlocation_attr(&attr, expr, &result)) + // A location that has been interpreted as an address. + return !dwarf_formaddr(&result, &address); + + // Just get the address out of the number field. + address = expr->number; return true; } - /// Return the index of a function in its virtual table. That is, /// return the value of the DW_AT_vtable_elem_location attribute. /// diff --git a/tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi b/tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi index 4a84fe97..91542872 100644 --- a/tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi +++ b/tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi @@ -639,6 +639,14 @@ + + + + + + + + @@ -665,6 +673,7 @@ + @@ -673,6 +682,7 @@ + @@ -727,11 +737,11 @@ - - + + - + @@ -739,7 +749,7 @@ - + @@ -768,63 +778,63 @@ - + - - - + + + - + - + - + - + - + - + - + - + - + - + - + @@ -834,7 +844,7 @@ - + @@ -944,8 +954,8 @@ - - + + @@ -974,13 +984,13 @@ - + - + @@ -994,10 +1004,10 @@ - - + + - + @@ -1030,9 +1040,9 @@ - - - + + + @@ -1045,11 +1055,11 @@ - + - + @@ -1068,11 +1078,15 @@ - - + + + + + + - - + +