This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Do not use PRIx32 for printing uint64_t values
ClosedPublic

Authored by atanasyan on Nov 12 2018, 5:49 AM.

Details

Summary

The DWARFDebugAddrTable::dump routine prints 32/64-bits addresses. These values are stored in a vector of uint64_t independently of their original sizes. But format function gets format string with PRIx32 suffix in case of 32-bit address size. At least on MIPS 32-bit targets that leads to incorrect output.

This patch changes formats strings and always use PRIx64 to print uint64_t values.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan created this revision.Nov 12 2018, 5:49 AM

Any chance of a test case?

Any chance of a test case?

I hope the following test case starts to pass on mips buildbot:
http://lab.llvm.org:8011/builders/llvm-mips-linux/builds/3739/steps/test-llvm/logs/FAIL%3A%20LLVM%3A%3Adebug_addr.ll

Could this also be tested cross-platform (on any platform that's building the mips backend)? (ie: a version of this test that 'REQUIRES: ' the mips target and specifically targets it)

Any chance of a test case?

I hope the following test case starts to pass on mips buildbot:
http://lab.llvm.org:8011/builders/llvm-mips-linux/builds/3739/steps/test-llvm/logs/FAIL%3A%20LLVM%3A%3Adebug_addr.ll

Could this also be tested cross-platform (on any platform that's building the mips backend)? (ie: a version of this test that 'REQUIRES: ' the mips target and specifically targets it)

I cannot figure out how to do that. In fact we test various libc. The following code (compiled by gcc and clang) works fine on x86_64 in both 32/64-bit executables but shows incorrect output on mips 32-bit.

uint64_t V = 1;
printf("0x%8.8" PRIx32 "\n", V);

Any chance of a test case?

I hope the following test case starts to pass on mips buildbot:
http://lab.llvm.org:8011/builders/llvm-mips-linux/builds/3739/steps/test-llvm/logs/FAIL%3A%20LLVM%3A%3Adebug_addr.ll

Could this also be tested cross-platform (on any platform that's building the mips backend)? (ie: a version of this test that 'REQUIRES: ' the mips target and specifically targets it)

I cannot figure out how to do that. In fact we test various libc. The following code (compiled by gcc and clang) works fine on x86_64 in both 32/64-bit executables but shows incorrect output on mips 32-bit.

uint64_t V = 1;
printf("0x%8.8" PRIx32 "\n", V);

Since this only affects 32-bit big-endian architectures it might be difficult to reproduce cross-platform.

I know it would also break on 64-bit CHERI-MIPS (big-endian) since we pass all variadic arguments on the stack instead of in registers. However, we have never tried to build LLVM as a pure-capability binary (and I doubt it would work).

dblaikie accepted this revision.Nov 12 2018, 2:34 PM

Ah, OK - so it's not so much a problem of the file being read containing interesting 64 bit values, but the way the host architecture works that exposes this bug. Makes sense - thanks for walking me through it!

This revision is now accepted and ready to land.Nov 12 2018, 2:34 PM
This revision was automatically updated to reflect the committed changes.