[PATCH] FreeBSD: Stop linking _p libs for -pg as of FreeBSD 14

Andreas Tobler andreast.dev@gmail.com
Fri Aug 13 04:52:23 GMT 2021


Hi,

I would like to commit the attached patch to trunk and after a settling 
period also to all open branches.
Is this ok?

TIA,
Andreas

-------------- next part --------------
From a8a602620917efad2579c0dc24b178c0f2b18ff3 Mon Sep 17 00:00:00 2001
From: Andreas Tobler <andreast@gcc.gnu.org>
Date: Thu, 12 Aug 2021 22:35:52 +0200
Subject: [PATCH] FreeBSD: Stop linking _p libs for -pg as of FreeBSD 14

As of FreeBSD version 14, FreeBSD no longer provides profiled system
libraries like libc_p and libpthread_p. Stop linking against them if
the FreeBSD major version is 14 or more.

gcc/ChangeLog

	* config/freebsd-spec.h: Change the fbsd-lib-spec for FreeBSD > 13,
	do not link against profiled system libraries if -pg is invoked.
	Add a define to note about this change.
	* config/aarch64/aarch64-freebsd.h: Use the note to inform if -pg
	is invoked on FreeBSD > 13 that FreeBSD no longer provides profiled
	system libraries.
	* config/arm/freebsd.h: Likewise.
	* config/i386/freebsd.h: Likewise.
	* config/i386/freebsd64.h: Likewise.
	* config/riscv/freebsd.h: Likewise.
	* config/rs6000/freebsd64.h: Likewise.
	* config/rs6000/sysv4.h: Likeise.
---
 gcc/config/aarch64/aarch64-freebsd.h |  1 +
 gcc/config/arm/freebsd.h             |  1 +
 gcc/config/freebsd-spec.h            | 18 ++++++++++++++----
 gcc/config/i386/freebsd.h            |  1 +
 gcc/config/i386/freebsd64.h          |  1 +
 gcc/config/riscv/freebsd.h           |  1 +
 gcc/config/rs6000/freebsd64.h        |  1 +
 gcc/config/rs6000/sysv4.h            |  1 +
 8 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-freebsd.h b/gcc/config/aarch64/aarch64-freebsd.h
index e2dfe784030..cde74fa7aa5 100644
--- a/gcc/config/aarch64/aarch64-freebsd.h
+++ b/gcc/config/aarch64/aarch64-freebsd.h
@@ -35,6 +35,7 @@
 #undef  FBSD_TARGET_LINK_SPEC
 #define FBSD_TARGET_LINK_SPEC "                                 \
     %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}  \
+    " FBSD_LINK_PG_NOTE "					\
     %{v:-V}                                                     \
     %{assert*} %{R*} %{rpath*} %{defsym*}                       \
     %{shared:-Bshareable %{h*} %{soname*}}                      \
diff --git a/gcc/config/arm/freebsd.h b/gcc/config/arm/freebsd.h
index 8a970be0144..d82be28e263 100644
--- a/gcc/config/arm/freebsd.h
+++ b/gcc/config/arm/freebsd.h
@@ -47,6 +47,7 @@
 #undef	LINK_SPEC
 #define LINK_SPEC "							\
   %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}		\
+  " FBSD_LINK_PG_NOTE "							\
   %{v:-V}								\
   %{assert*} %{R*} %{rpath*} %{defsym*}					\
   %{shared:-Bshareable %{h*} %{soname*}}				\
diff --git a/gcc/config/freebsd-spec.h b/gcc/config/freebsd-spec.h
index 2b492617a0d..3a66e9a0a15 100644
--- a/gcc/config/freebsd-spec.h
+++ b/gcc/config/freebsd-spec.h
@@ -92,19 +92,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    libc, depending on whether we're doing profiling or need threads support.
    (similar to the default, except no -lg, and no -p).  */
 
