From patchwork Thu Jul 20 16:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 73007 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 ADA1D385C8B0 for ; Thu, 20 Jul 2023 16:11:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADA1D385C8B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689869471; bh=Qp196USLnAy4LTAkpGzxnXfWsR6U5xBzW1Ke9Zcywm4=; h=Date:In-Reply-To:References:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Help:List-Subscribe:From: Reply-To:From; b=TTN9yedjws+L+TsRYHmLpua37hfshI7abf4pWnX5odOL22nE0PfrppgMWQaWbwahU xkpTUdqutvsFdtjGin26Diiw+g/7Kp/XvsQaL5GS7/KMJDeb4Ln2hfcA4XDuGvNXac v0nxThKsBWe573ubMKtP8RnEOpfbkRdBn4iyqX6s= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by sourceware.org (Postfix) with ESMTPS id 1512E385702B for ; Thu, 20 Jul 2023 16:11:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1512E385702B Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5834d9ec5f7so33077797b3.1 for ; Thu, 20 Jul 2023 09:11:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689869465; x=1690474265; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qp196USLnAy4LTAkpGzxnXfWsR6U5xBzW1Ke9Zcywm4=; b=Z6aweboCrlGC5KWQ5/J9JcqL9RhMPYTbUKSu23W64R2/3egwc5jiZH/8qcugkjpoGi FAhQ7YNNsoVeXSgZCp22UxP9kDf0Wwobf7J8/EoN9tTy95c09HQ0gVi64ETj5+zhXIMF Fs+P6GQiTQggvjIMJE4IqsCgg3cnHC++OnbF42xQDNCyTjHSX+PbGFWQ+oD9XBpE4MpD NdQAp/dbDtrKIH3w8ooxj6eulbMZZn7u6EhTQDsnb+ldaqhaNtdD4F1rdYSj+6tRfkep xOiQF2PtdxJDhuQLe+EOTqcU3NR3mTJQptJ3Kau4gBgCT40LdjXkCtOcP/lxhRrqX4l2 DS9A== X-Gm-Message-State: ABy/qLaYz2fyrBYpFcoBYSrntLG2oq2ZtAvgW99hZk0nFXOCTuyHs+sk q7ZaoVJynMEm4l5ZXIVUhw3OOYyyNG2diA== X-Google-Smtp-Source: APBJJlEiVEmuesw68z+x28qFD4ReuJRNuf+WB6wQmhi/bG4Ofb/elfxoE7pV67Grv8RRZAJJig+fwLf/UqbQFQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:209:c4c4:9486:83f9:4510]) (user=gprocida job=sendgmr) by 2002:a5b:349:0:b0:ceb:324c:ba8e with SMTP id q9-20020a5b0349000000b00ceb324cba8emr77473ybp.4.1689869465517; Thu, 20 Jul 2023 09:11:05 -0700 (PDT) Date: Thu, 20 Jul 2023 17:10:53 +0100 In-Reply-To: <20230407203456.27141-2-quic_johmoo@quicinc.com> Mime-Version: 1.0 References: <20230407203456.27141-2-quic_johmoo@quicinc.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230720161053.1213680-1-gprocida@google.com> Subject: [PATCH] scripts/check-uapi.sh: add stgdiff support To: quic_johmoo@quicinc.com Cc: masahiroy@kernel.org, nathan@kernel.org, ndesaulniers@google.com, nicolas@fjasle.eu, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, gregkh@linuxfoundation.org, rdunlap@infradead.org, arnd@arndb.de, andersson@kernel.org, tkjos@google.com, maennich@google.com, gprocida@google.com, kernel-team@android.com, libabigail@sourceware.org, jorcrous@amazon.com, quic_tsoni@quicinc.com, quic_satyap@quicinc.com, quic_eberman@quicinc.com, quic_gurus@quicinc.com X-Spam-Status: No, score=-21.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, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hi John. I spent a few minutes adding stgdiff support to the script. It's really just for illustration purposes. As I think you know, STG doesn't yet exist as a project outside of AOSP. Nevertheless, this may be useful to you as-is. STG has quite a different philosophy to libabigil in terms of filtering out certain kinds of differences. Some of the things (like enum enumerator additions) are not considered harmless. The reasoning behind this is basically... https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) However, it does have --ignore interface_addition (and the related --ignore type_definition_addition) which can be used to detect whether one ABI is a subset of another. I am looking at adding support for macro definitions (gcc -g3) to STG which will then let us cover significantly more of the UAPI surface. Unfortunately, there are some headers which use anonymous enums to define constants (e.g. and ironically BTF). ABI tracking these types would require something a bit hacky. Or we could just name them. Regards, Giuliano. Signed-off-by: Giuliano Procida --- scripts/check-uapi.sh | 102 ++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/scripts/check-uapi.sh b/scripts/check-uapi.sh index 755187f27be5..982666b48f3b 100755 --- a/scripts/check-uapi.sh +++ b/scripts/check-uapi.sh @@ -32,6 +32,7 @@ Options: -v Verbose operation (print more information about each header being checked). Environmental args: + STGDIFF Custom path to stgdiff binary - use stgdiff instead of abidiff ABIDIFF Custom path to abidiff binary CC C compiler (default is "gcc") ARCH Target architecture of C compiler (default is host arch) @@ -270,43 +271,78 @@ compare_abi() { exit "$FAIL_COMPILE" fi - local ret=0 - "$ABIDIFF" --non-reachable-types "${past_header}.bin" "${base_header}.bin" > "$log" || ret="$?" - if [ "$ret" -eq 0 ]; then - if [ "$VERBOSE" = "true" ]; then - printf "No ABI differences detected in %s from %s -> %s\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + if [ "$STGDIFF" ]; then + local ret=0 + "$STGDIFF" --types --ignore interface_addition --elf "${past_header}.bin" "${base_header}.bin" --format small --output "$log" || ret="$?" + if [ "$ret" -eq 0 ]; then + if [ "$VERBOSE" = "true" ]; then + printf "No ABI differences detected in %s from %s -> %s\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + fi + else + # stgdiff's return code can be used to determine the type of error + if [ $((ret & 0x1)) -gt 0 ]; then + eprintf "error - stgdiff failed\n" + exit 1 + fi + + { + printf "!!! ABI differences detected in %s from %s -> %s !!!\n\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + sed -e 's/^/ /g' "$log" + + if ! cmp "$past_header" "$base_header" > /dev/null 2>&1; then + printf "\nHeader file diff (after headers_install):\n" + diff -Naur "$past_header" "$base_header" \ + | sed -e "s|${past_header}|${past_ref}/${file}|g" \ + -e "s|${base_header}|${base_ref:-dirty}/${file}|g" + printf "\n" + else + printf "\n%s did not change between %s and %s...\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + printf "It's possible a change to one of the headers it includes caused this error:\n" + grep '^#include' "$base_header" + printf "\n" + fi + } | tee "${base_header}.error" >&2 + return 1 fi else - # Bits in abidiff's return code can be used to determine the type of error - if [ $((ret & 0x1)) -gt 0 ]; then - eprintf "error - abidiff did not run properly\n" - exit 1 - fi + local ret=0 + "$ABIDIFF" --non-reachable-types "${past_header}.bin" "${base_header}.bin" > "$log" || ret="$?" + if [ "$ret" -eq 0 ]; then + if [ "$VERBOSE" = "true" ]; then + printf "No ABI differences detected in %s from %s -> %s\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + fi + else + # Bits in abidiff's return code can be used to determine the type of error + if [ $((ret & 0x1)) -gt 0 ]; then + eprintf "error - abidiff did not run properly\n" + exit 1 + fi - # If the only changes were additions (not modifications to existing APIs), then - # there's no problem. Ignore these diffs. - if grep "Unreachable types summary" "$log" | grep -q "0 removed" && - grep "Unreachable types summary" "$log" | grep -q "0 changed"; then - return 0 - fi - { - printf "!!! ABI differences detected in %s from %s -> %s !!!\n\n" "$file" "$past_ref" "${base_ref:-dirty tree}" - sed -e '/summary:/d' -e '/changed type/d' -e '/^$/d' -e 's/^/ /g' "$log" - - if ! cmp "$past_header" "$base_header" > /dev/null 2>&1; then - printf "\nHeader file diff (after headers_install):\n" - diff -Naur "$past_header" "$base_header" \ - | sed -e "s|${past_header}|${past_ref}/${file}|g" \ - -e "s|${base_header}|${base_ref:-dirty}/${file}|g" - printf "\n" - else - printf "\n%s did not change between %s and %s...\n" "$file" "$past_ref" "${base_ref:-dirty tree}" - printf "It's possible a change to one of the headers it includes caused this error:\n" - grep '^#include' "$base_header" - printf "\n" + # If the only changes were additions (not modifications to existing APIs), then + # there's no problem. Ignore these diffs. + if grep "Unreachable types summary" "$log" | grep -q "0 removed" && + grep "Unreachable types summary" "$log" | grep -q "0 changed"; then + return 0 fi - } | tee "${base_header}.error" >&2 - return 1 + { + printf "!!! ABI differences detected in %s from %s -> %s !!!\n\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + sed -e '/summary:/d' -e '/changed type/d' -e '/^$/d' -e 's/^/ /g' "$log" + + if ! cmp "$past_header" "$base_header" > /dev/null 2>&1; then + printf "\nHeader file diff (after headers_install):\n" + diff -Naur "$past_header" "$base_header" \ + | sed -e "s|${past_header}|${past_ref}/${file}|g" \ + -e "s|${base_header}|${base_ref:-dirty}/${file}|g" + printf "\n" + else + printf "\n%s did not change between %s and %s...\n" "$file" "$past_ref" "${base_ref:-dirty tree}" + printf "It's possible a change to one of the headers it includes caused this error:\n" + grep '^#include' "$base_header" + printf "\n" + fi + } | tee "${base_header}.error" >&2 + return 1 + fi fi }