From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81795 invoked by alias); 27 Jul 2019 11:54:41 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 81777 invoked by uid 89); 27 Jul 2019 11:54:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-26.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Jul 2019 11:54:36 +0000 Received: from librem.wildebeest.org (host165-120-57-128.range165-120.btcentralplus.com [165.120.57.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id EECAD30D8305; Sat, 27 Jul 2019 13:54:33 +0200 (CEST) Received: by librem.wildebeest.org (Postfix, from userid 1000) id DBC81C0196; Sat, 27 Jul 2019 13:54:32 +0200 (CEST) Date: Sat, 27 Jul 2019 11:54:00 -0000 From: Mark Wielaard To: "Dmitry V. Levin" Cc: Florian Weimer , elfutils-devel@sourceware.org, Panu Matilainen Subject: Re: [PATCH] elfclassify tool Message-ID: <20190727115432.GA2881@wildebeest.org> References: <20190719134341.GA26346@altlinux.org> <84da918d32c57e6f16fbcf1c854b375111dbdcb5.camel@wildebeest.org> <20190719183542.GB29323@altlinux.org> <87v9vxivsu.fsf@oldenburg2.str.redhat.com> <20190719212308.GA31813@altlinux.org> <20190719213653.GA2851@wildebeest.org> <20190719225727.GA31985@altlinux.org> <20190720215116.GC2851@wildebeest.org> <20190726230448.GB14246@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190726230448.GB14246@altlinux.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2019-q3/txt/msg00082.txt.bz2 On Sat, Jul 27, 2019 at 02:04:48AM +0300, Dmitry V. Levin wrote: > On Sat, Jul 20, 2019 at 11:51:16PM +0200, Mark Wielaard wrote: > > On Sat, Jul 20, 2019 at 01:57:27AM +0300, Dmitry V. Levin wrote: > [...] > > > btw, I think it would be appropriate to move the has_dynamic check before > > > the first check in is_shared that returns true. > > > > Yes, that is probably fine, but does it really matter? > > It doesn't matter unless the file has DT_SONAME but doesn't have PT_DYNAMIC. > > If /lib64/ld-linux-x86-64.so.2 --verify doesn't like files without > PT_DYNAMIC, elfclassify --shared shouldn't classify them as DSOs, too. Yes, I see how theoretically that is "more correct". But if the file doesn't have PT_DYNAMIC then it cannot have a DT_SONAME. And there are no other checks that return true. So in practice there is no difference. Still, if it looks more correct, then lets just swap the checks. diff --git a/src/elfclassify.c b/src/elfclassify.c index 03655aea..0b1bb63a 100644 --- a/src/elfclassify.c +++ b/src/elfclassify.c @@ -498,6 +498,11 @@ is_shared (void) if (elf_type == ET_EXEC) return false; + /* If there is no dynamic section, the file cannot be loaded as a + shared object. */ + if (!has_dynamic) + return false; + /* If the object is marked as PIE, it is definitely an executable, and not a loadlable shared object. */ if (has_pie_flag) @@ -526,10 +531,6 @@ is_shared (void) if (has_dt_debug) return false; - /* If there is no dynamic section, the file cannot be loaded as a - shared object. */ - if (!has_dynamic) - return false; return true; } Thanks, Mark