+#if FBSD_MAJOR < 14
+#define FBSD_LINK_PG_NOTHREADS	"%{!pg: -lc}  %{pg: -lc_p}"
+#define FBSD_LINK_PG_THREADS	"%{!pg: %{pthread:-lpthread} -lc} " 	\
+				"%{pg: %{pthread:-lpthread} -lc_p}"
+#define FBSD_LINK_PG_NOTE ""
+#else
+#define FBSD_LINK_PG_NOTHREADS "%{-lc} "
+#define FBSD_LINK_PG_THREADS   "%{pthread:-lpthread} -lc "
+#define FBSD_LINK_PG_NOTE "%{pg:%nFreeBSD no longer provides profiled "\
+			  "system libraries}"
+#endif
+
 #ifdef FBSD_NO_THREADS
 #define FBSD_LIB_SPEC "							\
   %{pthread: %eThe -pthread option is only supported on FreeBSD when gcc \
 is built with the --enable-threads configure-time option.}		\
   %{!shared:								\
-    %{!pg: -lc}								\
-    %{pg:  -lc_p}							\
+    " FBSD_LINK_PG_NOTHREADS "						\
   }"
 #else
 #define FBSD_LIB_SPEC "							\
   %{!shared:								\
-    %{!pg: %{pthread:-lpthread} -lc}					\
-    %{pg:  %{pthread:-lpthread_p} -lc_p}				\
+    " FBSD_LINK_PG_THREADS "						\
   }									\
   %{shared:								\
     %{pthread:-lpthread} -lc						\
diff --git a/gcc/config/i386/freebsd.h b/gcc/config/i386/freebsd.h
index 00df79a7f57..dae3a0cd39c 100644
--- a/gcc/config/i386/freebsd.h
+++ b/gcc/config/i386/freebsd.h
@@ -80,6 +80,7 @@ along with GCC; see the file COPYING3.  If not see
 #undef	LINK_SPEC
 #define LINK_SPEC "\
   %{p:%nconsider using '-pg' instead of '-p' with gprof(1)} \
+  " FBSD_LINK_PG_NOTE " \
   %{v:-V} \
   %{assert*} %{R*} %{rpath*} %{defsym*} \
   %{shared:-Bshareable %{h*} %{soname*}} \
diff --git a/gcc/config/i386/freebsd64.h b/gcc/config/i386/freebsd64.h
index b69b8a5cea4..e4907f9758f 100644
--- a/gcc/config/i386/freebsd64.h
+++ b/gcc/config/i386/freebsd64.h
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
   %{m32:-m elf_i386_fbsd}%{!m32:-m elf_x86_64_fbsd} \
   %{p:%nconsider using '-pg' instead of '-p' with gprof(1)} \
+  " FBSD_LINK_PG_NOTE " \
   %{v:-V} \
   %{assert*} %{R*} %{rpath*} %{defsym*} \
   %{shared:-Bshareable %{h*} %{soname*}} \
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index 6018e7bb764..41c7ee367b5 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "						\
   -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv			\
   %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}	\
+  " FBSD_LINK_PG_NOTES "						\
   %{v:-V}							\
   %{assert*} %{R*} %{rpath*} %{defsym*}				\
   %{mbig-endian:-EB}						\
diff --git a/gcc/config/rs6000/freebsd64.h b/gcc/config/rs6000/freebsd64.h
index 7987983d787..b7368f3cde4 100644
--- a/gcc/config/rs6000/freebsd64.h
+++ b/gcc/config/rs6000/freebsd64.h
@@ -112,6 +112,7 @@ extern int dot_symbols;
 
 #define LINK_OS_FREEBSD_SPEC_DEF "\
   %{p:%nconsider using `-pg' instead of `-p' with gprof(1)} \
+  " FBSD_LINK_PG_NOTE " \
   %{v:-V} \
   %{assert*} %{R*} %{rpath*} %{defsym*} \
   %{shared:-Bshareable %{h*} %{soname*}} \
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index 23ff59403a3..977ff002ead 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -756,6 +756,7 @@ GNU_USER_TARGET_CC1_SPEC
 
 #define LINK_OS_FREEBSD_SPEC "\
   %{p:%nconsider using '-pg' instead of '-p' with gprof(1)} \
+  " FBSD_LINK_PG_NOTE " \
   %{v:-V} \
   %{assert*} %{R*} %{rpath*} %{defsym*} \
   %{shared:-Bshareable %{h*} %{soname*}} \
-- 
2.32.0



More information about the Gcc-patches mailing list