Skip to content

[FMV][AArch64] Fix missing FMV defines for AArch64 in LNT Makefile #269

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

IamYJLee
Copy link
Contributor

@IamYJLee IamYJLee commented Jul 21, 2025

Add conditional CFLAGS definitions for AArch64 targets to support FMV-related behavior on Darwin and Linux platforms.

  • Adds -DHAS_DARWIN_FMV when ARCH=AArch64 and TARGET_OS=Darwin
  • Adds -DHAS_LINUX_FMV when ARCH=AArch64 and TARGET_OS=Linux

This change fixes build errors when running LNT tests on AArch64 systems with platform-specific FMV handling.

This patch reflects the changes from llvm/llvm-test-suite@d24d5dcd.

ERROR CONTEXT

Before this patch, LNT test runs on AArch64 platforms (e.g., macOS arm64) could fail with missing symbol errors:

--- Tested: 140 tests --
FAIL: SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.compile_time (1 of 140)
FAIL: SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.execution_time (29 of 140)
Processing Times
Undefined symbols for architecture arm64:
  "_RUNTIME_INIT", referenced from:
      _main in aarch64-init-cpu-features.llvm.o
      _main in aarch64-init-cpu-features.llvm.o
      _main in aarch64-init-cpu-features.llvm.o
ld: symbol(s) not found for architecture arm64

Add conditional CFLAGS definitions for AArch64 targets to support
FMV-related behavior on Darwin and Linux platforms.

- Adds -DHAS_DARWIN_FMV when ARCH=AArch64 and TARGET_OS=Darwin
- Adds -DHAS_LINUX_FMV when ARCH=AArch64 and TARGET_OS=Linux

This change fixes build errors when running LNT tests on
AArch64 systems with platform-specific FMV handling.
@davemgreen davemgreen requested a review from labrinea July 21, 2025 07:42
@labrinea
Copy link
Contributor

I am a bit puzzled with the equivalent cmake code

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h "void __init_cpu_features_resolver(void);")
check_symbol_exists(__init_cpu_features_resolver ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h HAS_AARCH64_FMV)

The way I read it HAS_AARCH64_FMV is always true? Am I mistaken, do we need it here too perhaps? cc @jroelofs

@IamYJLee
Copy link
Contributor Author

@labrinea Thank you for your comment.

I've confirmed how check_symbol_exists functions and understand that HAS_AARCH64_FMV is not always true. In my environment, when I configure the project using CMakeLists.txt, HAS_AARCH64_FMV is set to False.

However, when I run LNT with a Makefile that includes my modifications, the build and execution complete without any issues.

In other words, even though check_symbol_exists confirms that the __init_cpu_features_resolver symbol is missing, there are no problems compiling and running aarch64-init-cpu-features.c.

- Adds a pre-build check in the Makefile for the __init_cpu_features_resolver, __init_cpu_features symbol.
- The result is used to define CHECK_FMV (HAS_DARWIN_FMV, HAS_LINUX_FMV), which conditionally compiles the platform-specific code in aarch64-init-cpu-features.c
@IamYJLee
Copy link
Contributor Author

@labrinea
I'm using the following command and encountering an Undefined Symbol error.

./mysandbox/bin/lnt runtest nt --sandbox ./result --cc ./llvm-project/build/bin/clang --test-suite ./llvm-test-suite -j 16 --only-test SingleSource/Benchmarks/Misc --isysroot `xcrun --show-sdk-path`

To match the CMakeLists.txt configuration and resolve this, I've made the following changes:

  1. I added an #if defined() directive to aarch64-init-cpu-features.c to prevent the problematic code from being compiled when HAS_***_FW is False. (My initial attempt to use PROGRAM_TO_SKIP to exclude the file did not work.)

  2. To replicate the logic from the CMakeLists.txt (below code), I added a step that generates and compiles a temporary header file. The result of this check is stored in the CHECK_FMV variable.

    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h "void __init_cpu_features_resolver(void);")
    check_symbol_exists(__init_cpu_features_resolver ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h HAS_AARCH64_FMV)

Testing

In my local environment, the check for the __init_cpu_features* symbol always results in 'no'. I've confirmed my changes work as intended by manually setting the CHECK_FMV variable to both 'yes' and 'no'.

Could you please test these changes in an environment where the __init_cpu_features* symbol check would result in 'yes'?

@labrinea
Copy link
Contributor

labrinea commented Jul 24, 2025

I have raised #270 to address the problem. I am not sure who to ask for review. I tested it and works on a system that has the __init_cpu_features symbol. My doubt is whether $(TARGET_LLVMGCC) is the right compiler. Also whether --rtlib=compiler-rt should be inferred from the existing CFLAGS

@IamYJLee
Copy link
Contributor Author

Hi @labrinea ,

Thank you for the review and for following up with a fix.

I noticed that instead of merging PR #269, you made a separate commit to address the issue.
Would you mind sharing the reasoning behind that? I’d really like to understand the process and expectations better.

If there are specific improvements or changes needed, I’d sincerely appreciate your guidance so that I can apply them myself.
Whenever possible, I’d prefer to see the contribution through to completion on my end — with your feedback and support. I find this helps me improve and feel more ownership of the patch.

Thanks again for your time and help!

@labrinea
Copy link
Contributor

Hi @IamYJLee. Apologies for not guiding you how to improve this PR instead. Since I spent the time investing this issue from my end I thought it's easier to raise a new PR with my changes. Allow me to explain why this patch doesn't work.

  • When overriding the compiler with --cc on the lnt command, it sets CC=None and Target_LLVMGCC=/path/to/compiler, so the shell compile command had no effect
  • Assuming the compiler was correctly set, the program you are trying to compile doesn't not attempt to find the definition of the symbol, so it always succeeds. Therefore I added an assignment to a function pointer. The compiler needs to be able to resolve this. If not you'll get error in which case the script returns something else than the symbol name.
  • When not intending to run a test ifdef-ing out the source is a bad practice. Instead we want to use the Makefile variable PROGRAMS_TO_SKIP

Feel free to adjust this PR accordingly and credit @momchil-velikov for helping me on this on the commit message. There are still two issues with my patch that need to be addressed, so we need someone to review these first.

@IamYJLee
Copy link
Contributor Author

@labrinea
Thank you very much for your detailed explanation and for taking the time to investigate and address the issue.

I completely understand your rationale for submitting a new PR, and I appreciate the clarity you've provided regarding the behavior of --cc, the importance of the function pointer assignment for symbol detection, and the recommendation to use PROGRAMS_TO_SKIP over conditional compilation.

With your permission, I would like to continue the work from here and revise the patch to address the remaining issues you mentioned. I will ensure that appropriate credit is given to you in the commit message for your valuable contributions.

Please let me know if you have any objections. Otherwise, I’ll proceed with the necessary updates.

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

Successfully merging this pull request may close these issues.

2 participants