Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ARM][Compiler-RT] Add optional exclusion of libc provided ARM AEABI builtins from compiler-rt. #137952

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

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

Conversation

simpal01
Copy link
Contributor

@simpal01 simpal01 commented Apr 30, 2025

This patch introduces a new optional CMake flag:
COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS

When enabled, this flag excludes the following ARM AEABI memory function implementations from the compiler-rt build:
__aeabi_memcmp
__aeabi_memset
__aeabi_memcpy
__aeabi_memmove

These functions are already provided by standard C libraries like glibc, newlib, and picolibc, so excluding them avoids duplicate symbol definitions and reduces unnecessary code duplication.

Note:

  • libgcc does not define the _aeabi* functions that overlap with those provided by the C library. Enabling this option makes compiler-rt behave consistently with libgcc.
  • This prevents duplicate symbol errors when linking, particularly in bare-metal configurations where compiler-rt is linked first.
  • This flag is OFF by default, meaning all AEABI memory builtins will still be built unless explicitly excluded.

This change is useful for environments where libc provides runtime routines, supporting more minimal, conflict free builds.

Copy link
Collaborator

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

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

I think it is worth mentioning in the description that libgcc does not define the aeabi functions that align with the C-library functions https://github.com/ARM-software/abi-aa/blob/main/rtabi32/rtabi32.rst#534memory-copying-clearing-and-setting so when this option is enabled then it will make compiler-rt match libgcc.

There is actually no __aeabi_memcmp function and neither clang or gcc call it. I don't know why compiler-rt defines it. I don't think it is worth removing it, but it does mean that we could exclude it, as it is logically a C-library provided function. I don't think it matters too much either way.

Also worth mentioning that this fixes a duplicate symbol problem when compiler-rt is added before the C-library on the link line, which is the case with the bare-metal driver.

@simpal01 simpal01 requested a review from petrhosek April 30, 2025 13:10
simpal01 added 2 commits May 1, 2025 10:02
…builtins from compiler-rt.

This patch introduces a new optional CMake flag:
  COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS

When enabled, this flag excludes the following ARM AEABI
memory function implementations from the compiler-rt build:
	__aeabi_memset
	__aeabi_memcpy
	__aeabi_memmove

These functions are already provided by standard C
libraries like glibc, newlib, and picolibc, so excluding
them avoids duplicate symbol definitions and reduces
unnecessary code duplication.

Note: __aeabi_memcmp and other AEABI functions are not
excluded, as they are not defined in all standard libraries.
This flag is OFF by default, meaning all AEABI memory builtins
will still be built unless explicitly excluded.

This change is useful for environments where libc provides
runtime routines, supporting more minimal, conflict free builds.
… AEABI builtins from compiler-rt.

Add aeabi_memcmp.S to the set of libc-supplied builtins.
Refactor the CMake logic upon adding a new optional flag.
@simpal01 simpal01 force-pushed the exclude-libc-provided-aeabi-builtins branch from 3f6c0b2 to bb4120b Compare May 1, 2025 09:08
@simpal01
Copy link
Contributor Author

simpal01 commented May 1, 2025

I think it is worth mentioning in the description that libgcc does not define the aeabi functions that align with the C-library functions https://github.com/ARM-software/abi-aa/blob/main/rtabi32/rtabi32.rst#534memory-copying-clearing-and-setting so when this option is enabled then it will make compiler-rt match libgcc.

There is actually no __aeabi_memcmp function and neither clang or gcc call it. I don't know why compiler-rt defines it. I don't think it is worth removing it, but it does mean that we could exclude it, as it is logically a C-library provided function. I don't think it matters too much either way.

Also worth mentioning that this fixes a duplicate symbol problem when compiler-rt is added before the C-library on the link line, which is the case with the bare-metal driver.

Done

Copy link
Collaborator

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. This looks good to me and should avoid a multiply defined symbol error between picolibc and compiler-rt.

Please leave some time for other reviewers to comment before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants