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

[cmake] link atomic library for certain CPU architectures #21743

Merged
merged 1 commit into from Sep 5, 2022
Merged

[cmake] link atomic library for certain CPU architectures #21743

merged 1 commit into from Sep 5, 2022

Conversation

dlan17
Copy link
Contributor

@dlan17 dlan17 commented Aug 9, 2022

For those CPU architectures:
RISC-V lack 8-bit and 16-bit atomic instructions, and
ARM/MIPS/PPC lack 64-bit atomic instruction.

GCC is supposed to convert these atomics via masking and shifting
like LLVM, which means anything that wants to use these instructions
needs the link option -latomic.

In this patch, we will try to detect if 8-bit, 64-bit atomic instructions exist,
otherwise the atomic library will append to the DEPLIBS list.

Signed-off-by: Yixun Lan dlan@gentoo.org

Description

Motivation and context

How has this been tested?

What is the effect on users?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@dlan17
Copy link
Contributor Author

dlan17 commented Aug 9, 2022

https://bugs.gentoo.org/864421
FYI, I've filed a downstream report here

CMakeLists.txt Outdated
@@ -127,6 +127,9 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED QUIET)
list(APPEND DEPLIBS ${CMAKE_THREAD_LIBS_INIT})

# Atomics
find_package(Atomics REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is linux and riscv/arm specific, this is not globally required. Instead move detection to https://github.com/xbmc/xbmc/blob/master/cmake/scripts/linux/ArchSetup.cmake and add atomics to PLATFORM_REQUIRED_DEPS only when needed

For those CPU architectures:
RISC-V lack 8-bit and 16-bit atomic instructions, and
ARM/MIPS/PPC lack 64-bit atomic instruction.

GCC is supposed  to convert these atomics via masking and shifting
like LLVM, which means anything that wants to use these instructions
needs the link option -latomic.

In this patch, we will try to detect if 8-bit, 64-bit atomic instructions exist,
otherwise the atomic library will append to the DEPLIBS list.

Original issue:
* https://gitlab.kitware.com/cmake/cmake/-/issues/23021#note_1098733

For reference:
* https://gcc.gnu.org/wiki/Atomic/GCCMM

riscv64 specific:
* https://lists.debian.org/debian-riscv/2022/01/msg00009.html

Signed-off-by: Yixun Lan <dlan@gentoo.org>
@dlan17
Copy link
Contributor Author

dlan17 commented Aug 15, 2022

@wsnipex hi, how about this new version? is it ok to merge? or, I'd really appreciate if you can give some comments

@candrews
Copy link
Contributor

@wsnipex can you please review this updated PR?

Thank you!

gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Aug 26, 2022
Upstream: xbmc/xbmc#21743
Closes: https://bugs.gentoo.org/864421
Signed-off-by: Yixun Lan <dlan@gentoo.org>
Closes: #27016
Signed-off-by: Jakov Smolić <jsmolic@gentoo.org>
@fuzzard fuzzard merged commit 1673f47 into xbmc:master Sep 5, 2022
@fuzzard
Copy link
Contributor

fuzzard commented Sep 5, 2022

Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake Platform: Linux Type: Fix non-breaking change which fixes an issue v20 Nexus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants