-
Notifications
You must be signed in to change notification settings - Fork 139
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
Cross compilation support for the libraries? #1202
Comments
What architecture do you want to cross-compile to? |
AArch64 (iOS) |
The current code base does not support cross-compilation of the frontend and the libraries, however we have implemented such a mechanism downstream. I'll see if I can clean things up and submit a PR with the change. |
That would be amazing! |
@bryanpkc I have a POC for enable cross-compilation in CMakefiles what I did some weeks ago [1], if you and the community are interested in, I can upload that. |
Thanks, I will take a look at that too! |
This is what I'm doing and the error I'm getting. build.sh (for libpgmath only)
setup.sh
The error
The repo is was cloned into flang_iphonesimulator but I made no changes to it. It's just the name that is wrong. |
I managed to make libpgmath target arch64 by commenting out two lines in
Now I'm getting:
I've tried setting compiler flags with clang -target arm64-apple-ios -print-supported-cpus
Any help is appreciated. |
I fixed the problem above but now there are more problems. Please let me know if something is not clear. The error
The hypothesis:
The top of
So far so good. If I move Only in the ARM pathway The relevant part of
|
Problem above is "fixed" but now I get: fltfenv.c error
Here is the relevant
But the functions in the error:
Fortunately FreeBSD implemennts all thoses three functions. freebsd/aarch64/fenv.h freebsd/aarch64/fenv.c My questions are:
|
I implemented the missing functions above myself. When trying to build libpgmath for iOS I'm getting a bunch of warnings that I will fix afterwards and an error. libpgmath error
The file |
For now I simply declared the prototype for the function above. The next error is again a bit weird. It seems it should be triggered on any arm64 platform. error
The error is on the file It turns out |
Good to see that you are making progress here. Is sincos expected to come from libm? |
As for the overall status: I can build libpgmath but: 1. some targets are still missing the arm64 compiler flags and thus built for x86 (the host) and; 2. there are some warnings about |
WRT SINCOS not being defined: SINCOS is a CPP object macro that is defined in CMakeLists.txt. |
I completely missed that, thanks! I only needed to add the prototype for |
I'm getting a bunch of implicit warnings
It seems that on apple |
I'm still getting quite a few warnings about user defined types in C-linkage functions. Looking at their code I'm not sure if this is really a problem. They are all structs with operator overloads and constructors, which in principles C code wouldn't even know how to call. The warnings.
For now I will just move on to flang itself and come back later. |
Hi. I'm away from my desk reading this on my phone - so I might be missing something. But if I'm following you correctly, you're trying to build for aarch64. The errors you're seeing are from an x86_64 target. |
Thanks, I will check if there is any The build process does finish and link successfully, what makes you think those are x86 errors? |
We implemented our own AArch64-specific routines in fltfenv.c as well.
I remember that I ran into this problem as well. IIRC the use of |
is there a set of code I can test on an apple M1? |
It's not working yet but I'm making progress. libpgmath already builds, I'm now tackling the flang runtime itself, which I expect to be easier. |
Everything builds statically, I'm now trying to solve some linking problems. Linking error
The problem seems to be with But it does not exist on mac, the equivalient seems to be I can't figure out where this flag is being set. |
The problem does not happen when Now what would be a good way around this? Should I just set the system name to Darwin instead of iOS? Ideally we should be able to distinct between both. iOS for example doesn't support |
Anyway, great progress here. |
I would like to make pull request, yes. |
The llvm-project |
I can see they also have |
We are 90% done, now there is only 90% to go. 🎉 🎉 🎉 All the libraries build and link statically and dynamically. But I still need to:
A three years old issue was solved 20 days ago. Talk about luck. I will leave it here for reference. |
@meow464 This is great. M1 support will be super. Thanks for pushing forward with this. |
OpenBLAS compiles and links successfully! |
I'm trying to make OpenBLAS work with numpy on iOS. It's not yet ready for a pull request but but I will leave the instructions here for now in case someone else needs to test it.
Things to be aware of:
setup.sh
build-llvm.sh
build-flang-iphoneos.sh
|
Problem: I'm running into a EXC_BAD_ACCESS with this call stack (forgive the formatting but the Xcode debugger UI is not copy/paste friendly):
Where Ftn_str_copy_klen is a variable args function and seems to be the implementation of the assignment All of this led me to this commit. I was simply using the flang, flang1 and flang2 build for x86 but it seems some code generation code wasn't being triggered? Please let me know if this makes sense. I'm missing something obvious or about to shoot myself on the foot? |
It didn't work :( I don't know how to solve this. EDIT: Sometimes I get a SIGSEGV but I still don't know how to solve it. |
Note: I copied the source of the function below. If I put a breakpoint at the function declaration I can actually proceed through by going step by step, The only thing I can think of is one thread stepping on each other's foot? Ftn_str_copy_klen
|
What does the assembly code (i.e. compiled code for the Fortran function |
I'm knowledgeable enough to tell if this is correct. It doesn't look particularly wrong.
Inside Note: This is not compiled with |
It also happens when:
With obj-c the function at least seems to receive the string parameter but the error still happens on the same line. Anyone using flang on ARM by any chance? |
It seems that a proper port of commit 5d46b68 for AArch64 |
(I didn't give up I just been busy. I got here, I'm fixing this) The function can be called by C code compiled with clang-10. This makes me think llvm11 probably wouldn't be helpful. Assembly generated by flang and register inspection
Assembly code generated by clang-10 with register inspection
It's way past midnight now but I will keep investigating. |
The darwin aarch64 ABI differs a bit from the default ARM64. It's not implemented in LLVM yet but it is implemented in clang and rustc so I will take inspiration from them. |
I'm back. On the AAPCS arguments for variadic functions are passed on the registers (x0-x7) until they are full and only then added to the stack. On Apple only the normal arguments are assigned to registers and all variadic arguments are put on the stack. You can see on my comment above how flang is trying to put all parameters on registers, while clang correctly puts only the first 3 on registers. The function responsible for deciding what to do with vargs seems to be "ll_abi_classify_va_arg_dtype" prototype and doc string
As documented, I set New ll_abi_classify_va_arg_dtype
I also set the CMakeLists.txt to use the modified But yet, the problem persists and the generated code looks the exact same: parameters on registers and nothing on the stack. Registers
Calling assembly code in ilaenv
It really looks like I accidentally didn't swap All ideas are welcomed. |
Hmm I can't find where |
Is there cross compilation support? I only need the libraries, not the compiler.
No matter what parameters I try it keeps building for the host architecture (x86_64).
The text was updated successfully, but these errors were encountered: