C/C++ and Fortran

power-server-operatingsystems.png

Operating Systems

The core of your mission-critical workloads: AIX, IBM i, and Enterprise Linux

power-ISV-Solutions1.png

ISV Solutions

Stay up to date with key capabilities running on POWER such as SAP

Business Continuity

Learn how to keep critical processes running and adapt quickly with PowerHA

power-infrastructure-security.png

Power Security

Protect your most sensitive data anywhere in your hybrid cloud

Virtualization

Check here for virtualization and management needs: HMC & CMC, PowerVC, and PowerVM

Open Source

Join our open source efforts within the IBM Power Systems portfolio

Enterprise Infrastructure as a Service

Achieve business growth with agility and flexibility with our enterprise IaaS in Power Virtual Server

Programming Languages

The hub for Programming Languages

Expand all | Collapse all

sigsegv occured when posix_memalign immediately after free in some devices and compile option in AIX

  • 1.  sigsegv occured when posix_memalign immediately after free in some devices and compile option in AIX

    Posted Wed June 24, 2020 05:13 AM
    Edited by JING CHEN Wed June 24, 2020 07:43 AM

    Disclaimer: This post is migrated from IBM Developer Answers that is no longer in use. Its original author is martin.m.kang, posted on Feb. 12, 2019.

    I was assigned to a pointer and free immediately, but sigsegv occur depending on some devices and xlc options.

    xlC_r -o cc.o c.c -lhm has sigsegv occured
    but xlC_r -o cc.o c.c is work.

    ( malloc and free is work. only posix_memalign and free sigsegv occurred )

    this is source code.
    ```
    #include< stdlib.h >
    #include< stdio.h >

    int main()
    {
        void * sPtr = NULL;

        size_t sAlign = 8388608;
        size_t sSize = 8388648;
        int sRet = 0;

        sRet = posix_memalign(&sPtr, sAlign, sSize);
        printf( "after malloc : %p return : %d\n", sPtr, sRet );
        free(sPtr);

        printf( "after free\n" );
        return 0;
    }
    ```

    it work
    - aix7.1 tl3 IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72) Version: 12.01.0000.0000
    - aix6.1 tl9 IBM XL C/C++ for AIX, V10.1 Version: 10.01.0000.0008
    result is

    ```
    after malloc : 22000000 return : 0
    after free
    ```

    but
    - aix6.1 tl3 IBM XL C/C++ for AIX, V10.1 Version: 10.01.0000.0008
    - aix5.3 tl9 IBM XL C/C++ for AIX, V10.1 Version: 10.01.0000.0000
    - aix5.3 tl1 C for AIX version 6.0.0.0 Version: 10.01.0000.0000

    result is

    ```
    after malloc : 22000000 return : 0
    Segmentation fault (core dumped)

    % dbx cc.o core Type 'help' for help.
    [using memory image in core]
    reading symbolic information ...

    Segmentation fault in _ufree at 0xd3c0fcc4 ($t1)
    0xd3c0fcc4 (_ufree+0x44) 80be0000 lwz r5,0x0(r30)
    (dbx) where
    _ufree(??) at 0xd3c0fcc4
    cbase.free(??) at 0xd2b7c048
    main(), line 16 in "c.c"
    ```

    I have not solved this problem over week.
    I searched for a bug report from aix, but I could not find it.

    It is not possible to delete both posix_memalign and lhm option.
    how can i work around or solve it?
    Are there any related bugs?

    Thank you for reading.
    Please help me.

    -------------------------------------------------------------------
    Question asked by martin.m.kang on Feb. 12, 2019
    --------------------------------------------------------------------



  • 2.  RE: sigsegv occured when posix_memalign immediately after free in some devices and compile option in AIX

    Posted Wed June 24, 2020 05:14 AM
    Edited by JING CHEN Wed June 24, 2020 06:37 AM
    This usage scenario is not supported. The memory debug library (libhmd) does not support posix_memalign. The way the library works is by providing alternative implementations of malloc, free, calloc, ..., etc that do some extra book-keeping to detect error situations. If you run nm on the library, you'll see that it does not provide a posix_memalign implementation. Furthermore, if you compile with -bmap:map to have the linker store information in ./map about how it resolved library calls, you'll find that posix_memalign was picked up from libc while free was picked up from libhmd. As a result, when free is called, it does not find the extra book-keeping information and the program fails.

    -----------------------------------------------------------
    Answered by Rafik_Zurob on Feb. 12, 2019
    -----------------------------------------------------------