Thursday, April 16, 2015

Illegal Instruction in IBM iSeries (AS400) PASE

Perhaps, most of those who had develop application(s) in iSeries PASE have encountered this very irritating error: "illegal instruction .. bla bla bla .." . Usually, the error shows up at runtime, not when compiling code on PASE. I was very confused back then too. However, upon closer inspection I found out that the culprit is mostly down to one of these facts:
  1. An operating system API defined in AIX also present in iSeries PASE header files but the API is not implemented by PASE runtime. This is how you might encounter this bug:
    • The compiler doesn't complain when you compile your program code due to  the presence of unaltered AIX header in PASE, even though  PASE runtime doesn't implement the said API.
    • At runtime, the runtime loader (and "linker") complained that the said API doesn't exist in the OS. This is the source of said "illegal instruction .. bla bla bla .." error.
  2. NULL pointer value. If your program code encounter NULL pointer at runtime, the OS400 PASE runtime will crash your program via the "illegal instruction .. bla bla bla ..". 
I have to give credit (sic) to IBM that the error made me nervous back then as I thought the compiler I used + IBM supplied linker "combination" created wrong binary which causes the illegal instruction to be emitted upon linking. Only upon closer inspection that I found the culprits explained above. 

Maybe, you want to ask me: then how the hell am I going to be sure the API I needed is supported or not?
Well, you can consult IBM Redbooks. But, AFAIK, you have to test your binary to be 100% sure because there's no detailed explanation on which API are supported and which are not for recent iSeries OS versions (>= iSeries v5.3).