We were printing every character, even those that weren't printable. It doesn't really make sense for this option.
The string content was sticked to its address, added two spaces in between (this matches GNU readelf behavior)
Differential D48271
[llvm-readobj] Fix printing format paulsemel on Jun 18 2018, 3:36 AM. Authored by
Details We were printing every character, even those that weren't printable. It doesn't really make sense for this option. The string content was sticked to its address, added two spaces in between (this matches GNU readelf behavior)
Diff Detail
Event Timeline
Comment Actions *looks at this a bit more closely* Ah, OK, so this is a string dumping mode - why is it dumping non-printable characters at all? (I assumed this was reimplementing/matching behavior of some existing tool (in the same way that llvm-objdump is meant to be like the binutils 'objdump' tool - I just assumed there was a 'readobj' tool out there somewhere, but googling around I don't immediately see anything like that)) more like the way the 'strings' tool would work? Or is this trying to match some existing/similar behavior elsewhere? Comment Actions Actually, you were close, this is readelf from GNU Binutils (that's what my GSoC is about :) ).
Comment Actions Probably worth generalizing over the other formats too (again, refactoring as much as possible into common helper functions - guessing most of the contents of "printSectionAsString" could be generalized over all the different formats without duplicating it in each one. But that can be done in follow-up patches. Comment Actions I got a build fail here : http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/10648 Comment Actions I'd guess it's pretty unlikely that it's the passing of a raw_ostream by reference - that's a pretty common thing. To my mind, the code that looks more likely to be crashing there is that maybe the StringRef is out-of-bounds and the range-based for loop is running off the end of the underlying buffer. Have you tried running the test under valgrind? asan? msan? things like that. You might be able to reproduce/identify the crash on your machine so you can validate a fix rather than throwing it at the buildbots again. Comment Actions Well, I ran it for the first patch. This one, I'm just refactoring, nothing has changed for the bounds right ? Comment Actions Which was the first patch that passed the buildbots? Could you Comment Actions Sure: https://reviews.llvm.org/D47989 Comment Actions Just to end this out of bounds possibility : in the failing test, the text section is at the middle of the binary. So, even if I was going out-of-bounds, there shouldn't be corruption.
Comment Actions Has this been recommitted yet? I added llvm::isPrint in r338034 which should help fix this issue. |
The behavior of isprint is undefined if the value is not representable as an unsigned char. Since char on Windows is signed (by default), this means that some bytes could be negative, which is not representable and an unsigned char.
I think the safest thing to do is to cast C to unsigned char.