Disassembly of x86-64 GD TLS code sequence is incorrect
| Bugzilla Link | 48901 |
| Resolution | FIXED |
| Resolved on | Feb 03, 2021 14:25 |
| Version | trunk |
| OS | All |
| Blocks | llvm/llvm-project#11360 llvm/llvm-project#48246 |
| Attachments | Test to reproduce issue. |
| CC | @adibiagio,@topperc,@MaskRay,@RKSimon,@phoebewang,@rotateright |
| Fixed by commit(s) | 94fedd266125a5425aa33e11332bf414f0b6dc35 b15f3fc5c71d |
Extended Description
The following x86-64 GD TLS code sequence does not disassemble correctly:
data16 leaq tdata@TLSGD(%rip),%rdi data16 data16 rex64 callq __tls_get_addr@PLT
Instead of the expected callq, you end up with callw + addb. Attached is a test to reproduce the issue.
This issue seems to be somewhat related to bug 38537 and the fix committed in https://github.com/llvm/llvm-project/commit/cade635c77004ddfabe97a0bbefefcf90d322ed8. That commit message suggests that this disassembly case was known to be broken.
mentioned in issue llvm/llvm-project#48246
Merged: b15f3fc5c71d
Having discussed my patch with a colleague, I have put it up for review here: https://reviews.llvm.org/D95682.
Possible patch for issue? I've attached a patch which appears to fix this issue. However, to be honest, this is the first time I've really looked at x86-64 prefix decoding, so I'm not entirely sure whether the logic in the prefix decoding is correct.
Hopefully, someone with better knowledge can pick this up.
objdump -wdr
0000000000000000 <.text>: 0: 66 48 8d 3d 00 00 00 00 data16 lea 0x0(%rip),%rdi # 0x8 4: R_X86_64_TLSGD tdata-0x4 8: 66 66 48 e8 00 00 00 00 data16 data16 callq 0x10 c: R_X86_64_PLT32 __tls_get_addr-0x4
llvm-objdump -dr
0000000000000000 <.text>: 0: 66 48 8d 3d 00 00 00 00 leaq (%rip), %rdi # 8 <.text+0x8> 0000000000000004: R_X86_64_TLSGD tdata-0x4 8: 66 66 48 e8 00 00 callw 0xe <.text+0xe> 000000000000000c: R_X86_64_PLT32 __tls_get_addr-0x4 e: 00 00 addb %al, (%rax)
Ideally we should also print data16 prefixes. (About the formatting: we intentionally place the inline relocation on the next line - it looks better than objdump's narrow/wide formats)