fix: lab 5: make sure placeholder is aligned to 4 KiB page in PFH2 #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在一些 gcc 版本下,Lab 5 的 PFH2 测试点中,编译器会将 global_increment 和 global_placeholder 的顺序重新排布. 这样一来,global_placeholder 并不是独占一整页空间,导致难以观测到实验文档中 create_mapping “缺少一页” 的现象.
这个 PR 通过添加
__attribute__((aligned(0x1000)))
告知 gcc 编译器应当让 global_placeholder 对齐到一整页,以确保文档中描述的现象(如果实现正确的话)能够出现.我的测试环境:
使用
nm
查看 gcc 对变量的编排:可以发现 global_placeholder 的位置是
[0x12010, 0x13010)
横跨了两页,而程序既会用到前一页位于 0x12000 的 global_increment,也会用到后一页位于 0x13010 的 buffer,所以两页都会被加载并 create_mapping.使用 gcc 14.2.0 版本时不会出现该问题,因为 gcc 14.2.0 会把 global_placeholder 放在
[0x13000, 0x14000)
,而 global_increment 在 0x12000 处.