public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-11372] Darwin: Check as for .build_version support and use it if available.
@ 2024-04-25 19:24 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2024-04-25 19:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9702d54788021b1f48a2fd1fe9f13607d37f491f

commit r11-11372-g9702d54788021b1f48a2fd1fe9f13607d37f491f
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Tue Oct 17 11:10:27 2023 +0100

    Darwin: Check as for .build_version support and use it if available.
    
    This adds support for the minimum OS version data in assembler files.
    At present, we have no mechanism to detect the SDK version in use, and
    so that is omitted from build_versions.
    
    We follow the implementation in clang, '.build_version' is only emitted
    (where supported) for target macOS versions >= 10.14.  For earlier macOS
    we fall back to using a '.macosx_version_min' directive.  This latter is
    also emitted when the assembler supports it, but not build_version.
    
    gcc/ChangeLog:
    
            * config.in: Regenerate.
            * config/darwin.c (darwin_file_start): Add assembler directives
            for the target OS version, where these are supported by the
            assembler.
            (darwin_override_options): Check for building >= macOS 10.14.
            * configure: Regenerate.
            * configure.ac: Check for assembler support of .build_version
            directives.
    
    Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
    (cherry picked from commit a4184c8a65a00eaf8a8d7f92fb8ad2f8621b39e2)

Diff:
---
 gcc/config.in       |  6 ++++++
 gcc/config/darwin.c | 34 ++++++++++++++++++++++++++++++++--
 gcc/configure       | 49 +++++++++++++++++++++++++++++++++++++++++++------
 gcc/configure.ac    | 12 ++++++++++--
 4 files changed, 91 insertions(+), 10 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index 982c453ca36..6dd0ff010ce 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -598,6 +598,12 @@
 #endif
 
 
+/* Define if your macOS assembler supports .build_version directives */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_MACOS_BUILD_VERSION
+#endif
+
+
 /* Define if the assembler understands -march=rv*_zifencei. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_MARCH_ZIFENCEI
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index e01460a996f..0564e6f0218 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -3032,7 +3032,35 @@ darwin_asm_output_dwarf_offset (FILE *file, int size, const char * lab,
 void
 darwin_file_start (void)
 {
-  /* Nothing to do.  */
+#ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
+  /* This should not happen with a well-formed command line, but the user could
+     invoke cc1* directly without it.  */
+  if (!darwin_macosx_version_min)
+    return;
+  /* This assumes that the version passed has been validated in the driver.  */
+  unsigned maj, min, tiny;
+  int count = sscanf (darwin_macosx_version_min, "%u.%u.%u", &maj, &min, &tiny);
+  if (count < 0)
+    return;
+  if (count < 3)
+    tiny = 0;
+  if (count < 2)
+    min = 0;
+  const char *directive;
+#ifdef HAVE_AS_MACOS_BUILD_VERSION
+  /* We only handle macos, so far.  */
+  if (generating_for_darwin_version >= 18)
+    directive = "build_version macos, ";
+  else
+#endif
+    directive = "macosx_version_min ";
+  if (count > 2 && tiny != 0)
+    fprintf (asm_out_file, "\t.%s %u, %u, %u\n", directive, maj, min, tiny);
+  else if (count > 1)
+    fprintf (asm_out_file, "\t.%s %u, %u\n", directive, maj, min);
+  else
+     fprintf (asm_out_file, "\t.%s %u, 0\n", directive, maj);
+#endif
 }
 
 /* Called for the TARGET_ASM_FILE_END hook.
@@ -3254,7 +3282,9 @@ darwin_override_options (void)
   /* Keep track of which (major) version we're generating code for.  */
   if (darwin_macosx_version_min)
     {
-      if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
+      if (strverscmp (darwin_macosx_version_min, "10.14") >= 0)
+	generating_for_darwin_version = 18;
+      else if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
 	generating_for_darwin_version = 11;
       else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0)
 	generating_for_darwin_version = 10;
diff --git a/gcc/configure b/gcc/configure
index d2ad1628edd..86f44a35f42 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -26007,16 +26007,22 @@ if ${gcc_cv_as_mmacosx_version_min+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   gcc_cv_as_mmacosx_version_min=no
-  if test x$gcc_cv_as != x; then
-    $as_echo '.text' > conftest.s
-    if { ac_try='$gcc_cv_as $gcc_cv_as_flags -mmacosx-version-min=10.1 -o conftest.o conftest.s >&5'
+    if test $in_tree_gas = yes; then
+    if test $gcc_cv_gas_vers -ge `expr \( \( -mmacosx-version-min=10.1 \* 1000 \) + gcc_cv_as_mmacosx_version_min=yes \) \* 1000 + `
+  then :
+fi
+  elif test x$gcc_cv_as != x; then
+    $as_echo '' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags .text -o conftest.o conftest.s >&5'
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
   (eval $ac_try) 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
     then
-	gcc_cv_as_mmacosx_version_min=yes
+
+$as_echo "#define HAVE_AS_MMACOSX_VERSION_MIN_OPTION 1" >>confdefs.h
+
     else
       echo "configure: failed program was" >&5
       cat conftest.s >&5
@@ -26026,12 +26032,43 @@ else
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_mmacosx_version_min" >&5
 $as_echo "$gcc_cv_as_mmacosx_version_min" >&6; }
-if test $gcc_cv_as_mmacosx_version_min = yes; then
 
-$as_echo "#define HAVE_AS_MMACOSX_VERSION_MIN_OPTION 1" >>confdefs.h
 
+    if test x$gcc_cv_as_mmacosx_version_min = "xyes"; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .build_version" >&5
+$as_echo_n "checking assembler for .build_version... " >&6; }
+if ${gcc_cv_as_darwin_build_version+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_darwin_build_version=no
+    if test $in_tree_gas = yes; then
+    if test $gcc_cv_gas_vers -ge `expr \( \( -mmacosx-version-min=10.14 \* 1000 \) + gcc_cv_as_darwin_build_version=yes \) \* 1000 + `
+  then :
+fi
+  elif test x$gcc_cv_as != x; then
+    $as_echo '' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  .build_version macos, 10, 14 sdk_version 10, 14 -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+
+$as_echo "#define HAVE_AS_MACOS_BUILD_VERSION 1" >>confdefs.h
+
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_darwin_build_version" >&5
+$as_echo "$gcc_cv_as_darwin_build_version" >&6; }
 
+
+    fi
     ;;
 esac
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 7ea5c6fe51b..a4d5bdb1b8d 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -4358,10 +4358,18 @@ AC_MSG_RESULT($gcc_cv_lto_plugin)
 case "$target_os" in
   darwin*)
     gcc_GAS_CHECK_FEATURE([-mmacosx-version-min option],
-      gcc_cv_as_mmacosx_version_min,,
+      gcc_cv_as_mmacosx_version_min,
       [-mmacosx-version-min=10.1], [.text],,
       [AC_DEFINE(HAVE_AS_MMACOSX_VERSION_MIN_OPTION, 1,
-	[Define if your Mac OS X assembler supports the -mmacos-version-min option.])])
+	[Define if your macOS assembler supports the -mmacos-version-min option.])])
+    if test x$gcc_cv_as_mmacosx_version_min = "xyes"; then
+       gcc_GAS_CHECK_FEATURE([.build_version],
+           gcc_cv_as_darwin_build_version,
+           [-mmacosx-version-min=10.14],
+           [ .build_version macos, 10, 14 sdk_version 10, 14],,
+      [AC_DEFINE(HAVE_AS_MACOS_BUILD_VERSION, 1,
+	[Define if your macOS assembler supports .build_version directives])])
+    fi
     ;;
 esac

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-25 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 19:24 [gcc r11-11372] Darwin: Check as for .build_version support and use it if available Iain D Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).