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

CppLink actions having access to fdo_profile_path variable #17277

Open
vinhdaitran opened this issue Jan 20, 2023 · 0 comments
Open

CppLink actions having access to fdo_profile_path variable #17277

vinhdaitran opened this issue Jan 20, 2023 · 0 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@vinhdaitran
Copy link

vinhdaitran commented Jan 20, 2023

Description of the feature request:

C++ rules explicitly pipes //command_line_option:fdo_profile to fdo_profile_path build variable for CppCompileAction. fdo_profile_path build variable is then used in several features in cc toolchain. autofdo is one of the using features.

autofdo is implicitly enabled and expands some fdo-specific flags on c/c++ compile actions when fdo_profile_path is available. This works well in making sure we're able to expand the same set of flags in Bazel as in Soong for CFlags.

In AOSP, Soong also sets some fdo-specific flags to LdFlags. AOSP has its own Bazel cc toolchain and we can modify our custom autofdo feature to expand the flags on the link actions as well. However, Bazel Cc++ rules doesn't not pipe the fdo_profile_path variable for CppLinkAction yet. Hence, the dynamic fdo-specific flags don't have access to fdo_profile_path build variable to expand the flags correctly.

It would be better if there's some mechanism to pipe build variables for C++ toolchain to use for this specific use case.

What underlying problem are you trying to solve with this feature?

There is a workaround to this problem. To set the flags on link actions, we can use user_link_flags and additional_linker_inputs attributes such as

filegroup(
  name = "libart_fdo",
  srcs = select({
    "...": ["libart_arm64.afdo"],
    "...": ["libart_arm.afdo"],
  })
)
cc_shared_library(
  name = "foo",
  user_link_flags = ["-fprofile-sample-use=$(location :libart_fdo)"],
  additional_linker_inputs = [":libart_fdo"],
)

But this is counter-intuitive to the existence of fdo_profile rule where we use fdo_profile rule to set the compile flags correctly and use ^ to set the link flags correctly. Another problem is that this approach results to duplicate profiles. fdo_profile symlinks the profile to a separate directory which is referenced in the compile flags. However, the link flags reference a different location though they should be the same.

@oquenchil oquenchil added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants