Hi there. I have been looking at compiling a nati...
# kotlin-native
e
Hi there. I have been looking at compiling a native project for linux arm32 v7 but are struggling to get my binary to run. I have attempted to compile down to linuxArm32Hfp. The code is for now an simple auto generated Hello World program that runs fine on my computer when compiled to mac. This is configured in a build.gradle.kts file. If it needs to be done elsewhere to get more control that should note be an issue. The unit in question has the following processor and linux version, in case I have misconstrued what the target is. • Linux version 3.12.10+ (root@localhost) (gcc version 4.9.3 (GCC) ) #1 custom • Model name: ARMv7 Processor rev 2 (v7l) • Features : swp half fastmult vfp edsp neon vfpv3 tls vfpd32 We are currently running a golang binary on the unit, that is compiled with the following parameters. • GOOS=linux GOARCH=arm GOARM=7 Thanks in advance for any help!
n
1. What is the ARM device that you are using? 2. Which Linux distribution (including version) is the ARM device running? 3. Have you tried cross compiling the Kotlin program on a real Linux PC (as the host)? 4. Does the Kotlin program run in a QEMU ( https://www.qemu.org/ ) VM? 5. Which ARM CPU does the ARM device use (eg i.MX6 - https://www.nxp.com/products/processors-and-microcontrollers/arm-processors/i-mx-applications-processors/i-mx-6-processors:IMX6X_SERIES )? 6. Which version of Kotlin is used by the program? 7. What problems are encountered when running the program on the ARM device? If possible can you please show the contents of the build.gradle.kts file.
e
I feel like some of that information is included in the first post. But here goes. 1. The device in question is a router from a company called induo, the device is called Spectre V3. 2. See first post 3. No 4. Site does not load 5. No idea 6. 1.4.10 (multiplatform) 7. After some digging i found out that it might be the linked binaries that did not exist, and after symlinking some library it presented segfault instead. I suspect I might need to disable fpmult but are not sure how.
Copy code
kotlin {

    linuxArm32Hfp("native"){
        
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }

    sourceSets {
        val nativeMain by getting
        val nativeTest by getting
    }
}
n
Does the device have the lsb_release command? If it does then please execute the following on the device, and report the results:
lsb_release -a
You should get output that is similar to the following: Distributor ID: Linuxmint Description: Linux Mint 20 Release: 20 Codename: ulyana
Replace the contents of the build.gradle.kts file with the following:
Copy code
group = "org.example"
version = "0.1-SNAPSHOT"

plugins {
    kotlin("multiplatform") version "1.4.10"
}

kotlin {
    linuxArm32Hfp("linuxArm32") {
        binaries {
            executable { entryPoint = "main" }
        }
    }
}
After doing that rename the source root from native to linuxArm32, run the linkDebugExecutableLinuxArm32Hfp Gradle task to generate the debug binary, copy the binary to the Spectre, and run the binary on the Spectre.
What do you mean site does not load? What error messages are you getting after running the program on the Spectre?
That Linux version you posted provides information about the Linux kernel, however additional information is needed on the Linux distribution ( https://en.wikipedia.org/wiki/Linux_distribution ) that the Spectre is running.
e
The linux version is unknown to me. And I have been unable to find out more about it. All I know is that there is a very limited set of commands available on the device in question. My best quess is that the manufacturer took the kernel and added the absolute bare minimum features needed to make the router work, and just left it there. So sadly the kernel version is the best I can do. I meant that qemu.org did not load. As in timed out, it seems to be back up and running now. Ill see if i can take a look at testing with that during the day.
I will try to get to that test you suggested with .kts and change of source root during the day as well. I appreciate that you are taking the time to help! Thank you!
And no lsb_release was not available.
After consulting a colleague we figured out that the dist is a "BusyBox v1.23.2 multi-call binary"
n
This article will aid you in setting up emulation of a ARM Linux environment (works with Kotlin Native ARM Linux binaries): https://shallowsky.com/blog/linux/raspbian-virtual-on-x86.html
j
Hi @napperley - I am facing the same issue as the original poster. I am trying to compile linuxArm32Hfp shared object using Kotlin 1.7 but it keeps giving me an ARMv6 .so file when I want an ARMv7 .so. My YouTrack ticket is here: https://youtrack.jetbrains.com/issue/KT-54427/Kotlin-Native-linuxArm32Hfp-produces-armv6-so-despite-using-compilerOpts-marcharmv7 I am running my build from an x86 ubuntu docker image. Do you know if it's possible to target ARMv7 using the included toolchain for linuxArm32Hfp -- which happens to be arm-unknown-linux-gnueabihf?
n
It should be possible to have Kotlin Native generate a shared library targeting ARMv7. Since Kotlin Native (via Kotlin 1.7) is generating a shared library targeting ARMv6 in your case, then that is a severe Kotlin regression. Do note that Linux ARMv8 is only backwards compatible with Linux ARMv7. If you were planning to use the shared library on a Linux ARMv8 device then that would be a problem. Mixing CPU architectures is likely to produce bad results. I have been in a situation that is kind of like this, except the shared library (for a C library) is already built and provided by the Linux distribution. Manually overriding the CPU architecture of a build is a build smell (bad practice).
j
Hi @napperley - in the details of my youtrack ticket above, my build output had this:
Copy code
w: Linking two modules of different target triples: /tmp/native1886632026687659406/cstubs.bc' is 'armv7-unknown-linux-gnueabihf' whereas 'out' is 'armv6kz-unknown-linux-gnueabihf'
And Sergey commented that the toolchain Kotlin uses is armv6. That's hard to determine using google searching, but ARM cross compilers has supported options for -march and -mcpu
Apparently it seems my cinterop was compiling as armv7 because I used this:
Copy code
compilerOpts ("-march=armv7")
But my Kotlin build scan shows a build step called linuxArm32HfpCompileKlibraries
n
Try asking Sergey (@sergey.bogolepov) why the linuxArm32Hfp target relies on an ARMv6 toolchain, instead of an ARMv7 one.
186 Views