Bug 430872 - Fails to build on RISC-V due to failing to link with atomics
Summary: Fails to build on RISC-V due to failing to link with atomics
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: General (show other bugs)
Version: 4.4.1
Platform: Debian unstable Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-28 00:21 UTC by John Scott
Modified: 2021-10-22 21:57 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Scott 2020-12-28 00:21:42 UTC
Hi,

Krita [fails to build on RISC-V with Debian unstable](https://buildd.debian.org/status/package.php?p=krita&suite=sid), and although I don't have a patch, I'm pretty sure I've found the cause. (I'm more of a GLib/GTK person myself.)

It fails like

/usr/bin/ld: CMakeFiles/kritaimage.dir/tiles3/kis_tile_data_store.cc.o: in function `Leapfrog<ConcurrentMap<int, KisTileData*, DefaultKeyTraits<int>, DefaultValueTraits<KisTileData*> > >::TableMigration::run()':
./obj-riscv64-linux-gnu/libs/image/./libs/image/3rdparty/lock_free_map/leapfrog.h:475: undefined reference to `__atomic_exchange_1'
```

The CMake module that tries to check atomic support seems to be doing this:
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
        # First check if atomics work without the library.
        check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
        # If not, check if the library exists, and atomics work with it.
        if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
                check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)

On RISC-V, atomics of four and eight bytes do not require library support (such as with `-pthread`), but for one and two bytes it does. Hence if this check is missing out on checking the need to link for one-byte atomics, that would explain the failure.

For a more eloquent explanation, here's a similar issue in zstd that was fixed: https://github.com/facebook/zstd/pull/1103
Comment 1 John Scott 2021-08-07 18:55:28 UTC
This issue seems to be fixed by this merge request, which removes the internal CheckAtomic.cmake and instead uses the more robust one from extra-cmake-modules: https://invent.kde.org/graphics/krita/-/merge_requests/498
Comment 2 Mara Huldra 2021-09-04 13:12:55 UTC
I ran into the same problem while trying to build Krita for RISC-V 64 bit. Going to try the patch in the PR.
Comment 3 amyspark 2021-10-16 17:30:44 UTC
Marking as confirmed because of an upcoming duplicate bug.
Comment 4 amyspark 2021-10-16 17:32:32 UTC
*** Bug 443817 has been marked as a duplicate of this bug. ***
Comment 5 Bug Janitor Service 2021-10-16 17:41:39 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1099
Comment 6 Halla Rempt 2021-10-19 07:46:09 UTC
Git commit f963f4f42b66715405c9bf087c630df8725332a2 by Halla Rempt, on behalf of L. E. Segovia.
Committed on 19/10/2021 at 07:45.
Pushed by rempt into branch 'master'.

Upgrade CheckAtomic module to a copy of ECM 5.75

I am making this commit since !498 seems to not have progressed for
quite a few months.
Related: bug 443817
Closes !498

M  +61   -59   cmake/modules/CheckAtomic.cmake

https://invent.kde.org/graphics/krita/commit/f963f4f42b66715405c9bf087c630df8725332a2
Comment 7 amyspark 2021-10-22 21:24:23 UTC
Git commit 8e7ccd3cd7601ac4c27696eafd8cd1bb8a40296c by L. E. Segovia.
Committed on 22/10/2021 at 21:23.
Pushed by lsegovia into branch 'master'.

Fix compiler check on CheckAtomic

LLVM_COMPILER_IS_GCC_COMPATIBLE is set by another module in LLVM, which
neither we nor ECM copy on their source.
Related: bug 443817

M  +14   -4    cmake/modules/CheckAtomic.cmake

https://invent.kde.org/graphics/krita/commit/8e7ccd3cd7601ac4c27696eafd8cd1bb8a40296c
Comment 8 amyspark 2021-10-22 21:57:25 UTC
Git commit 410ed417d5ac317f85eefc0f3b5c437b53537d07 by L. E. Segovia.
Committed on 22/10/2021 at 21:56.
Pushed by lsegovia into branch 'krita/5.0'.

Upgrade CheckAtomic module to a copy of ECM 5.75

I am making this commit since !498 seems to not have progressed for
quite a few months.
Related: bug 443817
Closes !498

(cherry picked from commit f963f4f42b66715405c9bf087c630df8725332a2)

M  +61   -59   cmake/modules/CheckAtomic.cmake

https://invent.kde.org/graphics/krita/commit/410ed417d5ac317f85eefc0f3b5c437b53537d07
Comment 9 amyspark 2021-10-22 21:57:41 UTC
Git commit daa53222c830c9b7a5b6c9e8efb322233d7cbc67 by L. E. Segovia.
Committed on 22/10/2021 at 21:56.
Pushed by lsegovia into branch 'krita/5.0'.

Fix compiler check on CheckAtomic

LLVM_COMPILER_IS_GCC_COMPATIBLE is set by another module in LLVM, which
neither we nor ECM copy on their source.
Related: bug 443817
(cherry picked from commit 8e7ccd3cd7601ac4c27696eafd8cd1bb8a40296c)

M  +14   -4    cmake/modules/CheckAtomic.cmake

https://invent.kde.org/graphics/krita/commit/daa53222c830c9b7a5b6c9e8efb322233d7cbc67