IBM Support

IJ06072: COMPILER GENERATING INCORRECT CODE LEADING TO MEMORY FAULT

Subscribe to this APAR

By subscribing, you receive periodic emails alerting you to the status of the APAR, along with a link to the fix after it becomes available. You can track this item individually or track all items by product.

Notify me when this APAR changes.

Notify me when an APAR for this component changes.

APAR status

  • Closed as program error.

Error description

  • The problem is that the compiler is generating assembler code
    that crashes.
    
    ===== COMPILE COMMAND:
    $ cc_r  -o test 157849.c
    
    ===== TESTCASE:
    $ cat 157849.c
    #include <strings.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <sys/types.h>
    #include <sys/mman.h>
    
    typedef unsigned char uchar;
    
    /* Calendar date/time structure. */
    #define BASE_YEAR 1900
    typedef struct _dt
    {
      uchar   year;                   /* Years since BASE_YEAR (0 -
    255). */
      uchar   mon;                    /* Month within year (1 - 12).
    */
      uchar   day;                    /* Day within month (1 - 31).
    */
      uchar   hour;                   /* Hours within day (0 - 23).
    */
      uchar   min;                    /* Minutes within hour (0 -
    59).    */
      uchar   sec;                    /* Seconds within minute (0 -
    59).  */
    } DateTime;
    
    static int printDate( DateTime d );
    
    int main( int argc, char *argv[] )
    {
      int rc = 0;
      int  i = 0;
      int fd = -1;
      int dateCount = 0;
      char  *map = NULL;
      DateTime *dates = NULL;
    
      fd = open( argv[1], O_RDWR );
      if ( fd > 0 )
      {
        map = mmap( NULL, 4096, PROT_READ|PROT_WRITE,
    MAP_FILE|MAP_PRIVATE,
                    fd, 0 );
        if ( map != NULL )
        {
          /* get the date count */
    /*    dateCount = *(int *)map; */
          dateCount = 682;
    
          /* point to the array of dates, which begins immediately
    after the
             count */
          dates     =  (DateTime *)(map + sizeof(int) );
    
          /* iterate over the entire array and print out each date
    */
          if ( dateCount > 4096/sizeof(DateTime) )
            fprintf( stderr, "Count value of %d is too big.\n",
    dateCount );
          else
          {
            for ( i=0; i<dateCount; i++ )
              printDate( dates[i] ); /* << crashes when the last
    date is at
                                        << the end of the mmapped
    region */
          }
        }
      }
      else
      {
        rc = errno;
        fprintf( stderr, "Error %d opening %s.\n", rc, argv[1] );
      }
    
      if ( map != 0 )
        munmap( map, 4096 );
    
      return rc;
    } /* main */
    static int printDate( DateTime d )
    {
      fprintf( stdout, "%04d:%02d:%02d\n", d.year+BASE_YEAR, d.mon,
    d.day );
      return 0;
    } /* printDate */
    $
    
    
    ===== ACTUAL OUTPUT:
    $ ./test 157849.dat
    .
    .
    .
    1900:00:00
    1900:00:00
    1900:00:00
    1900:00:00
    1900:00:00
    1900:00:00
    Memory fault
    $
    
    
    ===== EXPECTED OUTPUT:
    Should not crash at runtime
    

Local fix

  • N/A
    

Problem summary

  • USERS AFFECTED:
    Users who write code loading arguments ending at protected page
    boundary are affected by this issue
    
    PROBLEM DESCRIPTION:
    Users will experience a runtime memory error when loading
    arguments ending at protected page boundary
    

Problem conclusion

  • The compiler has been changed to force the load arguments ending
     at protected page boundary with the exact size to void memory
    fault.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IJ06072

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D13

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2018-05-02

  • Closed date

    2018-08-01

  • Last modified date

    2018-08-01

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

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

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5725C7100

Applicable component levels



Document information

More support for: XL C for AIX
Compiler

Software version: D13

Reference #: IJ06072

Modified date: 01 August 2018