On 4/14/2021 3:43 PM, David Edelsohn via Gcc-patches wrote:
     AIX uses a compiler-managed TOC for global data, including TLS symbols.
     The GCC TOC implementation manages the TOC entries through the
constant pool.

     TLS symbols sometimes require a function call to obtain the TLS base
     pointer.  The arguments to the TLS call can conflict with arguments to
     a normal function call if the TLS symbol is an argument in the normal call.
     GCC specifically checks for this situation and precomputes the TLS
     arguments, but the mechanism to check for this requirement utilizes
     legitimate_constant_p().  The necessary result of legitimate_constant_p()
     for correct TOC behavior and for correct TLS argument behavior is in
     conflict.

     I have tried multiple approaches to wrap the symbol in UNSPEC and
tweaking legitimate_constant_p definition.  The current AIX TOC
implementation is too tied to force_const_mem() and the constant pool.
The calls.c test is tied to both CONST and TLS.  I would appreciate
not being told that this is abusing the definition of CONST in GCC or
that I should re-write the TOC implementation.

     This patch adds a new target hook precompute_tls_p() to decide if an
     argument should be precomputed regardless of the result from
     legitmate_constant_p().

If you want to consider this a hack for AIX, fine.

Bootstrapped on powerpc-ibm-aix7.2.3.0.

Thanks, David

             * gcc/calls.c (precompute_register_parameters): Additionally test
             targetm.precompute_tls_p to pre-compute argument.
             * gcc/config/rs6000/aix.h (TARGET_PRECOMPUTE_TLS_P): Define.
             * gcc/config/rs6000/rs6000.c (rs6000_aix_precompute_tls_p): New.
             * gcc/target.def (precompute_tls_p): New.

Not ideal.  But I don't see a better way given your research.


OK

jeff

Reply via email to