[llvm] b0ef207 - [X86] Fix position-independent TType encoding
Harald van Dijk via llvm-commits
llvm-commits at lists.llvm.org
Mon May 10 09:04:54 PDT 2021
Author: Harald van Dijk
Date: 2021-05-10T17:04:33+01:00
New Revision: b0ef2070bc7da2b458fb15b9413d9e90abc71759
URL: https://github.com/llvm/llvm-project/commit/b0ef2070bc7da2b458fb15b9413d9e90abc71759
DIFF: https://github.com/llvm/llvm-project/commit/b0ef2070bc7da2b458fb15b9413d9e90abc71759.diff
LOG: [X86] Fix position-independent TType encoding
The logic for x86_64 position-independent TType encodings was backwards,
using 8 bytes where 4 were wanted and 4 where 8 were wanted. For regular
x86_64, this was mostly harmless, exception tables are allowed to use
8-byte encodings even when it is not needed. For the large code model,
and for X32, however, the generated exception tables were wrong. For the
large code model, we cannot assume that the address will fit in 4 bytes.
For X32, we cannot use 64-bit relocations.
Fixes PR50148.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D102132
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 5315ec9b7c0b7..3227fd79f5677 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -153,7 +153,7 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
((CM == CodeModel::Small || CM == CodeModel::Medium)
- ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
+ ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
} else {
PersonalityEncoding =
(CM == CodeModel::Small || CM == CodeModel::Medium)
diff --git a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
index e0aae5be7c390..13cec64dd276f 100644
--- a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
+++ b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
@@ -1,5 +1,11 @@
-; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,CHECK-NON-PIC
-; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -relocation-model=pic < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PIC
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -code-model=small < %s | FileCheck %s --check-prefixes=CHECK,CHECK-SMALL,CHECK-NON-PIC,CHECK-NON-PIC-SMALL,CHECK-NON-PIC-X64
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnux32 -code-model=small < %s | FileCheck %s --check-prefixes=CHECK,CHECK-SMALL,CHECK-NON-PIC,CHECK-NON-PIC-SMALL,CHECK-NON-PIC-X32
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -code-model=medium < %s | FileCheck %s --check-prefixes=CHECK,CHECK-MEDIUM,CHECK-NON-PIC,CHECK-NON-PIC-MEDIUM,CHECK-NON-PIC-X64
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -code-model=large < %s | FileCheck %s --check-prefixes=CHECK,CHECK-NON-PIC,CHECK-NON-PIC-LARGE,CHECK-NON-PIC-X64
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -relocation-model=pic -code-model=small < %s | FileCheck %s --check-prefixes=CHECK,CHECK-SMALL,CHECK-PIC,CHECK-PIC-SMALL,CHECK-PIC-X64
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnux32 -relocation-model=pic -code-model=small < %s | FileCheck %s --check-prefixes=CHECK,CHECK-SMALL,CHECK-PIC,CHECK-PIC-SMALL,CHECK-PIC-X32
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -relocation-model=pic -code-model=medium < %s | FileCheck %s --check-prefixes=CHECK,CHECK-MEDIUM,CHECK-PIC,CHECK-PIC-MEDIUM,CHECK-PIC-X64
+; RUN: llc -basic-block-sections=all -mtriple x86_64-pc-linux-gnu -relocation-model=pic -code-model=large < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PIC,CHECK-PIC-LARGE,CHECK-PIC-X64
@_ZTIi = external constant i8*
define i32 @main() uwtable optsize ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
@@ -10,19 +16,36 @@ define i32 @main() uwtable optsize ssp personality i8* bitcast (i32 (...)* @__gx
; CHECK-NEXT: .cfi_startproc
;; Verify personality function and LSDA encoding for NON-PIC mode.
-; PersonalityEncoding = dwarf::DW_EH_PE_udata4
-; CHECK-NON-PIC-NEXT: .cfi_personality 3, __gxx_personality_v0
-; LSDAEncoding = dwarf::DW_EH_PE_udata4
-; CHECK-NON-PIC-NEXT: .cfi_lsda 3, .Lexception0
+; PersonalityEncoding = dwarf::DW_EH_PE_udata4 (small/medium)
+; PersonalityEncoding = dwarf::DW_EH_PE_absptr (large)
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_personality 0, __gxx_personality_v0
+; LSDAEncoding = dwarf::DW_EH_PE_udata4 (small)
+; LSDAEncoding = dwarf::DW_EH_PE_absptr (medium/large)
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_lsda 3, .Lexception0
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_lsda 0, .Lexception0
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_lsda 0, .Lexception0
;; Verify personality function and LSDA encoding for PIC mode.
-; PersonalityEncoding = DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4
-; CHECK-PIC-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
-; LSDAEncoding = DW_EH_PE_pcrel | DW_EH_PE_sdata4
-; CHECK-PIC-NEXT: .cfi_lsda 27, .Lexception0
+; PersonalityEncoding = DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4 (small/medium)
+; PersonalityEncoding = DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata8 (large)
+; CHECK-PIC-SMALL-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-MEDIUM-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-LARGE-NEXT: .cfi_personality 156, DW.ref.__gxx_personality_v0
+; LSDAEncoding = DW_EH_PE_pcrel | DW_EH_PE_sdata4 (small)
+; LSDAEncoding = DW_EH_PE_pcrel | DW_EH_PE_sdata8 (medium/large)
+; CHECK-PIC-SMALL-NEXT: .cfi_lsda 27, .Lexception0
+; CHECK-PIC-MEDIUM-NEXT: .cfi_lsda 28, .Lexception0
+; CHECK-PIC-LARGE-NEXT: .cfi_lsda 28, .Lexception0
; CHECK-LABEL: .Ltmp0:
-; CHECK-NEXT: callq _Z1fv
+; CHECK-SMALL-NEXT: callq _Z1fv
+; CHECK-MEDIUM-NEXT: callq _Z1fv
+; CHECK-NON-PIC-LARGE-NEXT: movabsq $_Z1fv, %rax
+; CHECK-NON-PIC-LARGE-NEXT: callq *%rax
+; CHECK-PIC-LARGE-NEXT: movabsq $_Z1fv at GOT, %rax
+; CHECK-PIC-LARGE-NEXT: callq *(%rbx,%rax)
; CHECK-LABEL: .Ltmp1:
; CHECK-NOT: .cfi_lsda
@@ -30,22 +53,38 @@ define i32 @main() uwtable optsize ssp personality i8* bitcast (i32 (...)* @__gx
; CHECK-LABEL: main.__part.1:
; CHECK-NEXT: .cfi_startproc
-; CHECK-NON-PIC-NEXT: .cfi_personality 3, __gxx_personality_v0
-; CHECK-NON-PIC-NEXT: .cfi_lsda 3, .Lexception1
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_personality 0, __gxx_personality_v0
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_lsda 3, .Lexception1
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_lsda 0, .Lexception1
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_lsda 0, .Lexception1
-; CHECK-PIC-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
-; CHECK-PIC-NEXT: .cfi_lsda 27, .Lexception1
+; CHECK-PIC-SMALL-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-MEDIUM-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-LARGE-NEXT: .cfi_personality 156, DW.ref.__gxx_personality_v0
+; CHECK-PIC-SMALL-NEXT: .cfi_lsda 27, .Lexception1
+; CHECK-PIC-MEDIUM-NEXT: .cfi_lsda 28, .Lexception1
+; CHECK-PIC-LARGE-NEXT: .cfi_lsda 28, .Lexception1
; CHECK-NOT: .cfi_lsda
; CHECK-LABEL: main.__part.2:
; CHECK-NEXT: .cfi_startproc
-; CHECK-NON-PIC-NEXT: .cfi_personality 3, __gxx_personality_v0
-; CHECK-NON-PIC-NEXT: .cfi_lsda 3, .Lexception2
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_personality 3, __gxx_personality_v0
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_personality 0, __gxx_personality_v0
+; CHECK-NON-PIC-SMALL-NEXT: .cfi_lsda 3, .Lexception2
+; CHECK-NON-PIC-MEDIUM-NEXT: .cfi_lsda 0, .Lexception2
+; CHECK-NON-PIC-LARGE-NEXT: .cfi_lsda 0, .Lexception2
-; CHECK-PIC-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
-; CHECK-PIC-NEXT: .cfi_lsda 27, .Lexception2
+; CHECK-PIC-SMALL-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-MEDIUM-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0
+; CHECK-PIC-LARGE-NEXT: .cfi_personality 156, DW.ref.__gxx_personality_v0
+; CHECK-PIC-SMALL-NEXT: .cfi_lsda 27, .Lexception2
+; CHECK-PIC-MEDIUM-NEXT: .cfi_lsda 28, .Lexception2
+; CHECK-PIC-LARGE-NEXT: .cfi_lsda 28, .Lexception2
; CHECK: nop
; CHECK-LABEL: .Ltmp2:
@@ -82,18 +121,24 @@ declare i32 @__gxx_personality_v0(...)
;; Verify @LPStart encoding for NON-PIC mode.
; CHECK-NON-PIC-NEXT: .byte 0 # @LPStart Encoding = absptr
-; CHECK-NON-PIC-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X64-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X32-NEXT: .long main.__part.2
;; Verify @LPStart encoding for PIC mode.
; CHECK-PIC-NEXT: .byte 16 # @LPStart Encoding = pcrel
; CHECK-PIC-NEXT: [[DOT:\.Ltmp[0-9]+]]:
-; CHECK-PIC-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X64-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X32-NEXT: .long main.__part.2-[[DOT]]
;; Verify @TType encoding for NON-PIC mode.
-; CHECK-NON-PIC-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-SMALL-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-MEDIUM-NEXT: .byte 0 # @TType Encoding = absptr
+; CHECK-NON-PIC-LARGE-NEXT: .byte 0 # @TType Encoding = absptr
;; Verify @TType encoding for PIC mode.
-; CHECK-PIC-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
+; CHECK-PIC-SMALL-NEXT: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-MEDIUM-NEXT:.byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-LARGE-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
; CHECK-NEXT: .uleb128 .Lttbase0-.Lttbaseref0
; CHECK-NEXT: .Lttbaseref0:
@@ -102,21 +147,27 @@ declare i32 @__gxx_personality_v0(...)
; CHECK-NEXT: .Lcst_begin0:
; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 <<
; CHECK-NEXT: .uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
-; CHECK-NEXT: .uleb128 .Ltmp2-main.__part.2 # jumps to .Ltmp2
+; CHECK-NEXT: .uleb128 .Ltmp2-main.__part.2 # jumps to .Ltmp2
; CHECK-NEXT: .byte 3 # On action: 2
; CHECK-NEXT: .p2align 2
; CHECK-NEXT: .Lexception1:
; CHECK-NON-PIC-NEXT: .byte 0 # @LPStart Encoding = absptr
-; CHECK-NON-PIC-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X64-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X32-NEXT: .long main.__part.2
; CHECK-PIC-NEXT: .byte 16 # @LPStart Encoding = pcrel
; CHECK-PIC-NEXT: [[DOT:\.Ltmp[0-9]+]]:
-; CHECK-PIC-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X64-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X32-NEXT: .long main.__part.2-[[DOT]]
-; CHECK-NON-PIC-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-SMALL-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-MEDIUM-NEXT: .byte 0 # @TType Encoding = absptr
+; CHECK-NON-PIC-LARGE-NEXT: .byte 0 # @TType Encoding = absptr
-; CHECK-PIC-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
+; CHECK-PIC-SMALL-NEXT: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-MEDIUM-NEXT:.byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-LARGE-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
; CHECK-NEXT: .uleb128 .Lttbase0-.Lttbaseref1
; CHECK-NEXT: .Lttbaseref1:
@@ -127,15 +178,21 @@ declare i32 @__gxx_personality_v0(...)
; CHECK-NEXT: .Lexception2:
; CHECK-NON-PIC-NEXT: .byte 0 # @LPStart Encoding = absptr
-; CHECK-NON-PIC-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X64-NEXT: .quad main.__part.2
+; CHECK-NON-PIC-X32-NEXT: .long main.__part.2
; CHECK-PIC-NEXT: .byte 16 # @LPStart Encoding = pcrel
; CHECK-PIC-NEXT: [[DOT:\.Ltmp[0-9]+]]:
-; CHECK-PIC-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X64-NEXT: .quad main.__part.2-[[DOT]]
+; CHECK-PIC-X32-NEXT: .long main.__part.2-[[DOT]]
-; CHECK-NON-PIC-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-SMALL-NEXT: .byte 3 # @TType Encoding = udata4
+; CHECK-NON-PIC-MEDIUM-NEXT: .byte 0 # @TType Encoding = absptr
+; CHECK-NON-PIC-LARGE-NEXT: .byte 0 # @TType Encoding = absptr
-; CHECK-PIC-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
+; CHECK-PIC-SMALL-NEXT: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-MEDIUM-NEXT: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; CHECK-PIC-LARGE-NEXT: .byte 156 # @TType Encoding = indirect pcrel sdata8
; CHECK-NEXT: .uleb128 .Lttbase0-.Lttbaseref2
; CHECK-NEXT: .Lttbaseref2:
@@ -156,10 +213,14 @@ declare i32 @__gxx_personality_v0(...)
; CHECK-NEXT: .p2align 2
; CHECK-NEXT: # >> Catch TypeInfos <<
-; CHECK-NON-PIC-NEXT: .long _ZTIi # TypeInfo 1
+; CHECK-NON-PIC-SMALL-NEXT: .long _ZTIi # TypeInfo 1
+; CHECK-NON-PIC-MEDIUM-NEXT: .quad _ZTIi # TypeInfo 1
+; CHECK-NON-PIC-LARGE-NEXT: .quad _ZTIi # TypeInfo 1
; CHECK-PIC-NEXT: [[DOT:\.Ltmp[0-9]+]]:
-; CHECK-PIC-NEXT: .quad .L_ZTIi.DW.stub-[[DOT]]
+; CHECK-PIC-SMALL-NEXT: .long .L_ZTIi.DW.stub-[[DOT]]
+; CHECK-PIC-MEDIUM-NEXT: .long .L_ZTIi.DW.stub-[[DOT]]
+; CHECK-PIC-LARGE-NEXT: .quad .L_ZTIi.DW.stub-[[DOT]]
; CHECK-NEXT: .Lttbase0:
; CHECK-NEXT: .p2align 2
More information about the llvm-commits
mailing list