Index: include/llvm/ADT/Triple.h =================================================================== --- include/llvm/ADT/Triple.h +++ include/llvm/ADT/Triple.h @@ -180,6 +180,7 @@ EABI, EABIHF, Android, + Musl, MSVC, Itanium, @@ -559,6 +560,11 @@ /// Tests whether the target is Android bool isAndroid() const { return getEnvironment() == Triple::Android; } + /// Tests whether the target uses musl libc + bool isMusl() const { + return getEnvironment() == Triple::Musl; + } + /// Tests whether the target is NVPTX (32- or 64-bit). bool isNVPTX() const { return getArch() == Triple::nvptx || getArch() == Triple::nvptx64; Index: lib/Support/Triple.cpp =================================================================== --- lib/Support/Triple.cpp +++ lib/Support/Triple.cpp @@ -206,6 +206,7 @@ case EABI: return "eabi"; case EABIHF: return "eabihf"; case Android: return "android"; + case Musl: return "musl"; case MSVC: return "msvc"; case Itanium: return "itanium"; case Cygnus: return "cygnus"; @@ -466,6 +467,7 @@ .StartsWith("code16", Triple::CODE16) .StartsWith("gnu", Triple::GNU) .StartsWith("android", Triple::Android) + .StartsWith("musl", Triple::Musl) .StartsWith("msvc", Triple::MSVC) .StartsWith("itanium", Triple::Itanium) .StartsWith("cygnus", Triple::Cygnus) Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -1960,7 +1960,12 @@ return V; } - if (!Subtarget.isTargetAndroid()) + bool MuslSeparateStack = + Subtarget.isTargetMusl() && + Subtarget.isTargetLinux() && + Subtarget.useSeparateStackSeg(); + + if (!(MuslSeparateStack || Subtarget.isTargetAndroid())) return TargetLowering::getSafeStackPointerLocation(IRB); // Android provides a fixed TLS slot for the SafeStack pointer. See the Index: lib/Target/X86/X86Subtarget.h =================================================================== --- lib/Target/X86/X86Subtarget.h +++ lib/Target/X86/X86Subtarget.h @@ -477,6 +477,7 @@ bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); } bool isTargetMCU() const { return TargetTriple.isOSIAMCU(); } bool isTargetContiki() const { return TargetTriple.isOSContiki(); } + bool isTargetMusl() const { return TargetTriple.isMusl(); } bool isTargetWindowsMSVC() const { return TargetTriple.isWindowsMSVCEnvironment(); Index: test/Transforms/SafeStack/addr-taken.ll =================================================================== --- test/Transforms/SafeStack/addr-taken.ll +++ test/Transforms/SafeStack/addr-taken.ll @@ -1,5 +1,6 @@ ; 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 -mattr=+separate-stack-seg < %s -o - | FileCheck --check-prefix TCB %s @.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 @@ -9,6 +10,9 @@ define void @foo() nounwind uwtable safestack { entry: ; CHECK: __safestack_unsafe_stack_ptr + ; TCB: %unsafe_stack_ptr = load i8*, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*) + ; TCB-NEXT: %unsafe_stack_static_top = getelementptr i8, i8* %unsafe_stack_ptr, i32 -16 + ; TCB-NEXT: store i8* %unsafe_stack_static_top, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*) %retval = alloca i32, align 4 %a = alloca i32, align 4 %j = alloca i32*, align 8 @@ -17,6 +21,7 @@ %add = add nsw i32 %0, 1 store i32 %add, i32* %a, align 4 store i32* %a, i32** %j, align 8 + ; TCB: store i8* %unsafe_stack_ptr, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*) ret void }