[RS6000] -mno-minimal-toc vs. power10 pcrelative
authorAlan Modra <amodra@gmail.com>
Mon, 28 Sep 2020 06:53:01 +0000 (16:23 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 1 Oct 2020 01:04:48 +0000 (10:34 +0930)
We've had this hack in the libgcc config to build libgcc with
-mcmodel=small for powerpc64 for a long time.  It wouldn't be a bad
thing if someone who knows the multilib machinery well could arrange
for -mcmodel=small to be passed just for ppc64 when building for
earlier than power10.  But for now, make -mno-minimal-toc do nothing
when pcrel.  Which will do the right thing for any project that has
copied libgcc's trick.

We want this if configuring using --with-cpu=power10 to build a
power10 pcrel libgcc.  --mcmodel=small turns off pcrel.

gcc/
* config/rs6000/linux64.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Don't
set -mcmodel=small for -mno-minimal-toc when pcrel.
libgcc/
* config/rs6000/t-linux: Document purpose of -mno-minimal-toc.

gcc/config/rs6000/linux64.h
libgcc/config/rs6000/t-linux

index 2ded33012827a747735c133c489748d10c14b88a..5c9f8e3d7afba0f3115c46c4bb582f4b054876af 100644 (file)
@@ -132,20 +132,29 @@ extern int dot_symbols;
          if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) == 0)  \
            {                                                   \
              rs6000_isa_flags |= OPTION_MASK_POWERPC64;        \
-             error ("%<-m64%> requires a PowerPC64 cpu");              \
+             error ("%<-m64%> requires a PowerPC64 cpu");      \
            }                                                   \
+         if (!global_options_set.x_rs6000_current_cmodel)      \
+           SET_CMODEL (CMODEL_MEDIUM);                         \
          if ((rs6000_isa_flags_explicit                        \
               & OPTION_MASK_MINIMAL_TOC) != 0)                 \
            {                                                   \
              if (global_options_set.x_rs6000_current_cmodel    \
                  && rs6000_current_cmodel != CMODEL_SMALL)     \
                error ("%<-mcmodel incompatible with other toc options%>"); \
-             SET_CMODEL (CMODEL_SMALL);                        \
+             if (TARGET_MINIMAL_TOC)                           \
+               SET_CMODEL (CMODEL_SMALL);                      \
+             else if (TARGET_PCREL                             \
+                      || (PCREL_SUPPORTED_BY_OS                \
+                          && (rs6000_isa_flags_explicit        \
+                              & OPTION_MASK_PCREL) == 0))      \
+               /* Ignore -mno-minimal-toc.  */                 \
+               ;                                               \
+             else                                              \
+               SET_CMODEL (CMODEL_SMALL);                      \
            }                                                   \
          else                                                  \
            {                                                   \
-             if (!global_options_set.x_rs6000_current_cmodel)  \
-               SET_CMODEL (CMODEL_MEDIUM);                     \
              if (rs6000_current_cmodel != CMODEL_SMALL)        \
                {                                               \
                  if (!global_options_set.x_TARGET_NO_FP_IN_TOC) \
index 4f6d4c4a4d234d8a349d63bb754424f5a020583b..ed821947b66c2f7965db1986ef270420a2b7723c 100644 (file)
@@ -1,3 +1,8 @@
 SHLIB_MAPFILES += $(srcdir)/config/rs6000/libgcc-glibc.ver
 
-HOST_LIBGCC2_CFLAGS += -mlong-double-128 -mno-minimal-toc
+HOST_LIBGCC2_CFLAGS += -mlong-double-128
+
+# This is a way of selecting -mcmodel=small for ppc64, which gives
+# smaller and faster libgcc code.  Directly specifying -mcmodel=small
+# would need to take into account targets for which -mcmodel is invalid.
+HOST_LIBGCC2_CFLAGS += -mno-minimal-toc