[llvm] 47d6635 - [llvm-profgen] Fix alignment in preferred based calculation
Wenlei He via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 29 23:05:16 PDT 2021
Author: Wenlei He
Date: 2021-09-29T23:01:10-07:00
New Revision: 47d66355ef9039a15b7265945e3deb331d7f9e05
URL: https://github.com/llvm/llvm-project/commit/47d66355ef9039a15b7265945e3deb331d7f9e05
DIFF: https://github.com/llvm/llvm-project/commit/47d66355ef9039a15b7265945e3deb331d7f9e05.diff
LOG: [llvm-profgen] Fix alignment in preferred based calculation
We used the segment alignment in elf header to assume the loader alignment. However this is incorrect because loader alignment is always the same as page size. If segment needs to be aligned at load time, linker will set aligned address as virtual address in elf header.
Differential Revision: https://reviews.llvm.org/D110795
Added:
Modified:
llvm/tools/llvm-profgen/ProfiledBinary.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 2d1f68ff77ec..aa96f9478afa 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -233,11 +233,17 @@ ProfiledBinary::getExpandedContext(const SmallVectorImpl<uint64_t> &Stack,
template <class ELFT>
void ProfiledBinary::setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj, StringRef FileName) {
const auto &PhdrRange = unwrapOrError(Obj.program_headers(), FileName);
+ // FIXME: This should be the page size of the system running profiling.
+ // 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;
for (const typename ELFT::Phdr &Phdr : PhdrRange) {
if ((Phdr.p_type == ELF::PT_LOAD) && (Phdr.p_flags & ELF::PF_X)) {
// Segments will always be loaded at a page boundary.
- PreferredTextSegmentAddresses.push_back(Phdr.p_vaddr & ~(Phdr.p_align - 1U));
- TextSegmentOffsets.push_back(Phdr.p_offset & ~(Phdr.p_align - 1U));
+ PreferredTextSegmentAddresses.push_back(Phdr.p_vaddr &
+ ~(PageSize - 1U));
+ TextSegmentOffsets.push_back(Phdr.p_offset & ~(PageSize - 1U));
}
}
More information about the llvm-commits
mailing list