[X86] Avoid data16 prefix for lea in x32 mode

The ABI demands a data16 prefix for lea in 64-bit LP64 mode, but not in
64-bit ILP32 mode. In both modes this prefix would ordinarily be
ignored, but the instructions may be changed by the linker to
instructions that are affected by the prefix.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D93157
This commit is contained in:
Harald van Dijk 2020-12-12 17:05:24 +00:00
parent a4823377fd
commit f61e5ecb91
No known key found for this signature in database
GPG Key ID: 7D71BB318A5BD56D
2 changed files with 4 additions and 1 deletions

View File

@ -979,6 +979,8 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
NoAutoPaddingScope NoPadScope(*OutStreamer);
bool Is64Bits = MI.getOpcode() != X86::TLS_addr32 &&
MI.getOpcode() != X86::TLS_base_addr32;
bool Is64BitsLP64 = MI.getOpcode() == X86::TLS_addr64 ||
MI.getOpcode() == X86::TLS_base_addr64;
MCContext &Ctx = OutStreamer->getContext();
MCSymbolRefExpr::VariantKind SRVK;
@ -1012,7 +1014,7 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
if (Is64Bits) {
bool NeedsPadding = SRVK == MCSymbolRefExpr::VK_TLSGD;
if (NeedsPadding)
if (NeedsPadding && Is64BitsLP64)
EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
EmitAndCountInstruction(MCInstBuilder(X86::LEA64r)
.addReg(X86::RDI)

View File

@ -285,6 +285,7 @@ entry:
; CHECK-I686-DAG: calll ___tls_get_addr@PLT
; CHECK-I686-DAG: leal tlssrcgd@TLSGD(,%ebx), %eax
; CHECK-I686-DAG: calll ___tls_get_addr@PLT
; CHECK-X32-NOT: data16
; CHECK-X32-DAG: leaq tlsdstgd@TLSGD(%rip), %rdi
; CHECK-X32-DAG: callq __tls_get_addr@PLT
; CHECK-X32-DAG: leaq tlsptrgd@TLSGD(%rip), %rdi