thread local storage related issues

Bug #2067153 reported by leafze
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

Upon further digging, this issue is not unique to Android.

gcc 14 complains on linux/arm64:
/root/sbcl/sbcl/src/runtime/arm64-assem.S:161:(.text+0x38): dangerous relocation
: unsupported relocation
collect2: error: ld returned 1 exit status

And there is a report about monitor.c 's compilation error:
https://sourceforge.net/p/sbcl/mailman/message/58791911/

----
make-android.sh fails with higher (official recommended) version of NDK.

error message since 562a1a329ae9d23c10e6295a9331da20365c9ebb:

ld.lld: error: relocation R_AARCH64_LD_PREL_LO19 cannot be used against symbol 'current_thread'; recompile with -fPIC
>>> defined in thread.pic.o
>>> referenced by arm64-assem.S:153
>>> arm64-assem.pic.o:(call_into_lisp)
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)

This is probably due to GNU binutils is deprecated (GNU ld being replaced by clang's ld) since NDK version 22. (however, I suspect that the old relocation
would not work properly in PIC mode).

error message since f082b007bb342aecaf9fdc0aa6b1930a2cfe6247:

monitor.c:324:20: error: incompatible pointer to integer conversion assigning to 'pthread_key_t' (aka 'int') from 'struct thread *' [-Wint-conversion]
    current_thread = all_threads;
                   ^ ~~~~~~~~~~~

This is probably due to not considering without-gcc-tls flag.

I have attached a patch to fix said issue.

Tags: andorid
Revision history for this message
leafze (leafze) wrote :
description: updated
leafze (leafze)
summary: - make-android.sh failing with newer version of NDK
+ thread local storage related issues
leafze (leafze)
description: updated
Revision history for this message
leafze (leafze) wrote :

Updated version of the patch.

The main difference is removed the c preprocessor flag entirely.
The relocation works in non-PIC mode nonetheless; the original idea was to separate them to allow non-PIC mode having more efficient code.
But on the second thought, the performance gain is probably too small to justify the confusion of code.

---

The patch reused the c macro ASSIGN_CURRENT_THREAD (and its family) for monitor.c to fix its problem.
The relocation fix is pretty standard relocation: using adrp+ldr to load the address of current_thread in the global object table (GOT), which is a table for address of global variables, so use another ldr to dereference it.
The relocation fix is addressing to bugs that only observed on arm64 and PIC mode (compiling to shared memory).

description: updated
Changed in sbcl:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.