llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Disassembly of x86-64 GD TLS code sequence is incorrect

Open nga888 opened this issue 5 years ago • 5 comments

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.

nga888 avatar Jan 27 '21 16:01 nga888

mentioned in issue llvm/llvm-project#48246

tstellar avatar Nov 27 '21 04:11 tstellar

Merged: b15f3fc5c71d

tstellar avatar Feb 03 '21 22:02 tstellar

Having discussed my patch with a colleague, I have put it up for review here: https://reviews.llvm.org/D95682.

nga888 avatar Jan 29 '21 15:01 nga888

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.

nga888 avatar Jan 28 '21 10:01 nga888

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)

MaskRay avatar Jan 27 '21 23:01 MaskRay