Skip to content
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

Build for Linux on aarch64 #888

Open
PMExtra opened this issue Oct 10, 2023 · 5 comments
Open

Build for Linux on aarch64 #888

PMExtra opened this issue Oct 10, 2023 · 5 comments

Comments

@PMExtra
Copy link

PMExtra commented Oct 10, 2023

I found some issues and resolved them when building mvnd for Linux on aarch64.

I'm using docker image ubuntu:22.04 on aarch64 machine.

This is my patch:

diff --git a/client/pom.xml b/client/pom.xml
index 679cc23d..3a900043 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -228,6 +228,8 @@
                          -H:-ParseRuntimeOptions
                          -H:+AddAllCharsets
                          -H:+ReportExceptionStackTraces
+                         -H:+TraceNativeToolUsage
+                         -H:PageSize=65536
                          -ea</buildArgs>
             </configuration>
             <executions>
diff --git a/client/src/main/resources/glibc/dynamic-libc-start.c b/client/src/main/resources/glibc/dynamic-libc-start.c
index 2272b255..09097cbc 100644
--- a/client/src/main/resources/glibc/dynamic-libc-start.c
+++ b/client/src/main/resources/glibc/dynamic-libc-start.c
@@ -27,8 +27,8 @@
 #include <dlfcn.h>
 #include <stdint.h>

-__asm__(".symver dlsym,dlsym@GLIBC_2.2.5");
-__asm__(".symver dlvsym,dlvsym@GLIBC_2.2.5");
+__asm__(".symver dlsym,dlsym@GLIBC_2.17");
+__asm__(".symver dlvsym,dlvsym@GLIBC_2.17");

 /* __libc_csu_init is statically linked into each program, and passed to __libc_start_main
  * when the program is running with an old glibc (<2.34).
diff --git a/client/src/main/resources/glibc/glibc.redef b/client/src/main/resources/glibc/glibc.redef
index 10342159..4d330e02 100644
--- a/client/src/main/resources/glibc/glibc.redef
+++ b/client/src/main/resources/glibc/glibc.redef
@@ -15,21 +15,21 @@
 # specific language governing permissions and limitations
 # under the License.
 __libc_start_main __dynamic_libc_start_main
-clock_gettime clock_gettime@GLIBC_2.2.5
-dlopen dlopen@GLIBC_2.2.5
-dlsym dlsym@GLIBC_2.2.5
-memcpy memcpy@GLIBC_2.2.5
-posix_spawn posix_spawn@GLIBC_2.2.5
-pthread_attr_getguardsize pthread_attr_getguardsize@GLIBC_2.2.5
-pthread_attr_getstack pthread_attr_getstack@GLIBC_2.2.5
-pthread_attr_setstacksize pthread_attr_setstacksize@GLIBC_2.2.5
-pthread_condattr_setclock pthread_condattr_setclock@GLIBC_2.3.3
-pthread_create pthread_create@GLIBC_2.2.5
-pthread_getattr_np pthread_getattr_np@GLIBC_2.2.5
-pthread_join pthread_join@GLIBC_2.2.5
-pthread_kill pthread_kill@GLIBC_2.2.5
-pthread_setname_np pthread_setname_np@GLIBC_2.12
-sem_destroy sem_destroy@GLIBC_2.2.5
-sem_init sem_init@GLIBC_2.2.5
-sem_post sem_post@GLIBC_2.2.5
-sem_wait sem_wait@GLIBC_2.2.5
+clock_gettime clock_gettime@GLIBC_2.17
+dlopen dlopen@GLIBC_2.17
+dlsym dlsym@GLIBC_2.17
+memcpy memcpy@GLIBC_2.17
+posix_spawn posix_spawn@GLIBC_2.17
+pthread_attr_getguardsize pthread_attr_getguardsize@GLIBC_2.17
+pthread_attr_getstack pthread_attr_getstack@GLIBC_2.17
+pthread_attr_setstacksize pthread_attr_setstacksize@GLIBC_2.17
+pthread_condattr_setclock pthread_condattr_setclock@GLIBC_2.17
+pthread_create pthread_create@GLIBC_2.17
+pthread_getattr_np pthread_getattr_np@GLIBC_2.17
+pthread_join pthread_join@GLIBC_2.17
+pthread_kill pthread_kill@GLIBC_2.17
+pthread_setname_np pthread_setname_np@GLIBC_2.17
+sem_destroy sem_destroy@GLIBC_2.17
+sem_init sem_init@GLIBC_2.17
+sem_post sem_post@GLIBC_2.17
+sem_wait sem_wait@GLIBC_2.17

After the patch, it builds successfully and works fine on my machine.

I'm looking forward to the official release of Linux aarch64 pre-built distribution. But until then, this patch may help some people in need, so I share it.

@gnodet
Copy link
Contributor

gnodet commented Oct 18, 2023

My understanding is that it would go against #823.
Can this patch be adapted to be inlined and only require glibc 2.12 ?

It would be nice to be able to provide native binaries for linux-arm64, but I don't think GitHub action has any runner yet (see actions/runner-images#5631).

@PMExtra
Copy link
Author

PMExtra commented Oct 18, 2023

I'm sorry that I do not specialize in native programming. So, I'm unsure if my build only requires glibc@2.12.

But I built the project followed by the official workflow (https://github.com/apache/maven-mvnd/blob/1.0-m7/.github/workflows/release.yaml#L67) which contains #825 that solves #823.

I just replaced all amd64 or x86_64 with aarch64 after this patch.

Then everything was fine, even the Verify native binary for only requiring glibc 2.12 script passed. (https://github.com/apache/maven-mvnd/blob/1.0-m7/.github/workflows/release.yaml#L91).

When I copy the target to another aarch64 machine that runs Kylin-OS (a Linux distribution that seems like CentOS 8), it still works fine.

It is worth mentioning that my PAGE_SIZE is 64k rather than 4k (maybe 4k is more common). So I have to set -H:PageSize=65536. We can get more information from oracle/graal#5605

@PMExtra
Copy link
Author

PMExtra commented Oct 18, 2023

By the way, I built the project by Docker which runs on my Apple M1 Macbook.

So, can we use the macOS runner to start up a container and then build the project for linux-aarch64?

@gnodet
Copy link
Contributor

gnodet commented Oct 18, 2023

By the way, I built the project by Docker which runs on my Apple M1 Macbook.

So, can we use the macOS runner to start up a container and then build the project for linux-aarch64?

The mentioned runner is my laptop :-) If you can create a PR that would add provide a script that can generate the linux-aarch64 binaries, I should be able to upload those during the release process (please add the step to https://github.com/apache/maven-mvnd/blob/master/RELEASING.adoc in the PR...)

@gzm55
Copy link
Contributor

gzm55 commented Jan 2, 2024

I'm sorry that I do not specialize in native programming. So, I'm unsure if my build only requires glibc@2.12.

But I built the project followed by the official workflow (https://github.com/apache/maven-mvnd/blob/1.0-m7/.github/workflows/release.yaml#L67) which contains #825 that solves #823.

I just replaced all amd64 or x86_64 with aarch64 after this patch.

Then everything was fine, even the Verify native binary for only requiring glibc 2.12 script passed. (https://github.com/apache/maven-mvnd/blob/1.0-m7/.github/workflows/release.yaml#L91).

When I copy the target to another aarch64 machine that runs Kylin-OS (a Linux distribution that seems like CentOS 8), it still works fine.

It is worth mentioning that my PAGE_SIZE is 64k rather than 4k (maybe 4k is more common). So I have to set -H:PageSize=65536. We can get more information from oracle/graal#5605

For aarch64 arch, the oldest public released glibc is glibc-2.17 for CentOS7. It is reasonable that we limit the running glibc >= 2.17 on aarch64 cpu. But the resource should be upload for each hardware (x64/arm64). Also the UT in CI could be improved to check dependencies strictly for each arch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants