julia
9f1cc447 - Use uint64_t for debuginfo address differences/slide (#60179)

Commit
95 days ago
Use uint64_t for debuginfo address differences/slide (#60179) Replace all uses of `ptrdiff_t slide` and `int64_t slide` with `uint64_t`. If a JITted object is ever assigned an address in the upper half of the address space on a platform with `sizeof(char *) = 4`, which is quite common on 32-bit Linux, the following can happen: In JITDebugInfoRegistry::registerJITObject, `SectionAddr - SectionLoadAddr` is computed in uint64_t (ok), then cast to ptrdiff_t (two's complement of the uint64_t version mod 2^32). This is apparently implementation-defined behaviour rather than undefined. Say SectionAddr = 0x1000UL, SectionLoadAddr = 0xe93b2000UL and size_t pointer = 0xe93b20abU. ``` (ptrdiff_t)(SectionAddr - SectionLoadAddr) == (ptrdiff_t)0xffffffff16c4f000 == 382005248 ``` jl_DI_for_fptr implicitly converts the ptrdiff_t to int64_t: ``` (int64_t)382005248 == 382005248L ``` lookup_pointer adds `size_t pointer` to `int64_t slide`. Both are converted to int64_t because it can represent every size_t: ``` (int64_t)0xe93b20abU + 382005248L == 3912966315L + 382005248L == 4294971563L ``` This is converted back to uint64_t by makeAddress, resulting in an address other than the 0x10ab we expected: ``` (uint64_t)4294971563L == 0x1000010abUL ``` It is easier to use uint64_t everywhere we need a difference, since they avoid the problem of losing upper bits after sign extension and avoid weird UB from signed overflow. Cherry-picked from #60031. [1] https://buildkite.com/julialang/julia-master/builds/52196/steps/canvas?sid=019a9d6f-14a6-4ffc-be19-f2f835d1e719
Author
Parents
Loading