Skip to content

[profgen] Use a 64bit integer for &'ing the loadable address #79930

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

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

lanza
Copy link
Member

@lanza lanza commented Jan 30, 2024

For the linux kernel, the loadable segments start at 0xffff... and thus the 32 bit integer here was truncating all the meaningful bits. Grow it to 64 bits.

For the linux kernel, the loadable segments start at 0xffff... and thus
the 32 bit integer here was truncating all the meaningful bits. Grow it
to 64 bits.
@lanza lanza requested a review from WenleiHe January 30, 2024 01:45
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Jan 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2024

@llvm/pr-subscribers-pgo

Author: Nathan Lanza (lanza)

Changes

For the linux kernel, the loadable segments start at 0xffff... and thus the 32 bit integer here was truncating all the meaningful bits. Grow it to 64 bits.


Full diff: https://github.com/llvm/llvm-project/pull/79930.diff

1 Files Affected:

  • (modified) llvm/tools/llvm-profgen/ProfiledBinary.cpp (+1-1)
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index b40c5f8cbbe068..f62228627b8f1e 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -317,7 +317,7 @@ void ProfiledBinary::setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
   // However such info isn't available at post-processing time, assuming
   // 4K page now. Note that we don't use EXEC_PAGESIZE from <linux/param.h>
   // because we may build the tools on non-linux.
-  uint32_t PageSize = 0x1000;
+  uint64_t PageSize = 0x1000;
   for (const typename ELFT::Phdr &Phdr : PhdrRange) {
     if (Phdr.p_type == ELF::PT_LOAD) {
       if (!FirstLoadableAddress)

@WenleiHe WenleiHe requested a review from wlei-llvm January 30, 2024 02:37
Copy link
Member

@WenleiHe WenleiHe left a comment

Choose a reason for hiding this comment

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

Good catch! Thanks for the fix.

I'm wondering why we didn't run into the same issue when using llvm-profgen to generate profile for server linux kernel. cc @yonghong-song

@lanza
Copy link
Member Author

lanza commented Jan 30, 2024

Yea, no idea. The kernel on my work devserver also has a v_addr higher than 0xffffffff00000000, so this should have been truncating all along.

@lanza lanza merged commit 7ff2dc3 into llvm:main Jan 30, 2024
@lanza lanza deleted the page branch January 30, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants