From patchwork Fri Nov 19 15:01:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 47938 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 31CCD385AC2B for ; Fri, 19 Nov 2021 15:01:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31CCD385AC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637334113; bh=xyI16g/l44eef6YbQPvFVGoiDalH8XYda+kM+ta6qRc=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ixp3WJRHnETmD4K6jMUP5sjjM/VRm5xafbgap3uHKukVFT+pR1XgSe+m8JDpp2YUI bBXM0S38wdNl6/PwMUFl7Wrad5Otw7rcYSvvbDGbgnovQUCvVrLgTjxwgeHds8sjZf O21dW8ztAH9MC0E8QxxL27tjQqSj91WVZPn99np4= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by sourceware.org (Postfix) with ESMTPS id 145BB385800C for ; Fri, 19 Nov 2021 15:01:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 145BB385800C Received: by mail-wm1-x349.google.com with SMTP id ay34-20020a05600c1e2200b00337fd217772so4868363wmb.4 for ; Fri, 19 Nov 2021 07:01:45 -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=xyI16g/l44eef6YbQPvFVGoiDalH8XYda+kM+ta6qRc=; b=8ETmAOpFPR+/VTPcWz16jfW7FAoDJbu8WozFyBpCIqbPRhE8BISqQ2369CutrXH4j3 tChsWNwJ05EFLPXQlHQZ1s+HRwnR+dbrL2plyBRq+lciltfchUHe+OXe5Il4x87cy5by cIWqJA36Ho/TGh/P1K1meC5RQIKM+ahDfunAIxqGuWfL+U39eM7IP2p1NXXTVXDGfA/F AlxJ3RpbH4aY5vxCcxglCEshYju+cEunNI8Q1acLTJq5VCD5BH4D7BLmPXQFX/xuGq8P I0AiOgEZPpGRG/YHZ9SNSBxwwNQbhpOJRCVRQRAjsoAyX3KUBWEu9APXoUHY0Kuf8+M5 nIng== X-Gm-Message-State: AOAM533dcM/9YZEHRm8RO/431MevFypVhPTLl7+BY5LHbLeagKz4Y93L WdhZuIGX4cxIhIbS2NXHf2tNtjvKQ4ZYNcMyq7j1MQsJc20ur8k3WpLCQtHU9iFac6AIvLZmtiU zDGTAFNXJq+p7ri9vQLmBf/80vXyi9Gx608l3rwxleS7a+CwZ2dvaxsCvEBGSf5lJcnkNvs4= X-Google-Smtp-Source: ABdhPJxUQfa93nI0nZWSJc/IzLkJF7wCzGsQCEr5tgymSbUE//KPiUuyBTPpxL4l8wSellYIyZDpkKdr4UPAug== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:380c:1fb8:5156:8e58]) (user=gprocida job=sendgmr) by 2002:a5d:4e0b:: with SMTP id p11mr7968248wrt.88.1637334103888; Fri, 19 Nov 2021 07:01:43 -0800 (PST) Date: Fri, 19 Nov 2021 15:01:38 +0000 In-Reply-To: <20210827185755.953243-1-gprocida@google.com> Message-Id: <20211119150138.2930800-1-gprocida@google.com> Mime-Version: 1.0 References: <20210827185755.953243-1-gprocida@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3] Bug 28191 - Interpret DWARF 5 addrx locations To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 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 ec92f3f8..8ba7525b 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -8814,18 +8814,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 0e6e8af4..59e1e483 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 @@ - - + + + + + + - - + +