[PATCH] D19762: [safestack] Support USP in TCB for musl libc

Michael LeMay via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 10:31:06 PDT 2016


mlemay-intel updated this revision to Diff 76444.
mlemay-intel added a comment.

Updated so that USP is stored in TCB for all musl libc environments on X86,
rather than just those on Linux with the separate stack segment feature enabled.

My original musl libc patches just supported SafeStack with the separate stack
segment feature enabled, but I recently divided them into two series.  The first
series provides architecture-independent support for SafeStack including the
support for storing USP in the TCB.  The second series adds support for the
separate stack segment feature.

By the way, I would welcome feedback on my musl libc patches from the LLVM
community, especially from those of you that have experience developing runtime
support for SafeStack such as @pcc and @eugenis.  My recent posts are listed at
http://www.openwall.com/lists/musl/2016/10/28/ .


https://reviews.llvm.org/D19762

Files:
  lib/Target/X86/X86ISelLowering.cpp
  test/Transforms/SafeStack/X86/addr-taken.ll


Index: test/Transforms/SafeStack/X86/addr-taken.ll
===================================================================
--- test/Transforms/SafeStack/X86/addr-taken.ll
+++ test/Transforms/SafeStack/X86/addr-taken.ll
@@ -1,5 +1,7 @@
 ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
 ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
+; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-musl < %s -o - | FileCheck --check-prefix TCB32 %s
+; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-musl < %s -o - | FileCheck --check-prefix TCB64 %s
 
 @.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
 
@@ -9,14 +11,22 @@
 define void @foo() nounwind uwtable safestack {
 entry:
   ; CHECK: __safestack_unsafe_stack_ptr
+  ; TCB32: %unsafe_stack_ptr = load i8*, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
+  ; TCB32-NEXT: %unsafe_stack_static_top = getelementptr i8, i8* %unsafe_stack_ptr, i32 -16
+  ; TCB32-NEXT: store i8* %unsafe_stack_static_top, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
+  ; TCB64: %unsafe_stack_ptr = load i8*, i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
+  ; TCB64-NEXT: %unsafe_stack_static_top = getelementptr i8, i8* %unsafe_stack_ptr, i32 -16
+  ; TCB64-NEXT: store i8* %unsafe_stack_static_top, i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
   %retval = alloca i32, align 4
   %a = alloca i32, align 4
   %j = alloca i32*, align 8
   store i32 0, i32* %retval
   %0 = load i32, i32* %a, align 4
   %add = add nsw i32 %0, 1
   store i32 %add, i32* %a, align 4
   store i32* %a, i32** %j, align 8
+  ; TCB32: store i8* %unsafe_stack_ptr, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
+  ; TCB64: store i8* %unsafe_stack_ptr, i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
   ret void
 }
 
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -2048,7 +2048,7 @@
   if (Subtarget.getTargetTriple().isOSContiki())
     return getDefaultSafeStackPointerLocation(IRB, false);
 
-  if (!Subtarget.isTargetAndroid())
+  if (!(Subtarget.isTargetAndroid() || Subtarget.getTargetTriple().isMusl()))
     return TargetLowering::getSafeStackPointerLocation(IRB);
 
   // Android provides a fixed TLS slot for the SafeStack pointer. See the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19762.76444.patch
Type: text/x-patch
Size: 2457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161031/e3201589/attachment.bin>


More information about the llvm-commits mailing list