IBM Support

PH48307: BACK OUT OF METAL C __PTR32/__PTR64 AMODE PARAMETER CHANGES

A fix is available

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • A number of APARs developed to fix issues with Metal C-generated
    code for passing parameters between functions with different
    AMODEs are causing cascading code generation problems in
    subsequent PTFs.
    
    Code generation issues are seen with usage of
    the __ptr32/__ptr64 pointer qualifiers and the
    __attribute__((amode31))/__attribute__((amode64)) function
    attributes.
    
    There are a number of ways that the issues present.  Typically
    the issues are related to function parameters with incorrect
    memory offset values, missing dereferences, and incorrect
    pointer sizes.
    
    ================================================================
    
    The initial APAR introducing issues was PH18005 in the November
    2019 V2R4 PTF, with additional APARs PH27049 and PH35278 in the
    February 2021 V2R4 PTF.
    
    
    Fix list for z/OS XL C/C++
    https://www.ibm.com/support/pages/fix-list-zos-xl-cc#24
    
    2.4 November 2019 PTF
    APAR PH18005 - AMODE dependency in function parameter list
    formatio using LP64.
    
    2.4 February 2021 PTF
    APAR PH27049 - __ptr64 pointer treated as 31-bit pointer when
    passed as function parameter with O2
    APAR PH35278 Incorrect struct array function parameter when
    accessed via __PTR32 POINTER
    
    ================================================================
    
    It was determined that a complete fix for all function
    parameter problem scenarios was not possible in a PTF release,
    and that the compiler behaviour will need to be considered as a
    limitation.
    
    It was decided to back out the 3 APAR fixes and revert the
    compiler's behaviour back to the GA behaviour for all cases.
    This will re-introduce the issue in APAR PH18005, however the
    problem can be worked around by adding a __ptr32 qualifier cast
    to the parameter:
    
    -----------------------
    void g(int, ...) __attribute__((amode31));
    
    void f()
    { g(0, ""); }
    -----------------------
    
    modified to:
    
    -----------------------
    void g(int, ...) __attribute__((amode31));
    void f() {
      char * __ptr32 test = "";
      g(0, test);
    }
    -----------------------
    

Local fix

  • For users who are required to use a specific PTF level and are
    unable to update to the latest PTF, a potential solution is to
    provide AMODE conversion information to the compiler via
    pointer casting.
    
    Whenever there is pointer usage involving AMODE conversion, a
    __ptr32/__ptr64 cast must be used to make sure of the correct
    pointer value.  There are many different code scenarios where
    this may happen, but the essential rule is to cast the pointer
    to the expected AMODE, for example:
    
    -----------------------
    #include <metal.h>
    
    typedef struct {
       int i;
       union {
          unsigned char ar[16];
       } u;
    } X;
    
    int ext(void * p) __attribute__((amode31));
    void* f(void* buffer) {
       X* __ptr32 rec = (X*)buffer;
    
       //ext(rec->u.ar); // INCORRECT
    
       //ext((void*__ptr32 )(((X* __ptr64 )rec)->u.ar)); //CORRECT
    }
    -----------------------
    
    How to properly cast the ext() __ptr32 parameter, 'rec', is
    shown.  The 'rec' pointer is originally assigned to the
    64-bit pointer 'buffer' - this is OK - but access and
    operations to the 64-bit struct being pointed at, via the
    __ptr32 'rec' pointer, requires a 64-bit cast.
    
    Therefore the -> dereference in the param list needs to be cast
    to 64-bit, (X* __ptr64).  Then, that 64-bit dereferenced value
    needs to be passed to the AMODE31 ext() function, so the value
    needs to be cast again to (void* __ptr32).
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED: Uses accessing array members in structs      *
    *                 using alternate amode pointers to the        *
    *                 structure                                    *
    ****************************************************************
    * PROBLEM DESCRIPTION: Access to array struct members via a    *
    *                      ptr32 qualified pointer in 64-bit mode  *
    *                      may give incorrect offsets into the     *
    *                      structure.                              *
    ****************************************************************
    * RECOMMENDATION: Install the PTF                              *
    ****************************************************************
    N/A
    

Problem conclusion

  • Install the PTF or use workaround
    

Temporary fix

Comments

APAR Information

  • APAR number

    PH48307

  • Reported component name

    C/C++ FOR MVS

  • Reported component ID

    56551210A

  • Reported release

    7C0

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2022-07-28

  • Closed date

    2022-08-05

  • Last modified date

    2022-10-03

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    PH49634

Modules/Macros

  • CCNECICS CCNECWI  CCNED240 CCNEDSCT CCNEDWRT CCNEFILT CCNEHIFC
    CCNEIPA3 CCNEIPAO CCNEMDEP CCNEOPTP CCNEP    CCNEPP   CCNETBY
    CCNMSGE  CCNMSGT  CCNQIPA
    

Fix information

  • Fixed component name

    C/C++ FOR MVS

  • Fixed component ID

    56551210A

Applicable component levels

  • R7C0 PSY UI81828

       UP22/09/07 P F209

Fix is available

  • Select the PTF appropriate for your component level. You will be required to sign in. Distribution on physical media is not available in all countries.

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSTLTF","label":"z\/OS XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7C0","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
03 October 2022