From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C71D221A02910 for ; Thu, 25 May 2017 14:03:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3B84C057F91; Thu, 25 May 2017 21:02:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3B84C057F91 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lersek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E3B84C057F91 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-147.phx2.redhat.com [10.3.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4808617486; Thu, 25 May 2017 21:02:57 +0000 (UTC) To: Andrew Fish Cc: Ard Biesheuvel , Mike Kinney , Felix Poludov , "Fan, Jeff" , "edk2-devel@lists.01.org" , "Wu, Hao A" References: <1495581673-10788-1-git-send-email-michael.d.kinney@intel.com> <542CF652F8836A4AB8DBFAAD40ED192A4C5E94B8@shsmsx102.ccr.corp.intel.com> <56801ADE-446F-43C2-9C99-5500E8EE5881@apple.com> From: Laszlo Ersek Message-ID: Date: Thu, 25 May 2017 23:02:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <56801ADE-446F-43C2-9C99-5500E8EE5881@apple.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 25 May 2017 21:03:00 +0000 (UTC) Subject: Re: [Patch] SourceLevelDebugPkg/SecPeiDebugAgentLib: Fix duplicate symbol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 May 2017 21:03:01 -0000 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit On 05/25/17 22:37, Andrew Fish wrote: > >> On May 25, 2017, at 1:28 PM, Laszlo Ersek wrote: >> >> On 05/25/17 22:11, Ard Biesheuvel wrote: >>> On 25 May 2017 at 13:06, Kinney, Michael D wrote: >>>> Laszlo and Andrew, >>>> >>>> With the information that has been collected on this thread, I >>>> still think this patch in its original form is a good change >>>> to resolve the this one specific duplicate symbol issue for all >>>> tool chains. 'static' can not be mixed with >>>> GLOBAL_REMOVE_IF_UNREFERENCED for MSFT tool chains, so renaming >>>> the global variable is the easiest way to remove the duplicate. >>>> >>> >>> GLOBAL_REMOVE_IF_UNREFERENCED itself is problematic imo. I think it >>> was Felix who reported on this recently? >>> >>> STATIC is really the only sensible way to deal with this for symbols >>> that are only referenced by a single compilation unit. >>> >>>> I will continue to work on ways to detect duplicate symbols for >>>> all tool chains and will enter a Bugzilla issue to for that >>>> feature. >>>> >>>> In addition, the idea of detecting if a library is exporting more >>>> than the library class defines is another good feature to consider >>>> and I will enter a Bugzilla issue for that one as well. >>>> >>>> If we can find ways to both restrict the symbols exported by a >>>> library and strip all symbols that are unused, then we can have >>>> additional Bugzilla issues to perform that clean up on each >>>> library instance that is exporting more than the library class. >>>> >>> >>> A static library is nothing more than an archive containing a >>> collection of object files. Sadly, that implies that we cannot >>> distinguish between symbols that may only be referenced by other >>> objects in the same static library and symbols that are exported to >>> the library client. >> >> Do we know for a fact that, with /OPT:REF, VS does not strip unused >> *static* variables and functions? >> >> I mean, is it certain that *replacing* GLOBAL_REMOVE_IF_UNREFERENCED >> with STATIC in this case would lead to a size increase? >> >> If that's the case, then I'm fine if we go ahead with this patch, I'd >> just like to request that Mike please file some of those BZs, and please >> reference them from the commit message (as the longer term solution), >> before committing the patch. >> > > Clang will warn if you have unused static variables when warnings are cranked up. > > ~/work/Compiler>cat static.c > static unsigned char gTest[] = { 42 }; > > static int test () > { > return 1; > } > > int main () > { > return 0; > } > ~/work/Compiler>clang -Os static.c -Wall > static.c:1:22: warning: unused variable 'gTest' [-Wunused-variable] > static unsigned char gTest[] = { 42 }; > ^ > static.c:3:12: warning: unused function 'test' [-Wunused-function] > static int test () > ^ > 2 warnings generated. Sorry, my question was imprecise. Assume there is a public library function ("external linkage") that calls a static function in the same library instance and uses a static variable in the same library instance. Then this library instance is linked into a driver, but the driver never actually calls the extern function -- so the static variable and the static function too become useless. In this case, will /OPT:REF remove the static variable and the static function too? It seems counter-intuitive to me that an internal-only function or an internal-only variable has to be declared extern (via GLOBAL_REMOVE_IF_UNREFERENCED) just so it can be eliminated at link time, if it is never referenced (transitively). Thanks Laszlo