Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power


#Servers
#Programminglanguages
 View Only
  • 1.  Exceptions violate calling convention

    Posted 09/07/22 08:39 AM
    Consider the following minimal example:
    int main() {
        try {
            throw 0;
        } catch (int) { }
        return 0;
    }​
    Compile the source file:
    > xlclang++ -O3 -g -o minimal minimal.cpp​

    Set up a dbx session:

    (dbx) stop in main
    [1] stop in main
    (dbx) run
    [1] stopped in main at line 2 ($t1)
        2       try {
    (dbx) p $r14
    0x0000000000000001  <--- (1)
    (dbx) stop at 5
    [3] stop at 5
    (dbx) c
    [3] stopped in main at line 5 ($t1)
        5       return 0;
    (dbx) p $r14
    0x000000011000c250   <--- (2)​

    According to this document, the register r14 must be preserved across function calls but clearly throwing and catching an exception between (1) and (2) modifies this register. In particular this is quite dramatic, if the compiler chose to put some local variable inside this register.

    It seems to me that only systems with oslevel -s "7300-00-00-0000" are affected by this bug but we got similar reports from a AIX 7.2 system.

    Can you reproduce this behavior? How do we mitigate this bug since this seems to me like an bug inside the C++ runtime responsible for exception handling?



    ------------------------------
    Philipp Wähnert
    ------------------------------

    #C/C++andFortran


  • 2.  RE: Exceptions violate calling convention

    Posted 09/08/22 08:48 AM
    Hi Philipp,

    I tested it on AIX 7.2 TL5 SP2 and AIX 7.3 TL0 SP1 with both xlC 16.1.0.11 and Open xlC 17.1.0.1. Disregard of the AIX version, the register r14 is changed when the program is compiled using xlC 16.1.0.11 and is NOT changed when the program is compiled using Open xlC 17.1.0.1.

    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 3.  RE: Exceptions violate calling convention

    Posted 09/08/22 08:53 AM
    To make it even more interesting, I compiled the program using xlC (not xlclang++) and the value of the register is not changed.

    # xlC -O3 -g -o test-xlC test.cpp
    # dbx ./test-xlC
    Type 'help' for help.
    reading symbolic information ...
    (dbx) stop in main
    [1] stop in main
    (dbx) run
    [1] stopped in main at line 2
    2 try {
    (dbx) p $r14
    0x00000001
    (dbx) stop at 5
    [3] stop at 5
    (dbx) c
    [3] stopped in main at line 5
    5 return 0;
    (dbx) p $r14
    0x00000001


    So it looks like the problem with clang frontend in xlC 16.

    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 4.  RE: Exceptions violate calling convention

    Posted 09/12/22 03:42 AM
    Thank you for giving the minimal example a shot! I'm glad we aren't the only ones observing this bug.

    To our knowledge, it is a problem between the code generated by the XL C/C++ 16 and the Open XL C/C++ 17 runtime. We couldn't pinpoint the exact reason but
     the bug disappears if compiler and runtime matches.

    We already filed a case and now wait for an official statement from IBM.

    ------------------------------
    Philipp Wähnert
    ------------------------------



  • 5.  RE: Exceptions violate calling convention

    Posted 09/12/22 09:45 AM
    Good catch!  Hats off to you for isolating the problem.  We will work on fixing this.  If this is something you depend on or would like to follow the progress of, I suggest opening a Support case.

    ------------------------------
    Sean Perry
    ------------------------------



  • 6.  RE: Exceptions violate calling convention

    Posted 09/12/22 09:48 AM
    Good catch!  Hats off to you for isolating the problem so well.  We will fix the problem.  If you depend on this I suggest opening a Support case so you can track the progress.

    ------------------------------
    Sean Perry
    ------------------------------



  • 7.  RE: Exceptions violate calling convention

    Posted 09/12/22 11:17 AM
    Thank you! We already opened a support case but found another problem much less subtle: If two modules (e.g. executable and a shared library) contain the same type information, the runtime loader won't coalesce those symbols at runtime. That's a problem if dynamic casts rely on the fact that type information must be identical and not only equal. Usually operating systems choose one side: Either they coalesce those symbols at runtime and compare type information by a pointer comparison (Windows, macOS) or they don't necessarily coalesce those symbol and rely on a slower but more stable string comparison of the actual type name (GNU/Linux).

    Those issues let us wonder whether the C++ runtime 17 is compatible with the code generated by the XL C/C++ 16 and xlclang++. What is the official stance of IBM on the compatibility between the C++ runtime 17 and programs compiled with XL C/C++ 16?

    ------------------------------
    Philipp Wähnert
    ------------------------------



  • 8.  RE: Exceptions violate calling convention

    Posted 09/13/22 09:48 PM
    What is the official stance of IBM on the compatibility between the C++ runtime 17 and programs compiled with XL C/C++ 16?

    The new runtime is meant to be generally load-compatible in keeping with the deployment model of having unversioned runtime installations (different compiler versions target the same runtime library).

    If two modules (e.g. executable and a shared library) contain the same type information, the runtime loader won't coalesce those symbols at runtime.

    Thank you for reaching out about this. We had become aware of this during the development cycle for Open XL 17.1.1, and this is resolved in the new runtime by performing value-based comparison for typeinfo objects.



    ------------------------------
    Hubert Tong
    C++ Standards
    IBM XL Compilers

    My postings on this site do not necessarily represent IBM's positions, strategies or opinions.
    ------------------------------



  • 9.  RE: Exceptions violate calling convention

    Posted 09/14/22 03:36 AM
    Thank you for the clarification of the compatibility issue! So we'll keep our eyes open :-)

    So am I right that the type information issue is already fixed with Open XL C/C++ V17.1.1 or is it still in some pipeline? I already opened the case TS010594823 and following this post I'll link our thread here with this case.

    The initial issue of this thread (exceptions violate calling convention) has the case number TS010576698. In both cases IBM is currently working.


    ------------------------------
    Philipp Wähnert
    ------------------------------



  • 10.  RE: Exceptions violate calling convention

    Posted 09/15/22 02:03 AM
    You're right, the issue disappears with the C++ runtime 17.1.1. Thank you for pointing this out!

    ------------------------------
    Philipp Wähnert
    ------------------------------