From dan@dan.emsphone.com  Mon Aug  7 16:59:17 2006
Return-Path: <dan@dan.emsphone.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E691716A4DA
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  7 Aug 2006 16:59:17 +0000 (UTC)
	(envelope-from dan@dan.emsphone.com)
Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7AAE443D46
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  7 Aug 2006 16:59:17 +0000 (GMT)
	(envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.13.6/8.13.6) id k77GxGTA014220;
	Mon, 7 Aug 2006 11:59:16 -0500 (CDT)
	(envelope-from dan)
Message-Id: <200608071659.k77GxGTA014220@dan.emsphone.com>
Date: Mon, 7 Aug 2006 11:59:16 -0500 (CDT)
From: Dan Nelson <dnelson@allantgroup.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: -O2 optimizing out abi-tag note from executables
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         101590
>Category:       bin
>Synopsis:       [lib] [patch] -O2 optimizing out abi-tag note from executables
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 07 17:00:33 GMT 2006
>Closed-Date:    Fri Dec 07 20:01:56 UTC 2007
>Last-Modified:  Fri Dec 07 20:01:56 UTC 2007
>Originator:     Dan Nelson
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
The Allant Group
>Environment:
System: FreeBSD dan.emsphone.com 6.1-STABLE FreeBSD 6.1-STABLE #0: Sun Aug 6 16:39:49 CDT 2006 zsh@dan.emsphone.com:/usr/obj/usr/src-6/sys/DANSMP i386


	
>Description:
	

gcc's -O2 level removes unreferenced static variables from object
files, which results in the 'abitag' symbol in lib/csu/common/crtbrand.c
being optimized out of existence from /usr/lib/crt1.o .

>How-To-Repeat:
	

Compile any program on a FreeBSD 6.0 or newer system (the default
CFLAGS was switched from -O to -O2 here), and note that the 'file'
command doesn't list the version of FreeBSD it was compiled on.

$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), stripped

After patching and reinstalling crt1.o, and relinking ls:

$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), for FreeBSD 6.1 (601103), dynamically linked (uses shared libs), stripped


>Fix:

Mark abitag as __used instead of __unused, which will force gcc to
leave the symbol in the resulting object file even though it's static
and has no references.

Index: crtbrand.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/common/crtbrand.c,v
retrieving revision 1.4
diff -u -p -r1.4 crtbrand.c
--- crtbrand.c	17 Oct 2003 15:43:13 -0000	1.4
+++ crtbrand.c	7 Aug 2006 01:14:35 -0000
@@ -43,7 +43,7 @@ static const struct {
     int32_t	type;
     char	name[sizeof ABI_VENDOR];
     int32_t	desc;
-} abitag __attribute__ ((section (ABI_SECTION), aligned(4))) __unused = {
+} abitag __attribute__ ((section (ABI_SECTION), aligned(4))) __used = {
     sizeof ABI_VENDOR,
     sizeof(int32_t),
     ABI_NOTETYPE,


>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: Dan Nelson <dnelson@allantgroup.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject: Re: bin/101590: -O2 optimizing out abi-tag note from executables
Date: Tue, 8 Aug 2006 07:38:03 +1000 (EST)

 On Mon, 7 Aug 2006, Dan Nelson wrote:
 
 >> Fix:
 >
 > Mark abitag as __used instead of __unused, which will force gcc to
 > leave the symbol in the resulting object file even though it's static
 > and has no references.
 
 "__used" is misspelled "__unused" in several other places.  "__used" is new
 so it is rarely used.  "__unused" had to be used bogusly to prevent warnings
 about things that are used but which the compiler couldn't see are used,
 but now the correct spelling can be used.
 
 "__used" is now defined in <sys/cdefs.h>, but <sys/cdefs.h> doesn't
 actually use it.  E.g., <sys/cdefs.h still uses "__unused" for __IDSTRING(),
 but only in the non-__GNUC__ case which is broken anyway due to related
 bugs (some header files use __aligned(), but __aligned is intentionally
 left undefined to properly break the non-__GNUC__ case).  The usual case
 of __IDSTRING() (and thus __FBSDID()) apparently works because the usedness
 is hidden in an asm statement.
 
 crtbrand.c hard-codes the gccism __attribute((...__[un]used)) instead
 of using the macro __[un]used defined in <sys/cdefs.h>.  This is almost
 correct, since crtbrand.c needs to use more attributes than <sys/cdefs.h>
 can reasonably define.
 
 Bruce
State-Changed-From-To: open->closed 
State-Changed-By: kib 
State-Changed-When: Fri Dec 7 20:00:13 UTC 2007 
State-Changed-Why:  
Patched CURRENT-8/RELENG_7/RELENG_6/RELENG_6_3. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=101590 
>Unformatted:
