From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21725 invoked by alias); 5 Feb 2020 02:43:00 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 21705 invoked by uid 89); 5 Feb 2020 02:42:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_05,SPF_HELO_PASS,SPF_PASS autolearn=unavailable version=3.3.1 spammy=gcc-nm, gccnm, nms, School X-HELO: mengyan1223.wang Received: from mengyan1223.wang (HELO mengyan1223.wang) (89.208.246.23) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 02:42:57 +0000 Received: from xry111-X57S1 (unknown [183.202.3.165]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 4FF5A66212; Tue, 4 Feb 2020 21:42:54 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mengyan1223.wang; s=mail; t=1580870575; bh=p6+KPw+Cq61QY8tHnB5/orMRv0nxUQjZoffreD03DyA=; h=Subject:From:Reply-To:To:Cc:Date:In-Reply-To:References:From; b=G34bwmPLlaZUmR5l9PlSiBHjGjAxTG08+y9uTo6cYlYdpKrrq8JhdeXTFbz/EE+lw iXZQg75ONDizwLCMKL5PYQbhCo9oydX/FzxF3i22JQ6s/zT61uVtKnq7aOCHCMnTOf 6aDgZDZh+HAMq4n8N9Jo1OrzZlqheDPDWeIbAM0fUujHz5WHI9zgY+IJEp9iYEHeop 50fR8hnemwE7Nv8+L4LgOpH2bQrj6kjFmkkZmJBe9tGCFiqueYAOpUrO3eCwfUAUKp E1jMPVqBG7TUhsVw8xf8svfMZ4j2RFhLuekfO2OtFOrn27kBRyOHqrueL7Eid5jPce mKk2envodZfbQ== Message-ID: <6b009a19778dde9cb64b19ce6d38ee9f9cb0ea3b.camel@mengyan1223.wang> Subject: Re: gcc-nm behavior with -flto From: Xi Ruoyao Reply-To: gcc-help@gcc.gnu.org To: Arvind Sankar , gcc-help@gcc.gnu.org Cc: binutils@sourceware.org Date: Wed, 05 Feb 2020 02:43:00 -0000 In-Reply-To: <20200204205851.GA3873578@rani.riverdale.lan> References: <20200204205851.GA3873578@rani.riverdale.lan> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00035.txt.bz2 On 2020-02-04 15:58 -0500, Arvind Sankar wrote: > Hi, I get some odd symbol types when using gcc-nm on an lto file. > > Given the source file > void text(void) {} > int data = 1; > int bss = 0; > int common; > > gcc -c test.c && gcc-nm test.o: > 0000000000000000 B bss > 0000000000000004 C common > 0000000000000000 D data > 0000000000000000 T text > > gcc -flto -c test.c && gcc-nm test.o: > 00000000 T bss > 00000000 C common > 00000000 T data > 00000000 T text > > gcc -flto -fno-common -c test.c && gcc-nm test.o: > 00000000 T bss > 00000000 T common > 00000000 T data > 00000000 T text > > i.e. with LTO, .bss and .data symbols are shown as text symbols instead > by gcc-nm. This causes issues with configure scripts that use libtool > when the CFLAGS contain both -flto and -fno-common. There's a section in > the configure script that tries to figure out how to parse nm's output. > It compiles a source file that contains a common symbol and a function, > then parses nm output to create a second .c file with those > declarations, and tries to check that everything is working by linking > them together. In the -flto -fno-common case, the second file ends up > with both symbols turning into functions which then gives a link-time > error. I can't reproduce this. $ cat test1.c void text(void) {} int data = 1; int bss = 0; int common; $ cat test2.c #include extern void text(void); extern int data; extern int bss; extern int common; int main() { assert(bss == 0 && data == 1); return 0; } $ cc test1.c test2.c -flto -fno-common $ ./a.out $ Did you forgot the "extern" in test2.c for "int common;"? "int common;" is a tentative definition, equivalent to "int common = 0;", in ANSI C. "-fcommon" is a workaround enabled by default to resolve same tentative definitions in multiple files. With "-fno-common" there is no such a workaround so the linker will complain. -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University