From patchwork Mon Apr 12 15:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 42948 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 EC42F385781C; Mon, 12 Apr 2021 15:31:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC42F385781C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618241469; bh=TT9C13g1D/M19Oa0MzDY1J8Q1yxB5YD50W3m9BAN/D8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=YTq86Dli2j9+Z2GMBEdTgXHQVsK4tgqcH66YgdT197zhBRj0x+YytNaHRrpXXxyjt LI62l9PbkXnyt9oHOBrNjLYXuBhrx/EQkBv12zPEox+1AgymERke57L+J9TfwRynK7 M1SML5VQyfl8SsYN+go0KKrhC9mOLPGY3WF9gJ7Q= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id EFFB1385781C for ; Mon, 12 Apr 2021 15:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EFFB1385781C Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-iICpyQv-Ou-39JzZRksyXA-1; Mon, 12 Apr 2021 11:30:59 -0400 X-MC-Unique: iICpyQv-Ou-39JzZRksyXA-1 Received: by mail-wr1-f71.google.com with SMTP id p16so4765032wre.2 for ; Mon, 12 Apr 2021 08:30:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:organization:date:message-id :user-agent:mime-version; bh=TT9C13g1D/M19Oa0MzDY1J8Q1yxB5YD50W3m9BAN/D8=; b=AtUVMLzFm13kDESV05u+Z7k9uQpFfSUlRNobPURHAaELz+rmqm8m6nhYJgvtleKjgb WvgiQRcuWDwq2IJN3dp093/b9z1J3EHaMGVMkZ9UwhtwlN6Bq6HEp5IiiPy9VcZ6AgRH 0D6owarrSKIqpn8ZfxGiELPBdYklzB2IdN7Ye1tTL6nVoLopT/NVOpAOMlYzoDFbrQ6b 8G8CaeIfy9gNlW70d74IZjUCvwO8lK9qkxJE+dwlhKKnTo4HgkyL/9n6NmIx+ghTDpdQ QFkzU5XccrCx6lkGxfOcEnbI+sMJ8eeSoxBVZEcI+KsakPTTsA7fVAswmJEjQeymE52G nxQQ== X-Gm-Message-State: AOAM533l8NlkSG14AnaAs2oJPXie8OCwYMBMjP40G/spdhLDb3DvR8t1 9bOAH/ZrtkK/nQZnFQvY+nCf5ZAwjIDfYJpca1VVlmCIPGKscbVHWm6JYvfO+M5eS4/1c+wcJ8m 8KiRkVaSribFXqIUDZulKYYYdRkDBHRtkXM3UU+z1vxySaYG7999QIFG9XZM5bXYxGCen X-Received: by 2002:a1c:dc02:: with SMTP id t2mr27160937wmg.157.1618241458090; Mon, 12 Apr 2021 08:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiyoZbSi6VWF9SnfkDhtcpsy576yjfeRWqf5lqtPy7TJ/ledQKbLvwceC3wVxX0JQBKn/faA== X-Received: by 2002:a1c:dc02:: with SMTP id t2mr27160912wmg.157.1618241457769; Mon, 12 Apr 2021 08:30:57 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id r22sm15411196wmh.11.2021.04.12.08.30.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 08:30:56 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id F0C93580100; Mon, 12 Apr 2021 17:30:55 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH, applied] dwarf-reader: Canonicalize opaque enums and classes Organization: Red Hat / France X-Operating-System: Fedora 34 X-URL: http://www.redhat.com Date: Mon, 12 Apr 2021 17:30:55 +0200 Message-ID: <87wnt7tt8w.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Hello, This issue was reported in bug https://sourceware.org/bugzilla/show_bug.cgi?id=27700. When we construct an opaque type (triggered by the use of --drop-private-types along with the --headers-dir option on abidw, for instance) with get_opaque_version_of_type we forget to canonicalize the resulting type. Later, at abixml emitting time (for instance) nhash_as_canonical_type_or_constant would rightfully abort because the type wasn't canonicalized. We want all types (okay, modulo one exception) in the system to be canonicalized. This patch fixes the problem by canonicalizing opaque types. * src/abg-dwarf-reader.cc (build_ir_node_from_die): Canonicalize opaque enums and classes. * tests/data/test-read-dwarf/PR27700/include-dir/priv.h: New test header file. * tests/data/test-read-dwarf/PR27700/include-dir/pub.h: Likewise * tests/data/test-read-dwarf/PR27700/pub-incdir/inc.h: Likewise. * tests/data/test-read-dwarf/PR27700/test-PR27700.o: New binary input file. * tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Reference abi file of the binary above. * tests/data/test-read-dwarf/PR27700/test-PR27700.c: Source file of the binary above. * tests/data/Makefile.am: Add the test material above to source distribution. * tests/test-read-dwarf.cc (InOutSpec::in_public_headers_path): Add new data member. (in_out_specs): Adjust to reflect the new data member in the InOutSpec type. Add a new test input. (set_suppressions_from_headers): Define new static function. (test_task::perform): Use the content of the new InOutSpec::in_public_headers_path to construct and add "--headers-dir --drop-private-types" to the options of the abidw program run. Signed-off-by: Dodji Seketeli Applied to master. --- src/abg-dwarf-reader.cc | 34 +++--- tests/data/Makefile.am | 6 + .../PR27700/include-dir/priv.h | 7 ++ .../test-read-dwarf/PR27700/include-dir/pub.h | 0 .../test-read-dwarf/PR27700/pub-incdir/inc.h | 0 .../test-read-dwarf/PR27700/test-PR27700.abi | 17 +++ .../test-read-dwarf/PR27700/test-PR27700.c | 6 + .../test-read-dwarf/PR27700/test-PR27700.o | Bin 0 -> 3248 bytes tests/test-read-dwarf.cc | 107 +++++++++++++++++- 9 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 tests/data/test-read-dwarf/PR27700/include-dir/priv.h create mode 100644 tests/data/test-read-dwarf/PR27700/include-dir/pub.h create mode 100644 tests/data/test-read-dwarf/PR27700/pub-incdir/inc.h create mode 100644 tests/data/test-read-dwarf/PR27700/test-PR27700.abi create mode 100644 tests/data/test-read-dwarf/PR27700/test-PR27700.c create mode 100644 tests/data/test-read-dwarf/PR27700/test-PR27700.o diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 47d63a7a..604c76e3 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14807,13 +14807,16 @@ build_ir_node_from_die(read_context& ctxt, bool type_suppressed = type_is_suppressed(ctxt, scope, die, type_is_private); if (type_suppressed && type_is_private) - // The type is suppressed because it's private. If other - // non-suppressed and declaration-only instances of this - // type exist in the current corpus, then it means those - // non-suppressed instances are opaque versions of the - // suppressed private type. Lets return one of these opaque - // types then. - result = get_opaque_version_of_type(ctxt, scope, die, where_offset); + { + // The type is suppressed because it's private. If other + // non-suppressed and declaration-only instances of this + // type exist in the current corpus, then it means those + // non-suppressed instances are opaque versions of the + // suppressed private type. Lets return one of these opaque + // types then. + result = get_opaque_version_of_type(ctxt, scope, die, where_offset); + maybe_canonicalize_type(is_type(result), ctxt); + } else if (!type_suppressed) { enum_type_decl_sptr e = build_enum_type(ctxt, die, scope, @@ -14837,13 +14840,16 @@ build_ir_node_from_die(read_context& ctxt, type_is_suppressed(ctxt, scope, die, type_is_private); if (type_suppressed && type_is_private) - // The type is suppressed because it's private. If other - // non-suppressed and declaration-only instances of this - // type exist in the current corpus, then it means those - // non-suppressed instances are opaque versions of the - // suppressed private type. Lets return one of these opaque - // types then. - result = get_opaque_version_of_type(ctxt, scope, die, where_offset); + { + // The type is suppressed because it's private. If other + // non-suppressed and declaration-only instances of this + // type exist in the current corpus, then it means those + // non-suppressed instances are opaque versions of the + // suppressed private type. Lets return one of these opaque + // types then. + result = get_opaque_version_of_type(ctxt, scope, die, where_offset); + maybe_canonicalize_type(is_type(result), ctxt); + } else if (!type_suppressed) { Dwarf_Die spec_die; diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 53faec67..576309e8 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -556,6 +556,12 @@ test-read-dwarf/test-suppressed-alias.c \ test-read-dwarf/test-suppressed-alias.o \ test-read-dwarf/test-suppressed-alias.o.abi \ test-read-dwarf/test-suppressed-alias.suppr \ +test-read-dwarf/PR27700/include-dir/priv.h \ +test-read-dwarf/PR27700/include-dir/pub.h \ +test-read-dwarf/PR27700/pub-incdir/inc.h \ +test-read-dwarf/PR27700/test-PR27700.abi \ +test-read-dwarf/PR27700/test-PR27700.c \ +test-read-dwarf/PR27700/test-PR27700.o \ \ test-annotate/test0.abi \ test-annotate/test1.abi \ diff --git a/tests/data/test-read-dwarf/PR27700/include-dir/priv.h b/tests/data/test-read-dwarf/PR27700/include-dir/priv.h new file mode 100644 index 00000000..e76683d4 --- /dev/null +++ b/tests/data/test-read-dwarf/PR27700/include-dir/priv.h @@ -0,0 +1,7 @@ +enum foo +{ + foo_e0, + foo_e1, + foo_e2, + foo_e3 +}; diff --git a/tests/data/test-read-dwarf/PR27700/include-dir/pub.h b/tests/data/test-read-dwarf/PR27700/include-dir/pub.h new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/test-read-dwarf/PR27700/pub-incdir/inc.h b/tests/data/test-read-dwarf/PR27700/pub-incdir/inc.h new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/test-read-dwarf/PR27700/test-PR27700.abi b/tests/data/test-read-dwarf/PR27700/test-PR27700.abi new file mode 100644 index 00000000..5c49e369 --- /dev/null +++ b/tests/data/test-read-dwarf/PR27700/test-PR27700.abi @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/PR27700/test-PR27700.c b/tests/data/test-read-dwarf/PR27700/test-PR27700.c new file mode 100644 index 00000000..b44a3226 --- /dev/null +++ b/tests/data/test-read-dwarf/PR27700/test-PR27700.c @@ -0,0 +1,6 @@ +#include "include-dir/priv.h" + +void +foo(enum foo* c __attribute__((unused))) +{ +} diff --git a/tests/data/test-read-dwarf/PR27700/test-PR27700.o b/tests/data/test-read-dwarf/PR27700/test-PR27700.o new file mode 100644 index 0000000000000000000000000000000000000000..3f084d2132f0f43a683769ea91e9733fc599700a GIT binary patch literal 3248 zcmb_e&2Jl35TCbe$1dAAAFfJ6in1V}DZ*s*VTGc zLJ^`85>f>cL2!d365@u0#6N(zapR7-AaUhZi37~+&T}@e8x;Yg_|433X5P%3_py2Z zxfeDJAwZFUH8|1~3h-^=NN&Vp1I|Dh_O@>Qwsq^h+lO!b@Cm|s5Jj>YG~7=^nyi#! zc7{VJzc3?a3)A-km^on<*DTB0F0WWmSx;J`43K*WENjg&OSlwAJUwR? z6WfJ33TvFZF-Kk#c~FM!vT+WeFoj{;Xo1J507?yUA7Y6HRqPmG;br7`^u2^!2=QlW zk{GQKe<&;@lc8>)JY}MgB9RwxYV2|L1H;6a{b1yG1L@g*5W(h4d-i&L*{;`}np3lv zYD;zcvln;KVatu!P^n$CD}!i1kgHu8$k1=2>W1y!>cN%EmCKLYl`dfWoAOe^Y6+_+ zYzeBp;Xqcsq4%a=?fOx*@3-8R-*x?db!T^JdAU}rMsgI5s-7FUu~-SE>s7qB-LRuv zfLto<@3jA?N&TSR-}hw2^Fuv>mhW2VUw3){o9pW<_9Axf;y-8`@5UMC;>IqBgK05; zx==jCEj*7n{fOc-aJ4l3p|L(Wv4IW=oH^17$iW|fWf^gkvtTg!Wflnhco9fT_-f4SHZwZmw zgL_a;uUgGaIIT|UvnUf0PQMLOkj^G-jI#>&u|PXEzNjca$~euTY9Q!p3a7kH);Bf0 z!}^OFK4AS74S$vO*EO6~z+)eiUZ?5_)tP4>V$^3M-T%P^9`|97^+z=P3)X8I{x$1Q zX!!T6uW0y>tUt?Kug7MbdY|q;IHPw4k=sHZg$eH|DUt^fIP_A1(;AJy31#1PJlWds zHvOP8L|ZJotyU;#?o>vR+kT5D zmc3>tbO(|b@*mke##4{fzN+aOER639>*SlJ2T&nQe^H)KJEdej{sP+Qy#L$yI>zdA zQaY9YGg4Bd`_lKBUcE-jCl>i|+Z-^1Ao;1gi68lxR&mtlB*QPU6(D4;nC`oS1|1{c z9R}5XI4PdinN`2d8>-@|etNC-`aQ(5^50}oy&LEjlkQ9JQC9vP&VR^pl%L)&J^wYt zXiilpiZT7ni6R9sSNRox7xAq4O}^Ye-6j5`6XMH!AggzY|D5ABH+V)r(Cnb files; + suppression_sptr suppr = + abigail::tools_utils::gen_suppr_spec_from_headers(path, files); + + if (suppr) + { + suppr->set_drops_artifact_from_ir(true); + suppressions_type supprs; + supprs.push_back(suppr); + add_read_context_suppressions(read_ctxt, supprs); + } +} + /// The task that peforms the tests. struct test_task : public abigail::workers::task { @@ -477,7 +565,8 @@ struct test_task : public abigail::workers::task virtual void perform() { - string in_elf_path, in_abi_path, in_suppr_spec_path, out_abi_path; + string in_elf_path, in_abi_path, in_suppr_spec_path, in_public_headers_path, + out_abi_path; abigail::ir::environment_sptr env; in_elf_path = in_elf_base + spec.in_elf_path; @@ -486,6 +575,11 @@ struct test_task : public abigail::workers::task else in_suppr_spec_path.clear(); + if (spec.in_public_headers_path) + in_public_headers_path = spec.in_public_headers_path; + if (!in_public_headers_path.empty()) + in_public_headers_path = in_elf_base + spec.in_public_headers_path; + env.reset(new abigail::ir::environment); abigail::dwarf_reader::status status = abigail::dwarf_reader::STATUS_UNKNOWN; @@ -498,6 +592,9 @@ struct test_task : public abigail::workers::task if (!in_suppr_spec_path.empty()) set_suppressions(*ctxt, in_suppr_spec_path); + if (!in_public_headers_path.empty()) + set_suppressions_from_headers(*ctxt, in_public_headers_path); + abigail::corpus_sptr corp = read_corpus_from_elf(*ctxt, status); // if there is no output and no input, assume that we do not care about the // actual read result, just that it succeeded. @@ -541,7 +638,11 @@ struct test_task : public abigail::workers::task of.close(); string abidw = string(get_build_dir()) + "/tools/abidw"; - string cmd = abidw + " --abidiff " + in_elf_path; + string drop_private_types; + if (!in_public_headers_path.empty()) + drop_private_types += "--headers-dir " + in_public_headers_path + + " --drop-private-types"; + string cmd = abidw + " " + drop_private_types + " --abidiff " + in_elf_path; if (system(cmd.c_str())) { error_message = string("ABIs differ:\n")