[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread Xiang Zhang via Phabricator via cfe-commits
xiangzhangllvm added a comment.

Hello rsmith, 
first, very sorry for have committed this patch before your reply, I waited 10 
days, I thought you have agreed it. 
I think the  linux-ABI can be the specification of this head file. The context 
of this cet.h is according to the linux ABI about CET.
We explained in which case we should use this cet.h file. (line 2-4)
tks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread H.J Lu via Phabricator via cfe-commits
hjl.tools added a comment.

In D79617#2045552 , @rsmith wrote:

> I would like a specification for this header to be added somewhere. We 
> shouldn't be implementing random things with no specification. (Suppose 
> someone claims that our `` is wrong in some way. How would we know 
> whether they're right?)
>
> Ideally, I'd also like this header to be installed somewhere where we look 
> for assembler-with-cpp preprocessing but not for regular compilation; it 
> doesn't make sense to me to pollute the header namespace for all C and C++ 
> compilations with a header that is not meaningful in C and C++. But knowing 
> whether that change is correct depends on having, you know, a specification.


 from GCC is as close as you can get for a reference 
implementation/specification.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I would like a specification for this header to be added somewhere. We 
shouldn't be implementing random things with no specification. (Suppose someone 
claims that our `` is wrong in some way. How would we know whether 
they're right?)

Ideally, I'd also like this header to be installed somewhere where we look for 
assembler-with-cpp preprocessing but not for regular compilation; it doesn't 
make sense to me to pollute the header namespace for all C and C++ compilations 
with a header that is not meaningful in C and C++. But knowing whether that 
change is correct depends on having, you know, a specification.

I don't think we should be porting this to Clang 10. It seems clear that this 
is a new feature, not a bug fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread Xiang Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcc0c894f38f: Add cet.h for writing CET-enabled assembly 
code (authored by xiangzhangllvm).

Changed prior to commit:
  https://reviews.llvm.org/D79617?vs=264772=264799#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/cet.h
  clang/test/CodeGen/asm-cet.S

Index: clang/test/CodeGen/asm-cet.S
===
--- /dev/null
+++ clang/test/CodeGen/asm-cet.S
@@ -0,0 +1,27 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang --target=x86_64-pc-linux -fcf-protection  -include cet.h -c %s -o - | llvm-readelf -n | FileCheck %s
+// RUN: %clang --target=x86_64-pc-linux -include cet.h -c %s -o - | llvm-readelf -S | FileCheck %s --check-prefixes=NOCET
+// RUN: %clang --target=x86_64-pc-linux -include cet.h -S %s -o - | FileCheck %s --check-prefixes=NOENDBR
+// RUN: %clang --target=x86_64-pc-linux -fcf-protection  -include cet.h -S %s -o - | FileCheck %s --check-prefixes=ENDBR64
+
+// RUN: %clang --target=i386-pc-linux -fcf-protection  -include cet.h -c %s -o - | llvm-readelf -n | FileCheck %s
+// RUN: %clang --target=i386-pc-linux -include cet.h -c %s -o - | llvm-readelf -S | FileCheck %s --check-prefixes=NOCET
+// RUN: %clang --target=i386-pc-linux -include cet.h -S %s -o - | FileCheck %s --check-prefixes=NOENDBR
+// RUN: %clang --target=i386-pc-linux -fcf-protection  -include cet.h -S %s -o - | FileCheck %s --check-prefixes=ENDBR32
+
+// CHECK: IBT, SHSTK
+
+// NOCET: Section Headers
+// NOCET-NOT: .note.gnu.property
+
+// NOENDBR:   foo
+// NOENDBR-NOT: endbr
+
+// ENDBR64: endbr64
+// ENDBR32: endbr32
+.text
+.globl  foo
+.type   foo, @function
+foo:
+_CET_ENDBR
+ret
Index: clang/lib/Headers/cet.h
===
--- /dev/null
+++ clang/lib/Headers/cet.h
@@ -0,0 +1,66 @@
+/*===-- cet.h -Control-flow Enforcement Technology  feature ===
+ * Add x86 feature with IBT and/or SHSTK bits to ELF program property if they
+ * are enabled. Otherwise, contents in this header file are unused. This file
+ * is mainly design for assembly source code which want to enable CET.
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __CET_H
+#define __CET_H
+
+#ifdef __ASSEMBLER__
+
+#ifndef __CET__
+# define _CET_ENDBR
+#endif
+
+#ifdef __CET__
+
+# ifdef __LP64__
+#  if __CET__ & 0x1
+#define _CET_ENDBR endbr64
+#  else
+#define _CET_ENDBR
+#  endif
+# else
+#  if __CET__ & 0x1
+#define _CET_ENDBR endbr32
+#  else
+#define _CET_ENDBR
+#  endif
+# endif
+
+
+#  ifdef __LP64__
+#   define __PROPERTY_ALIGN 3
+#  else
+#   define __PROPERTY_ALIGN 2
+#  endif
+
+	.pushsection ".note.gnu.property", "a"
+	.p2align __PROPERTY_ALIGN
+	.long 1f - 0f		/* name length.  */
+	.long 4f - 1f		/* data length.  */
+	/* NT_GNU_PROPERTY_TYPE_0.   */
+	.long 5			/* note type.  */
+0:
+	.asciz "GNU"		/* vendor name.  */
+1:
+	.p2align __PROPERTY_ALIGN
+	/* GNU_PROPERTY_X86_FEATURE_1_AND.  */
+	.long 0xc002	/* pr_type.  */
+	.long 3f - 2f		/* pr_datasz.  */
+2:
+	/* GNU_PROPERTY_X86_FEATURE_1_XXX.  */
+	.long __CET__
+3:
+	.p2align __PROPERTY_ALIGN
+4:
+	.popsection
+#endif
+#endif
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -46,6 +46,7 @@
   __clang_cuda_math_forward_declares.h
   __clang_cuda_runtime_wrapper.h
   cetintrin.h
+  cet.h
   cldemoteintrin.h
   clzerointrin.h
   cpuid.h
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-18 Thread Xiang Zhang via Phabricator via cfe-commits
xiangzhangllvm added a comment.

@rsmith


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-18 Thread Tom Stellard via Phabricator via cfe-commits
tstellar reopened this revision.
tstellar added a comment.
This revision is now accepted and ready to land.

Did @rsmith ever approve this patch?  I was following the discussion at 
llvm.org/PR45484 but did not see an explicit approval.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-18 Thread Xiang Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7e84ff24a5f: Add cet.h for writing CET-enabled assembly 
code (authored by xiangzhangllvm).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79617/new/

https://reviews.llvm.org/D79617

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/cet.h
  clang/test/CodeGen/asm-cet.S

Index: clang/test/CodeGen/asm-cet.S
===
--- /dev/null
+++ clang/test/CodeGen/asm-cet.S
@@ -0,0 +1,26 @@
+// RUN: %clang --target=x86_64-pc-linux -fcf-protection  -include cet.h -c %s -o - | llvm-readelf -n | FileCheck %s
+// RUN: %clang --target=x86_64-pc-linux -include cet.h -c %s -o - | llvm-readelf -S | FileCheck %s --check-prefixes=NOCET
+// RUN: %clang --target=x86_64-pc-linux -include cet.h -S %s -o - | FileCheck %s --check-prefixes=NOENDBR
+// RUN: %clang --target=x86_64-pc-linux -fcf-protection  -include cet.h -S %s -o - | FileCheck %s --check-prefixes=ENDBR64
+
+// RUN: %clang --target=i386-pc-linux -fcf-protection  -include cet.h -c %s -o - | llvm-readelf -n | FileCheck %s
+// RUN: %clang --target=i386-pc-linux -include cet.h -c %s -o - | llvm-readelf -S | FileCheck %s --check-prefixes=NOCET
+// RUN: %clang --target=i386-pc-linux -include cet.h -S %s -o - | FileCheck %s --check-prefixes=NOENDBR
+// RUN: %clang --target=i386-pc-linux -fcf-protection  -include cet.h -S %s -o - | FileCheck %s --check-prefixes=ENDBR32
+
+// CHECK: IBT, SHSTK
+
+// NOCET: Section Headers
+// NOCET-NOT: .note.gnu.property
+
+// NOENDBR:   foo
+// NOENDBR-NOT: endbr
+
+// ENDBR64: endbr64
+// ENDBR32: endbr32
+.text
+.globl  foo
+.type   foo, @function
+foo:
+_CET_ENDBR
+ret
Index: clang/lib/Headers/cet.h
===
--- /dev/null
+++ clang/lib/Headers/cet.h
@@ -0,0 +1,66 @@
+/*===-- cet.h -Control-flow Enforcement Technology  feature ===
+ * Add x86 feature with IBT and/or SHSTK bits to ELF program property if they
+ * are enabled. Otherwise, contents in this header file are unused. This file
+ * is mainly design for assembly source code which want to enable CET.
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __CET_H
+#define __CET_H
+
+#ifdef __ASSEMBLER__
+
+#ifndef __CET__
+# define _CET_ENDBR
+#endif
+
+#ifdef __CET__
+
+# ifdef __LP64__
+#  if __CET__ & 0x1
+#define _CET_ENDBR endbr64
+#  else
+#define _CET_ENDBR
+#  endif
+# else
+#  if __CET__ & 0x1
+#define _CET_ENDBR endbr32
+#  else
+#define _CET_ENDBR
+#  endif
+# endif
+
+
+#  ifdef __LP64__
+#   define __PROPERTY_ALIGN 3
+#  else
+#   define __PROPERTY_ALIGN 2
+#  endif
+
+	.pushsection ".note.gnu.property", "a"
+	.p2align __PROPERTY_ALIGN
+	.long 1f - 0f		/* name length.  */
+	.long 4f - 1f		/* data length.  */
+	/* NT_GNU_PROPERTY_TYPE_0.   */
+	.long 5			/* note type.  */
+0:
+	.asciz "GNU"		/* vendor name.  */
+1:
+	.p2align __PROPERTY_ALIGN
+	/* GNU_PROPERTY_X86_FEATURE_1_AND.  */
+	.long 0xc002	/* pr_type.  */
+	.long 3f - 2f		/* pr_datasz.  */
+2:
+	/* GNU_PROPERTY_X86_FEATURE_1_XXX.  */
+	.long __CET__
+3:
+	.p2align __PROPERTY_ALIGN
+4:
+	.popsection
+#endif
+#endif
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -46,6 +46,7 @@
   __clang_cuda_math_forward_declares.h
   __clang_cuda_runtime_wrapper.h
   cetintrin.h
+  cet.h
   cldemoteintrin.h
   clzerointrin.h
   cpuid.h
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits