SQLite Forum

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__atomic_store_4"
Login

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__atomic_store_4"

(1) By codeservice on 2020-06-08 20:24:37 [link] [source]

On armv7 I cant load sqlite dll now. Previous version fine, issue detected on 3.32.2 only

(2) By Warren Young (wyoung) on 2020-06-08 20:43:16 in reply to 1 [link] [source]

It may be due to this change. You could try cloning the repo and building from source, with the single change backed out:

  $ fossil merge --backout a49f8ec552

If that works, then we know the change doesn't work on your platform, which then leads us to many questions:

  • What OS?
  • What version of the OS?
  • Stock GCC for that OS, or some other version?

Also, please don't use "DLL" when speaking of platforms using dlopen() unless you're speaking of Cygwin or similar. Are you? If not, then some other platform-specific term is more correct: shared object, dylib, etc.

(3) By codeservice on 2020-06-08 20:51:32 in reply to 2 [link] [source]

Its android 9, "so" library compiled on NDK20. Issue detected only for armv7 for now. Android emulator for x86,x64 no issues. iOS arm64, MacOS x64, Windows x64,x86 no issues

(4) By Warren Young (wyoung) on 2020-06-08 20:57:44 in reply to 3 [link] [source]

That means you're probably using Clang rather than GCC, which may explain the problem. It probably needs a more fine-grained ifdef here.

Try removing the ifdef half of that in your local copy, rebuilding it to use the else version. If that works, then you may be able to suggest a modification to the condition that will make Clang take the "else" path on NDK20.

(5) By codeservice on 2020-06-08 21:25:17 in reply to 4 [link] [source]

For now I rollback to 3.31.1

I know for sure this works on NDK20, my previous release was NDK20/3.31.1:

#if GCC_VESRION>=5004000

define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)

define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)

#else

define AtomicLoad(PTR) (*(PTR))

define AtomicStore(PTR,VAL) (*(PTR) = (VAL))

#endif

I know for sure this works on all platforms I am using including armv7,arm64 android

(6) By doug (doug9forester) on 2020-06-09 01:14:32 in reply to 5 [link] [source]

Did you mean to say "...GCC_VERSION..."?

(7) By codeservice on 2020-06-09 02:58:18 in reply to 6 [link] [source]

Hmm, code copied from 3.31.1 (sqlite3.c) Looks like typo in older versions. Now I see why atomic store wasn't included in compilation before.

(8) By codeservice on 2021-01-08 20:09:57 in reply to 4 [source]

Hi, I have fix for armv7 / android / NDK20 atomic store issue.

Already tested and it does look fine to me:

Old code:

#if GCC_VERSION>=4007000 || __has_extension(c_atomic)

New code:

#if GCC_VERSION>=4007000 || (__has_extension(c_atomic) && __has_extension(__atomic_store_n))

Its just require additional check __atomic_store because atomic can be available but atomic store don't.

(9) By codeservice on 2021-01-11 15:14:03 in reply to 8 [link] [source]

Finally found solution. No need to change sqlite code. Sorry for misleading. For armv7 I need to compile with flag: -latomic Only now I have lots of warnings:

./thirdparty/sqlite-3.34.0/sqlite3.c:27511:3: warning: large atomic operation may incur significant performance penalty [-Watomic-alignment] AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed); ^ ./thirdparty/sqlite-3.34.0/sqlite3.c:13536:32: note: expanded from macro 'AtomicStore'

define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)

etc.

But library itself functional on armv7. I think for armv7 NDK20 include only headers for atomic, but not code.