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

CONC-764: Build error in ma_context.c on android #273

Open
wants to merge 2 commits into
base: 3.3
Choose a base branch
from

Conversation

knielsen
Copy link
Contributor

@knielsen knielsen commented Apr 1, 2025

X18 is a platform-reserved register on Android, not a callee-save register. So it will not be touched by the spawned/resumed co-routine and must not be included in the GCC asm clobber list on this platform.

After some research, it looks like X18 is a scratch register on Linux, but platform reserved on most other platforms, including Android, MacOS, FreeBSD, Windows. So the patch puts X18 in the clobber list on Linux only (and not on Android, which also defines the __linux__ preprocessor macro).

References:

Build failure: microsoft/vcpkg#44015
Android arm64-v8a ABI: https://developer.android.com/ndk/guides/abis#arm64-v8a

X18 is a platform-reserved register on Android, not a callee-save
register. So it will not be touched by the spawned/resumed co-routine
and must not be included in the GCC asm clobber list on this platform.

Signed-off-by: Kristian Nielsen <[email protected]>
@martinp2812
Copy link

The same problem is present on MacOS on ARM64:

   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:676:6: error: inline asm clobber list contains reserved registers: X18 [-Werror,-Winline-asm]
     676 |      "mov x10, sp\n\t"
         |      ^
   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:676:6: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:746:6: error: inline asm clobber list contains reserved registers: X18 [-Werror,-Winline-asm]
     746 |      "ldp x13, x11, [%[save], #0]\n\t"
         |      ^
   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:746:6: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:846:6: error: inline asm clobber list contains reserved registers: X18 [-Werror,-Winline-asm]
     846 |      "ldp x13, x11, [%[save], #0]\n\t"
         |      ^
   ext/mariadb-connector-c-3.4.4-src/libmariadb/ma_context.c:846:6: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
   3 errors generated.

@knielsen
Copy link
Contributor Author

knielsen commented Apr 1, 2025

Interesting. And it seems X18 is also a platform reserved register on arm64 Windows.
Maybe the #ifdef should then be changed to only include X18 in the clobber list on Linux? Though I'll need to check the *BSD's too.

@knielsen
Copy link
Contributor Author

knielsen commented Apr 1, 2025

This is quite annoying, actually :-/

The libmariadb code in ma_context.cc does not use the X18 register in any way, it will work fine on any of the platforms.

On platforms where X18 is reserved, the ma_context.cc code will also preserve it. On other platforms, the X18 register need not be preserved by the ma_context.cc code.

The only case to handle is to tell GCC itself to not generate code that uses X18 in the function, which is only relevant on platforms where it is not reserved.

In summary, the code is correct in all cases, it's just the compiler warning that is bogus. And -Werror is wrongly causing a compile failure here.

Some research show that X18 is mentioned as a platform-reserved
register on most non-linux platforms, including MacOS, Windows, and
FreeBSD. So only put it in the clobber list in Linux.

Note that the ma_context.c code does not itself use the X18 register
in any way. On platforms where X18 is reserved, the co-routine code
will preserve it. On platforms where co-routine code can modify X18,
it does not need to be preserved. Putting X18 in the clobber list is
only to avoid GCC itself generating code that requires that X18 is
preserved.

Signed-off-by: Kristian Nielsen <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants