Topic
  • No replies
acrimon86
acrimon86
1 Post

Pinned topic How to call a Metal-C function from plain C/C++ with LP64?

‏2014-06-18T23:48:30Z |

Hi everyone,

I'm a bit of a newbie when it comes to the mainframe in general, but I'm hoping someone can help me out. I'm playing around with calling a Metal-C function from another (non-Metal) C module. I saw this thread and I was able to compile and run the following as the author there did. However, now I'm trying to compile a 64-bit version instead (using the lp64 option), but I'm getting some binder errors.

I compile with this sequence of USS commands:

xlc -Wc,metal,longname,lp64 -S metal.c
as -mgoff metal.s
xlc -Wc,lp64 -c driver.c
xlc -Wl,lp64 driver.o metal.o

The last one results in this error:

IEW2469E 9907 THE ATTRIBUTES OF A REFERENCE TO metal_function FROM SECTION
          driver#C DO NOT MATCH THE ATTRIBUTES OF THE TARGET SYMBOL. REASON  2

The reason code explanation for IEW2469E apparently is: The xplink attributes of the reference and target do not match.

If I remove the lp64 option, my code compiles nicely and runs, so I'm not sure what to do to compile it as 64-bit. Does anyone have any ideas?

metal.c

#pragma prolog(metal_function,main)
#pragma epilog(metal_function,main)

int metal_function() {
    return 42;
}

driver.c

#include <stdio.h>

int metal_function();

int main() {
    int result = metal_function();
    printf("Result: %d\n", result);

    return 0;
}

 

  • ilam
    ilam
    3 Posts
    ACCEPTED ANSWER

    Re: How to call a Metal-C function from plain C/C++ with LP64?

    ‏2014-07-28T21:13:10Z  

    Hi,

    The reason why you got those messages is due to your main program (driver.c)  compiles with LP64 which turns on XPLINK,   but your Metal.c. is non-XPLINK (METAL does not support  XPLINK).

    The issues:

    • There is no LE environment in Metal C, so the stack and linkage in the Metal program is completely under the user's control. 
    • The linkage for your main program is XPLINK when compiles with LP64, so you must provide the appropriate  code to accept the XPLINK call.
    You can specify  #pragma linkage(metal_function,OS) or #pragma linkage(metal_function,OS_NOSTACK) in both driver.c and metal.c, it should solve your problem.
  • ilam
    ilam
    3 Posts

    Re: How to call a Metal-C function from plain C/C++ with LP64?

    ‏2014-07-28T21:13:10Z  

    Hi,

    The reason why you got those messages is due to your main program (driver.c)  compiles with LP64 which turns on XPLINK,   but your Metal.c. is non-XPLINK (METAL does not support  XPLINK).

    The issues:

    • There is no LE environment in Metal C, so the stack and linkage in the Metal program is completely under the user's control. 
    • The linkage for your main program is XPLINK when compiles with LP64, so you must provide the appropriate  code to accept the XPLINK call.
    You can specify  #pragma linkage(metal_function,OS) or #pragma linkage(metal_function,OS_NOSTACK) in both driver.c and metal.c, it should solve your problem.