Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Apr 2011 16:03:11 +0200 (CEST)
From:      Gerald Pfeifer <gerald@pfeifer.com>
To:        freebsd-toolchain@freebsd.org
Subject:   x86_64 -profile option patch (fwd)
Message-ID:  <alpine.LNX.2.00.1104241602140.5419@gerinyyl.fvgr>

next in thread | raw e-mail | index | archive | help
Hi guys,

just wondering whether any of you has input/guidance on the mail
below regarding FreeBSD and profile handing in GCC?

Feel free to let Joseph know directly (cc:ing me), or I'll be
happy to relay back anything.

Gerald

---------- Forwarded message ----------
From: Joseph S. Myers <joseph@codesourcery.com>
To: gcc-patches@gcc.gnu.org
Cc: rth@redhat.com, jh@suse.cz, ubizjak@gmail.com, ljrittle@acm.org
Date: Tue, 15 Feb 2011 01:11:40 +0000 (UTC)
Subject: x86_64 -profile option patch

config/i386/x86-64.h defines CC1_SPEC to handle the -profile option.
This option (link with a profiling version of libc) is OS-specific so
should not be in such an OS-independent spec.

The affected targets (those using this definition) are: x86_64-*-elf*,
x86_64-*-freebsd*, x86_64-*-netbsd*, i[34567]86-*-linux*
--enable-targets=all, x86_64-*-linux* | x86_64-*-kfreebsd*-gnu |
x86_64-*-knetbsd*-gnu, i[34567]86-*-solaris2*.  Of these, only the
GNU-userspace targets and FreeBSD generally have any specs handling
-profile, and so only for those targets have I added it to .opt
files.  This patch removes the problem CC1_SPEC definition, adding
definitions to i386/freebsd64.h and i386/linux64.h to cover the subset
of affected targets where this definition is actually appropriate.

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Also
tested building cc1 and xgcc for crosses to: x86_64-elf
x86_64-freebsd8 x86_64-netbsd i686-pc-linux-gnu (--enable-targets=all)
x86_64-kfreebsd-gnu x86_64-knetbsd-gnu i686-solaris2.10.  OK to
commit?

A general note on profiling options and their effects:

There are three options for gprof-style function profiling (as opposed
to basic block profiling): -p (profiling with prof), -pg (profiling
with gprof), -profile (profiling with gprof, and link with a profiling
version of libc so that libc functions get profiled as well).  The
last option is undocumented and OS-specific (for GNU userspace and
FreeBSD targets).

The only option known to cc1 is -p; the differences between the three
options are only around linking except insofar as other specs
distinguish between them.  -pg is unconditionally mapped to -p for cc1
(gcc.c:cc1_options); -profile relies on CC1_SPEC for compile-time
effect (meaning that even for targets where it is nominally supported
there may well be inconsistency depending on what's in CC1_SPEC).
Many specs handle -p and -pg identically; I don't know what targets
relevant to current GCC actually have "prof" so that handling them
differently makes sense, but surely not most of them.

Whether -profile really makes sense for FreeBSD, or whether -profile
specs for FreeBSD should be removed, seems unclear.  I added it to
freebsd.opt on the basis of freebsd-spec.h:FBSD_STARTFILE_SPEC;
FBSD_LIB_SPEC doesn't handle it, but links with -lc_p unconditionally
for -pg.  I don't know what's in -lc_p on FreeBSD (whether it's just
profiling support code, or whether as with glibc it has profiling
enabled for all the libc functions).

cp/g++spec.c and go/gospec.c know about linking with different
versions of certain libraries (in particular libm) for profiling on
certain targets; for that driver code, profiling means -p or -pg and
-profile is unknown.

(I do not have specific recommendations for cleaning things up in this
area.)

2011-02-14  Joseph Myers  <joseph@codesourcery.com>

	* config/i386/freebsd64.h (CC1_SPEC): Define.
	* config/i386/linux64.h (CC1_SPEC): Define.
	* config/i386/x86-64.h (CC1_SPEC): Don't define.

Index: gcc/config/i386/x86-64.h
===================================================================
--- gcc/config/i386/x86-64.h	(revision 170150)
+++ gcc/config/i386/x86-64.h	(working copy)
@@ -1,5 +1,6 @@
 /* OS independent definitions for AMD x86-64.
-   Copyright (C) 2001, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2005, 2007, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Bo Thorsen <bo@suse.de>.
 
 This file is part of GCC.
@@ -48,9 +49,6 @@ see the files COPYING3 and COPYING.RUNTI
 #undef WCHAR_TYPE_SIZE
 #define WCHAR_TYPE_SIZE 32
 
-#undef CC1_SPEC
-#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
-
 #undef ASM_SPEC
 #define ASM_SPEC "%{m32:--32} %{m64:--64}"
 
Index: gcc/config/i386/freebsd64.h
===================================================================
--- gcc/config/i386/freebsd64.h	(revision 170150)
+++ gcc/config/i386/freebsd64.h	(working copy)
@@ -1,5 +1,5 @@
 /* Definitions for AMD x86-64 running FreeBSD with ELF format
-   Copyright (C) 2002, 2004, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2007, 2010, 2011 Free Software Foundation, Inc.
    Contributed by David O'Brien <obrien@FreeBSD.org>
 
 This file is part of GCC.
@@ -25,6 +25,9 @@ along with GCC; see the file COPYING3.  
 #define SUBTARGET_EXTRA_SPECS \
   { "fbsd_dynamic_linker", FBSD_DYNAMIC_LINKER }
 
+#undef CC1_SPEC
+#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
+
 /* Provide a LINK_SPEC appropriate for the FreeBSD/x86-64 ELF target.
    This is a copy of LINK_SPEC from <i386/freebsd.h> tweaked for
    the x86-64 target.  */
Index: gcc/config/i386/linux64.h
===================================================================
--- gcc/config/i386/linux64.h	(revision 170150)
+++ gcc/config/i386/linux64.h	(working copy)
@@ -1,5 +1,5 @@
 /* Definitions for AMD x86-64 running Linux-based GNU systems with ELF format.
-   Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Jan Hubicka <jh@suse.cz>, based on linux.h.
 
@@ -40,6 +40,9 @@ see the files COPYING3 and COPYING.RUNTI
 #undef CPP_SPEC
 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
 
+#undef CC1_SPEC
+#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
+
 /* The svr4 ABI for the i386 says that records and unions are returned
    in memory.  In the 64bit compilation we will turn this flag off in
    ix86_option_override_internal, as we never do pcc_struct_return

-- 
Joseph S. Myers
joseph@codesourcery.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.LNX.2.00.1104241602140.5419>