[llvm] r339534 - Restore correct x86_64 EH encodings in kernel code model

Lei Liu via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 12 23:06:54 PDT 2018


Author: lliu0
Date: Sun Aug 12 23:06:53 2018
New Revision: 339534

URL: http://llvm.org/viewvc/llvm-project?rev=339534&view=rev
Log:
Restore correct x86_64 EH encodings in kernel code model

Fixes PR37524.

The exception handling encodings for x86_64 in kernel code model
has been changed with r309884.  Restore it to correct ones.  These
encodings include PersonalityEncoding, LSDAEncoding and
TTypeEncoding.

Differential Revision: https://reviews.llvm.org/D50490


Added:
    llvm/trunk/test/CodeGen/X86/code-model-kernel.ll
Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=339534&r1=339533&r2=339534&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Sun Aug 12 23:06:53 2018
@@ -96,7 +96,7 @@ void TargetLoweringObjectFileELF::Initia
   TargetLoweringObjectFile::Initialize(Ctx, TgtM);
   TM = &TgtM;
 
-  bool Large = TgtM.getCodeModel() == CodeModel::Large;
+  CodeModel::Model CM = TgtM.getCodeModel();
 
   switch (TgtM.getTargetTriple().getArch()) {
   case Triple::arm:
@@ -124,18 +124,23 @@ void TargetLoweringObjectFileELF::Initia
     break;
   case Triple::x86_64:
     if (isPositionIndependent()) {
-      PersonalityEncoding =
-          dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
-          (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
+      PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+        ((CM == CodeModel::Small || CM == CodeModel::Medium)
+         ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
-                     (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
+        (CM == CodeModel::Small
+         ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
-                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
+        ((CM == CodeModel::Small || CM == CodeModel::Medium)
+         ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     } else {
       PersonalityEncoding =
-          Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
-      LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
-      TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
+        (CM == CodeModel::Small || CM == CodeModel::Medium)
+        ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
+      LSDAEncoding = (CM == CodeModel::Small)
+        ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
+      TTypeEncoding = (CM == CodeModel::Small)
+        ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
     }
     break;
   case Triple::hexagon:

Added: llvm/trunk/test/CodeGen/X86/code-model-kernel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/code-model-kernel.ll?rev=339534&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/code-model-kernel.ll (added)
+++ llvm/trunk/test/CodeGen/X86/code-model-kernel.ll Sun Aug 12 23:06:53 2018
@@ -0,0 +1,79 @@
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -code-model=kernel %s -o - | FileCheck %s
+; CHECK-LABEL: main
+; CHECK: .cfi_startproc
+; CHECK: .cfi_personality 0, __gxx_personality_v0
+; CHECK: .cfi_lsda 0, [[EXCEPTION_LABEL:.L[^ ]*]]
+; CHECK: [[EXCEPTION_LABEL]]:
+; CHECK: .byte	0                       # @TType Encoding = absptr
+; CHECK: .quad	_ZTIi
+
+ at _ZTIi = external constant i8*
+
+; Function Attrs: noinline norecurse optnone uwtable
+define i32 @main() #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+  %1 = alloca i32, align 4
+  %2 = alloca i8*
+  %3 = alloca i32
+  %4 = alloca i32, align 4
+  store i32 0, i32* %1, align 4
+  %5 = call i8* @__cxa_allocate_exception(i64 4) #2
+  %6 = bitcast i8* %5 to i32*
+  store i32 20, i32* %6, align 16
+  invoke void @__cxa_throw(i8* %5, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #3
+          to label %26 unwind label %7
+
+; <label>:7:                                      ; preds = %0
+  %8 = landingpad { i8*, i32 }
+          catch i8* bitcast (i8** @_ZTIi to i8*)
+  %9 = extractvalue { i8*, i32 } %8, 0
+  store i8* %9, i8** %2, align 8
+  %10 = extractvalue { i8*, i32 } %8, 1
+  store i32 %10, i32* %3, align 4
+  br label %11
+
+; <label>:11:                                     ; preds = %7
+  %12 = load i32, i32* %3, align 4
+  %13 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+  %14 = icmp eq i32 %12, %13
+  br i1 %14, label %15, label %21
+
+; <label>:15:                                     ; preds = %11
+  %16 = load i8*, i8** %2, align 8
+  %17 = call i8* @__cxa_begin_catch(i8* %16) #2
+  %18 = bitcast i8* %17 to i32*
+  %19 = load i32, i32* %18, align 4
+  store i32 %19, i32* %4, align 4
+  call void @__cxa_end_catch() #2
+  br label %20
+
+; <label>:20:                                     ; preds = %15
+  ret i32 0
+
+; <label>:21:                                     ; preds = %11
+  %22 = load i8*, i8** %2, align 8
+  %23 = load i32, i32* %3, align 4
+  %24 = insertvalue { i8*, i32 } undef, i8* %22, 0
+  %25 = insertvalue { i8*, i32 } %24, i32 %23, 1
+  resume { i8*, i32 } %25
+
+; <label>:26:                                     ; preds = %0
+  unreachable
+}
+
+declare i8* @__cxa_allocate_exception(i64)
+
+declare void @__cxa_throw(i8*, i8*, i8*)
+
+declare i32 @__gxx_personality_v0(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #1
+
+declare i8* @__cxa_begin_catch(i8*)
+
+declare void @__cxa_end_catch()
+
+attributes #0 = { noinline norecurse optnone uwtable }
+attributes #1 = { nounwind readnone }
+attributes #2 = { nounwind }
+attributes #3 = { noreturn }




More information about the llvm-commits mailing list