https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125938

--- Comment #4 from Avinash Jayakar <avinashd at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)
> This isn't documented that way at least.  Instead documentation says
> 
> "If you still run out of space in the TOC even when you specify both of
> these options, specify @option{-mminimal-toc} instead.  This option causes
> GCC to make only one TOC entry for every file.  When you specify this
> option, GCC produces code that is slower and larger but which
> uses extremely little TOC space.  You may wish to use this option
> only on files that contain less frequently-executed code."
> 
> framing -mminimal-toc as safe fallback

Right. In code, i see that no other code model other than small can be used if
minimal-toc is used.
      if ((rs6000_isa_flags_explicit & OPTION_MASK_MINIMAL_TOC) != 0)
        {
          if (OPTION_SET_P (rs6000_current_cmodel)
              && rs6000_current_cmodel != CMODEL_SMALL)
            error ("%<-mcmodel%> incompatible with other toc options");
          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);
        }
Based on the code above, it looks like for mfull-toc and m{no}minimal-toc 
(rs6000_isa_flags_explicit & OPTION_MASK_MINIMAL_TOC) != 0
this is true, and unless we gave -mno-minimal-toc with power10 (that has pcrel
support), it sets the code model to small.

Also in the documentation it is mentioned for these options

-mfull-toc
-mno-fp-in-toc
-mno-sum-in-toc
-mminimal-toc
Modify generation of the TOC (Table Of Contents), which is created for every
executable file. The -mfull-toc option is selected by default. In that case,
GCC allocates at least one TOC entry for each unique non-automatic variable
reference in your program. GCC also places floating-point constants in the TOC.
However, only 16,384 entries are available in the TOC.

But I am not sure the statement regarding limited entries applies to
minimal-toc, it looks like not, and it should use the default medium code
model, as it does for no-{fp/sum}-in-toc

Need to check why other code models cannot be used with minimal-toc.

Only warnings are emitted with mcmodel=small, because r2 is used as
toc_register, but with minimal-toc, r30 is used since it used one toc entry per
procedure, and the offset overflows the 16 bit value.
But at linking stage the issue may happen when the values of these offsets are
calculated.

Reply via email to