← Back to index
|
Original Bugzilla link
Bug 18748 – bt instruction with immediate offset uses 64-bit variant for 32-bit data
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-04-09T22:41:06Z
Last change time
2020-07-02T09:58:06Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
ag0aep6g
Blocks
18750
Comments
Comment #0
by ag0aep6g — 2018-04-09T22:41:06Z
---- int bt_32_imm(in uint* p) { enum bitnum = 1; return ((p[bitnum >> 5] & (1 << (bitnum & 31)))) != 0; } void main() { import core.sys.posix.sys.mman; import core.sys.posix.unistd; // Allocate two pages. immutable sz = 2 * sysconf(_SC_PAGESIZE); auto m = mmap(null, sz, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); // Discard the higher page. It becomes unreadable. munmap(m + sz / 2, sz / 2); // Try looking at the last 4 bytes of the readable page. uint* p = cast(uint*) (m + sz / 2 - uint.sizeof); bt_32_imm(p); munmap(m, sz / 2); // Free the readable page. } ---- Compile with `-O`. Resulting program segfaults. Generated code for bt_32_imm: ---- 0: 55 push rbp 1: 48 8b ec mov rbp,rsp 4: 48 0f ba 27 01 bt QWORD PTR [rdi],0x1 9: 19 c0 sbb eax,eax b: f7 d8 neg eax d: 5d pop rbp e: c3 ret ---- The bt instruction should be the 32-bit variant (DWORD instead of QWORD). The 64-bit variant tries to load 8 bytes, but only 4 are accessible.
Comment #1
by dlang-bot — 2020-06-21T07:48:15Z
@WalterBright created dlang/dmd pull request #11305 "fix Issue 18748 - bt instruction with immediate offset uses 64-bit va…" fixing this issue: - fix Issue 18748 - bt instruction with immediate offset uses 64-bit variant for 32-bit data
https://github.com/dlang/dmd/pull/11305
Comment #2
by dlang-bot — 2020-07-02T09:58:06Z
dlang/dmd pull request #11305 "fix Issue 18748 - bt instruction with immediate offset uses 64-bit va…" was merged into master: - 31085a3f40beb3bed4e9dbf7cc47970d0e55a46f by Walter Bright: fix Issue 18748 - bt instruction with immediate offset uses 64-bit variant for 32-bit data
https://github.com/dlang/dmd/pull/11305