-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for OS400 #9
Comments
I neglected to mention that I see I tried altering
** |
This is the right place to report bugs with jffi! We can put your good, working changes into a PR any time. alloca allocates memory from the calling function's stack. When the called function returns, the stack pointer moves back to the caller's position, so the memory is deallocated automatically. This is equivalent to having "char[256] x" in your code. Because of the stack effects and automatic deallocation, alloca can't directly be emulated with malloc. You're running into problems because the code calling alloca doesn't actually pay attention to the configure results. I'm not sure how to proceed. We could modify all code that uses alloca, but it seems really unfortunate to cripple other platforms for OS/400. I'm poking around to see if there's a blessed alternative to alloca on OS/400. Maybe you have better developer docs? |
I think it may be possible to transplant the magic ifdef alloca block from jni/libffi/include/ffi_common.h to jni/jffi/jffi.h. Can you try that? |
What compiler does OS/400 use? Does it support C99? If so, you could just try to replace alloca() with variable-length arrays. |
If I read the linked compiler documentation correctly, it does support C99. So you should be able to replace the diff --git a/jni/jffi/LongDouble.c b/jni/jffi/LongDouble.c
index cb8f243..b6031a7 100644
--- a/jni/jffi/LongDouble.c
+++ b/jni/jffi/LongDouble.c
@@ -32,9 +32,6 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __sun
-# include <alloca.h>
-#endif
#include <stdint.h>
#include <stdbool.h>
#include <jni.h>
@@ -75,11 +72,10 @@ Java_com_kenai_jffi_Foreign_longDoubleFromString(JNIEnv *env, jobject self, jstr
jbyteArray array, jint arrayOffset, jint arrayLength)
{
long double ld;
- char* tmp;
jsize len;
len = (*env)->GetStringUTFLength(env, str);
- tmp = alloca(len + 1);
+ char tmp[len + 1];
(*env)->GetStringUTFRegion(env, str, 0, len, tmp);
ld = strtold(tmp, NULL);
jffi_encodeLongDouble(env, ld, array, arrayOffset, arrayLength); |
I am using the gcc compiler**. I will work on testing the two suggestions and get back to you. **
|
@aaronbartell That's pretty recent GCC version. It should support VLAs so if the pragma magic @headius suggested doesn't work, please try the above. You probably need to convert more code, of course, but it should be straight-forward. |
@penberg, it made it past |
Here is the log (failed). Below are the diffs so I can make sure I made the correct changes. |
@aaronbartell I meant to copy the pragmas into jffi.h. libffi and the jffi JNI binding get built separately, and will both need the pragmas. Since libffi built fine without the pragmas and failed (with alloca warnings and related errors) when they were removed, it would seem we're on the right track. |
I now have that ifdef code in both areas. I did an Let me know if you'd like me to run it again with either |
That's looking much closer. Something wrong with the final linking of libjffi, but everything seems to have compiled. Perhaps there's a gcc flag needed here to indicate this is a shared library and not an executable? |
@headius Yes, |
I believe we have a successful build! See log here. The issue is I had the operating system upper-cased on this line. I think one thing needing to be cleaned up is the name of the resulting .jar file because it contains a slash (/) in it:
I will work to find how to get rid of the slash in the name. |
I am now running through the diff --git a/libtest/GNUmakefile b/libtest/GNUmakefile
index 9e70664..65c3097 100644
--- a/libtest/GNUmakefile
+++ b/libtest/GNUmakefile
@@ -153,6 +153,13 @@ ifneq ($(findstring mingw, $(OS)),)
LIBEXT = dll
PICFLAGS=
endif
+
+ifeq ($(OS), os400)
+ LIBEXT = a
+ SOFLAGS = -shared -static-libgcc
+ PICFLAGS += -pthread
+endif
+
ifeq ($(CPU), sparcv9)
MODEL = 64
endif That caused some pthread errors to show up during Looking through the libtest/GNUmakefile it doesn't appear PICFLAGS (where -pthread is added) is used on the compiles so I made the following change to see if it would further the test, and it did. diff --git a/libtest/GNUmakefile b/libtest/GNUmakefile
index 9e70664..65c3097 100644
--- a/libtest/GNUmakefile
+++ b/libtest/GNUmakefile
$(LIBTEST): $(TEST_OBJS)
- $(CC) -o $@ $(LDFLAGS) $(TEST_OBJS) -lm
+ $(CC) -pthread -o $@ $(LDFLAGS) $(TEST_OBJS) -lm
clean::
# nothing to do - ant will delete the build dir Then I run Thoughts on what direction I should take these tests? |
Does anything in jffi/build/test/results show what the errors are? With all tests failing I'd guess it's not able to load libjffi.so. |
Great progress btw...I'm sure we'll iron this out soon :-) |
@headius, there was a file for each failure in jffi/build/test (sorry I missed those). Here is an example of one and they are all conveying basically the same error of Concerning -bash-4.2$ pwd
/home/aaron/git/jffi
-bash-4.2$ find . -name libjffi*
./build/jni/libjffi-1.2.a |
Doh! If I would have looked further into the aforementioned stack trace I would have seen this:
I will do some digging to see what I can find. |
I have made it a bit further and am now stuck with errors in this full stack trace. Here's an excerpt:
It is true the above link/file doesn't exist. What portion of the build should have created it? I ran In case you need to know, here are my changes to diff --git a/src/main/java/com/kenai/jffi/internal/StubLoader.java b/src/main/java/com/kenai/jffi/internal/StubLoader.java
index 9a1d842..1e2e14d 100644
--- a/src/main/java/com/kenai/jffi/internal/StubLoader.java
+++ b/src/main/java/com/kenai/jffi/internal/StubLoader.java
@@ -82,6 +82,8 @@ public class StubLoader {
WINDOWS,
/** IBM AIX */
AIX,
+ /** IBM OS400 */
+ OS400,
/** IBM zOS **/
ZLINUX,
@@ -136,7 +138,9 @@ public class StubLoader {
} else if (startsWithIgnoreCase(osName, "sunos") || startsWithIgnoreCase(osName, "solaris")) {
return OS.SOLARIS;
} else if (startsWithIgnoreCase(osName, "aix")) {
- return OS.AIX;
+ return OS.AIX;
+ } else if (startsWithIgnoreCase(osName, "OS/400")) {
+ return OS.OS400;
} else if (startsWithIgnoreCase(osName, "openbsd")) {
return OS.OPENBSD;
} else if (startsWithIgnoreCase(osName, "freebsd")) {
@@ -208,8 +212,10 @@ public class StubLoader {
if (getOS().equals(OS.DARWIN)) {
return "Darwin";
}
+ if (getOS().equals(OS.OS400)) {
+ return "OS400";
+ }
-
String osName = System.getProperty("os.name").split(" ")[0];
return getCPU().name().toLowerCase(LOCALE) + "-" + osName;
} |
The StubLoader changes look good. The libjffi.so would be created by the native part of the build. It occurs to me now you may need to manually copy the it to the archive directory (working from memory here since my machine is busted). Then I believe the jar task will incorporate it into the jffi jar file. |
Bummer about your machine. Is this the file you are talking about? Does it matter it is an archive library vs. shared object?
|
No, the file is jffi-SOMETHING.jar, and the build will put it in dist:
Copy that to archive/ and rebuild, and I believe it will get included into the final jffi jar. The build does not copy to archive/ because the files there are known to git. |
BTW...the final, working OS/400 native jar, copied to archive/, is what you'd PR (ideally as a separate commit from the changes needed to build it). |
Here's the steps I've taken: 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 -
and
9 - 10 - I am guessing I did something wrong. What should I have done? |
Your steps have a lot of duplication, but the end result should have been correct if the library's getting built right. Once you've built the native archive and copied the jar into archive/ you can just do normal builds from then on. The archive/ jar will not be updated unless you copy a new one in place, but it is where the build gets artfacts to insert into the jffi jar. Check that the jffi jar has either the OS400 native jar or the files that would be inside it (the native lib itself). Check that the path/filename jffi uses to load that library actually matches the file (I see .so, and you mentioned .a, so there's a lead). It looks like jffi may not have the right heuristics for building a shared lib filename on OS/400, and so it can't locate the built library. |
A little more info... it seems System.load in |
I wonder if System.loadLibrary is a way to route around this. I've never spent a lot of time looking at how those paths work. I've put out a call for help on Twitter. If System.load is actually appending an invalid extension (and System.mapLibraryName is adding a bogus or atypical extension) that would seem to be a bug in IBM's JVM. That seems unlikely to me. Do you have an IBM iSeries or J9 support person you can talk to about this? I'm running out of ideas and don't have an iSeries machine here to play around on :-) |
@boskowski See this post for a unit test property change you need to make to get past the |
@aaronbartell Thanks, I definitely have to catch up with the backlog. Now I'm stuck with the OS complaining the library (build/jni/libjffi-1.2.a) has a wrong signature (i..e an invalid magic number). |
@boskowski Please include a gist of stack traces so I can look further into errors. Note, you will need to hard code the OS to not have a slash in it (i.e. |
@aaronbartell I just updated the previous message with the log. |
@boskowski, so you've got all my changes including this one where I comment out the default |
Trying not to overdo it, I switched JVM from Java 8 64bit to --- src/main/java/com/kenai/jffi/Platform.java (revision a803d182d8cdbad1eb71fd9a759d764113b9bb11)
+++ src/main/java/com/kenai/jffi/Platform.java (revision )
@@ -415,7 +415,7 @@
@Override
public String mapLibraryName(String libName) {
- return "lib" + libName + ".a";
+ return "lib" + libName + ".so";
}
@Override
--- src/test/java/com/kenai/jffi/UnitHelper.java (revision a803d182d8cdbad1eb71fd9a759d764113b9bb11)
+++ src/test/java/com/kenai/jffi/UnitHelper.java (revision )
@@ -63,6 +63,7 @@
case WINDOWS:
return "msvcrt.dll";
case AIX:
+ case OS400:
if (Platform.getPlatform().addressSize() == 32){
return "libc.a(shr.o)";
} else {
NumberTest yields
this is the test output file (here I shortened the number as already tried by @aaronbartell, but the result is the same as with the original number). What looks strange is the comma, which isn't contained in com/kenai/jffi/NumberTest.java:264. So I tried this:
Does anyone have an idea what magic managed to conjure up the comma replacement? |
What does
|
System-wide CCSID is 65535, I changed it to 37 for my user profile, but I guess this is not enough... I'll check with the sysadmin if a system-wide change is feasible. Thanks, @aaronbartell. Update 2015-12-09: Changing the system-wide CCSID of the target machine is a no go. However, looking at the Java properties, it seems that my CCSID (037) is inherited by the job as can be seen in the properties ant dumps when executing the test, e.g.
I also wonder how any encoding issue can cause a change in the contents of a string constant, turning a dot into a comma, as the error appears before the string is converted into a number. Update: I didn't notice that the error is caused by ret_f128 as it quite obviously receives the BigDecimal in the wrong format. |
Hey folks, where do we stand today? |
@headius I need your input on this question Then I would need to re-fork (to get latest) and re-implement changes (assuming the un-passing test is ok). SIDE NOTE: I am creating an online service for having easy access to the IBM i operating system. It's called Litmis Spaces and currently only supports Node.js and Ruby development with Python, Java, and PHP coming soon. My hope is to automate builds of JRuby-like things so IBM i folks become first class citizens in open source. |
@aaronbartell Thanks, sorry I missed the question. Yes, sounds like we should go forward with the binary assume that is a bad test, and if possible mask out or patch the test to work appropriately on AIX. WRT getting regular testing on i-series...that would obviously be great :-) Let me know if I can do anything to help make that happen. |
@aaronbartell I'll bump this to next release so you have a chance to re-pull and re-base your changes. |
@headius You released 1.2.12 but I don't see the OS400 support. Why? |
@pierrickrouxel Well, I don't see a PR for it anywhere and I'm a little confused at this point what to merge. It's an easy matter to spin a new release, so can someone sort out what we need to do? |
@aaronbartell Still out there? If you're happy with what you have now, can we get a (rebased) PR? |
I can do a rebased PR but not until after I get done with two international travels (Toronto this week and Stockholm in June). Earliest I could accomplish this task is June 25th. Side note: Bummed I can't make the RUM meetup tonight as I see JRuby is the topic (I live in Mankato, MN). Have fun! |
@aaronbartell Ok, whenever you can get to it is great, or if someone else here wants to try to do it that's great too. Yeah, the RUM thing was a last-minute decision...but I'm hoping to get to RUM more regularly. |
All: This is one of the only outstanding issues in the JFFI tracker, and I'd like to resolve it. Do we have anything current that could go into 1.2.13 or a big bang 1.3 release? |
Could you change |
Pinging this one last time to see if someone can contribute a binary or provide access to an environment where we can build for IBM i-series. |
I have access to IBMi 720, but we are in the process of upgrading to a Power 9 IBMi next week and would prefer to do it after we upgrade to the newer machine. It would also but built on the most current i hardware and software environment. Thanks. |
There currently isn't jffi support for IBM's OS400** operating system and I am attempting to build jffi from a git clone of the current master. I see @pierrickrouxel is also working through this issue in the JRuby project and also this issue. Should I be logging this issue here or in the JRuby issues?
**Now known as
IBM i
or justi
. You might also hear it referred to asiSeries
.What I've Done
I've made some changes to the build process (see fork) to support OS400 but have come to a point where I need input because the build isn't completing. The config.log declares alloca support was found, but alloca does NOT exist on OS400.
from config.log
The stdout to my shell gives more information - specifically:
The text was updated successfully, but these errors were encountered: