Skip to content

[FMV][AArch64] Set HAS_*_FMV macro and skip test if symbol is unavailable #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 5 commits into
base: main
Choose a base branch
from

Conversation

IamYJLee
Copy link
Contributor

@IamYJLee IamYJLee commented Jul 21, 2025

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
ld: symbol(s) not found for architecture arm64

Patch Description

  • Selects __init_cpu_features_resolver for Darwin, and __init_cpu_features for Linux.
  • Attempts to compile a dummy program to detect availability of the symbol via TARGET_LLVMGCC.
  • Adds corresponding macro (HAS_DARWIN_FMV or HAS_LINUX_FMV) if detection succeeds.
  • Skips test if the symbol is undefined.

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.

Credit to @momchil-velikov and @labrinea for their valuable input and support during review.

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.

IamYJLee and others added 3 commits July 25, 2025 22:22
…able

- Selects __init_cpu_features_resolver for Darwin, and __init_cpu_features for Linux.
- Attempts to compile a dummy program to detect availability of the symbol via TARGET_LLVMGCC.
- Adds corresponding macro (HAS_DARWIN_FMV or HAS_LINUX_FMV) if detection succeeds.
- Skips test if the symbol is undefined.

Credit to @momchil-velikov and @labrinea for their valuable input and support during review.
@IamYJLee IamYJLee changed the title [FMV][AArch64] Fix missing FMV defines for AArch64 in LNT Makefile [FMV][AArch64] Set HAS_*_FMV macro and skip test if symbol is unavailable Jul 25, 2025
# TARGET_LLVMGCC refers to the compiler specified with the --cc option,
# and can be checked in the build-tools.log file in the test results directory.
SYMBOL := $(shell echo "extern void $(SYMBOL)(void); void (*p)() = $(SYMBOL); int main() {}" | \
$(TARGET_LLVMGCC) --rtlib=compiler-rt -x c - -o /dev/null 2>/dev/null && \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TARGET_LLVMGCC refers to the compiler specified with the --cc option, and can be checked in the build-tools.log file in the test results directory.

@IamYJLee
Copy link
Contributor Author

@jroelofs @labrinea @momchil-velikov Could you please take a look? Thanks!

Copy link
Contributor

@labrinea labrinea left a comment

Choose a reason for hiding this comment

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

As I said earlier I am not sure if TARGET_LLVMGCC is the right compiler and whether --rtlib=compiler-rt should be inherited from some CFLAGS variable. I tested this patch and it worked in my environment.

# TARGET_LLVMGCC refers to the compiler specified with the --cc option,
# and can be checked in the build-tools.log file in the test results directory.
SYMBOL := $(shell echo "extern void $(SYMBOL)(void); void (*p)() = $(SYMBOL); int main() {}" | \
$(TARGET_LLVMGCC) --rtlib=compiler-rt -x c - -o /dev/null 2>/dev/null && \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reviewed the build/CMakeFiles/CMakeConfigureLog.yaml to trace how check_symbol_exists is executed through CMakeLists.txt.
compiler-rt (a runtime library) is not shown in the configuration log, but including it in the current patch appears to work fine without introducing any issues.
Here is check_symbol_exists Log :

buildResult:
      variable: "HAS_AARCH64_FMV"
      cached: true
      stdout: |
        Change Dir: /Users/nshc-yjlee_m/Documents/dev/llvm-test-suite/build/CMakeFiles/CMakeScratch/TryCompile-j5irsv
        
        Run Build Command(s):/opt/homebrew/bin/ninja -v cmTC_f539e && [1/2] /Applications/Xcode161_Testing.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc   -arch arm64 -isysroot /Applications/Xcode161_Testing.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -MD -MT CMakeFiles/cmTC_f539e.dir/CheckSymbolExists.c.o -MF CMakeFiles/cmTC_f539e.dir/CheckSymbolExists.c.o.d -o CMakeFiles/cmTC_f539e.dir/CheckSymbolExists.c.o -c /Users/nshc-yjlee_m/Documents/dev/llvm-test-suite/build/CMakeFiles/CMakeScratch/TryCompile-j5irsv/CheckSymbolExists.c
        [2/2] : && /Applications/Xcode161_Testing.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -arch arm64 -isysroot /Applications/Xcode161_Testing.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_f539e.dir/CheckSymbolExists.c.o -o cmTC_f539e   && :
        
      exitCode: 0

@IamYJLee
Copy link
Contributor Author

IamYJLee commented Jul 25, 2025

As I said earlier I am not sure if TARGET_LLVMGCC is the right compiler and whether --rtlib=compiler-rt should be inherited from some CFLAGS variable. I tested this patch and it worked in my environment.

The logs for check_symbol_exists indicate that the symbol detection is being carried out using the system’s default compiler rather than the clang compiler we aim to test.
This raises the possibility that CC might be the more appropriate variable to use instead of TARGET_LLVMGCC.
If possible, could you take a look at how check_symbol_exists behaves in your environment?

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