On Apr 16, 2025, Alexandre Oliva <ol...@adacore.com> wrote:

> But I acknowledge that it's a bit of a risky proposition; I suppose it
> would be more conservative to disable it uniformly on all targets, and
> only enable it with -m32 when explicitly requested.  I.e., make
> OS_MISSING_POWERPC64 the rule rather than the exception, and define it
> to zero on targets where it is deemed safe.

After much pondering, I've decided to implement this change that flips
the default on powerpc-*-elf.  If it's acceptable, perhaps other powerpc
ports would like to adopt it as well.

Tested on x86_64-linux-gnu-x-powerpc-elf.  Ok to install?


Disable the implicit enabling of -mpowerpc64 upon
-mcpu=<ppc64-supporting>, instead of assuming the embedded operating
system can save and restore all 64 bits of registers, which has ABI
implications.  Compiling with -mpowerpc64 explicitly restores current
behavior, in case the operating system can indeed deal with this
unusual scenario.


for  gcc/ChangeLog

        * config/rs6000/os-missing-powerpc64.h: New.
        * config.gcc <powerpc-*-elf*>: Add it.
---
 gcc/config.gcc                           |    2 +-
 gcc/config/rs6000/os-missing-powerpc64.h |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/config/rs6000/os-missing-powerpc64.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index afbf82fd2b8f2..9c5ed8801e4b1 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3054,7 +3054,7 @@ powerpc-*-eabisim*)
        use_gcc_stdint=wrap
        ;;
 powerpc-*-elf*)
-       tm_file="${tm_file} elfos.h gnu-user.h usegas.h freebsd-spec.h 
newlib-stdint.h rs6000/sysv4.h"
+       tm_file="${tm_file} elfos.h gnu-user.h usegas.h freebsd-spec.h 
newlib-stdint.h rs6000/sysv4.h rs6000/os-missing-powerpc64.h"
        extra_options="${extra_options} rs6000/sysv4.opt"
        tmake_file="rs6000/t-fprules rs6000/t-ppcgas rs6000/t-ppccomm"
        ;;
diff --git a/gcc/config/rs6000/os-missing-powerpc64.h 
b/gcc/config/rs6000/os-missing-powerpc64.h
new file mode 100644
index 0000000000000..0e9fd34868da3
--- /dev/null
+++ b/gcc/config/rs6000/os-missing-powerpc64.h
@@ -0,0 +1,28 @@
+/* Adjust for operating systems without 64-bit support.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   Contributed by Richard Kenner (ken...@vlsi1.ultra.nyu.edu)
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This setting arranges for the compiler to *not* enable -mpowerpc64
+   implicitly when a 64-bit CPU is selected while building in 32-bit mode.  */
+#define OS_MISSING_POWERPC64 !TARGET_64BIT


-- 
Alexandre Oliva, happy hacker            https://blog.lx.oliva.nom.br/
Free Software Activist     FSFLA co-founder     GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity.
Excluding neuro-others for not behaving ""normal"" is *not* inclusive!

Reply via email to