[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-12-03 Thread Ahmed Bougacha via Phabricator via cfe-commits
ab added a comment.

Thanks Tim!  f77c948d56b 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87095

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-12-03 Thread Ahmed Bougacha via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf77c948d56b0: [Triple][MachO] Define arm64e, an 
AArch64 subarch for Pointer Auth. (authored by ab).

Changed prior to commit:
  https://reviews.llvm.org/D87095?vs=292557=309261#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87095

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arclite-link.c
  clang/test/Driver/target-triple-deployment.c
  clang/test/Preprocessor/arm64e.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/BinaryFormat/MachO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/LTOModule.cpp
  llvm/lib/Object/MachOObjectFile.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  llvm/test/MC/AArch64/arm64e-subtype.s
  llvm/test/MC/AArch64/arm64e.s
  llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
  llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
  llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
  llvm/test/tools/llvm-readobj/macho-arm64e.test
  llvm/unittests/ADT/TripleTest.cpp
  llvm/utils/UpdateTestChecks/asm.py

Index: llvm/utils/UpdateTestChecks/asm.py
===
--- llvm/utils/UpdateTestChecks/asm.py
+++ llvm/utils/UpdateTestChecks/asm.py
@@ -336,6 +336,7 @@
   'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
   'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
   'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
+  'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
   'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),
Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -1590,5 +1590,10 @@
 Triple T = Triple("aarch64_be");
 EXPECT_EQ(Triple::aarch64_be, T.getArch());
   }
+  {
+Triple T = Triple("arm64e");
+EXPECT_EQ(Triple::aarch64, T.getArch());
+EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
+  }
 }
 } // end anonymous namespace
Index: llvm/test/tools/llvm-readobj/macho-arm64e.test
===
--- /dev/null
+++ llvm/test/tools/llvm-readobj/macho-arm64e.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -h %t.o | FileCheck %s
+
+# CHECK: Magic: Magic64 (0xFEEDFACF)
+# CHECK: CpuType: Arm64 (0x10C)
+# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E (0x2)
+
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x010C
+  cpusubtype:  0x0002
+  filetype:0x0001
+  ncmds:   0
+  sizeofcmds:  0
+  flags:   0x
+  reserved:0x
Index: llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
===
--- llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
+++ llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
@@ -22,7 +22,7 @@
 # CHECK-NEXT: offset 16384
 # CHECK-NEXT: size 384
 # CHECK-NEXT: align 2^14 (16384)
-# CHECK-NEXT: architecture
+# CHECK-NEXT: architecture arm64e
 # CHECK-NEXT: cputype CPU_TYPE_ARM64
 # CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E
 # CHECK-NEXT: capabilities 0x0
Index: llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
@@ -0,0 +1,17 @@
+; RUN: llc -O0 %s -filetype=obj -o - \
+; RUN:   | llvm-dwarfdump -arch arm64e - | FileCheck %s
+; CHECK: file format Mach-O arm64
+
+source_filename = "/tmp/empty.c"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64e-apple-ios"
+
+!llvm.module.flags = !{!1, !2, !3, !4}
+!llvm.dbg.cu = !{!5}
+
+!1 = !{i32 2, !"Dwarf Version", i32 4}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 1, !"wchar_size", i32 4}
+!4 = !{i32 7, !"PIC Level", i32 2}
+!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!6 = !DIFile(filename: "/tmp/empty.c", directory: "/Volumes/Data/llvm-project")
Index: llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
===

[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-23 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added a comment.

I had a look through this and everything seemed to be in place. I think the ABI 
versioning is probably sufficient to prevent surprises and land this now, to 
avoid churn in the rest of the code. If more is really needed, we could add a 
temporary warning ("incomplete ABI") to the Clang driver.


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

https://reviews.llvm.org/D87095

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-17 Thread Ahmed Bougacha via Phabricator via cfe-commits
ab updated this revision to Diff 292557.
ab added a comment.
Herald added a subscriber: pzheng.

Reformat ValidArchs.


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

https://reviews.llvm.org/D87095

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arclite-link.c
  clang/test/Driver/target-triple-deployment.c
  clang/test/Preprocessor/arm64e.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/BinaryFormat/MachO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/LTOModule.cpp
  llvm/lib/Object/MachOObjectFile.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  llvm/test/MC/AArch64/arm64e-subtype.s
  llvm/test/MC/AArch64/arm64e.s
  llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
  llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
  llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
  llvm/test/tools/llvm-readobj/macho-arm64e.test
  llvm/unittests/ADT/TripleTest.cpp
  llvm/utils/UpdateTestChecks/asm.py

Index: llvm/utils/UpdateTestChecks/asm.py
===
--- llvm/utils/UpdateTestChecks/asm.py
+++ llvm/utils/UpdateTestChecks/asm.py
@@ -335,6 +335,7 @@
   'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
   'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
   'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
+  'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
   'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),
Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -1590,5 +1590,10 @@
 Triple T = Triple("aarch64_be");
 EXPECT_EQ(Triple::aarch64_be, T.getArch());
   }
+  {
+Triple T = Triple("arm64e");
+EXPECT_EQ(Triple::aarch64, T.getArch());
+EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
+  }
 }
 } // end anonymous namespace
Index: llvm/test/tools/llvm-readobj/macho-arm64e.test
===
--- /dev/null
+++ llvm/test/tools/llvm-readobj/macho-arm64e.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -h %t.o | FileCheck %s
+
+# CHECK: Magic: Magic64 (0xFEEDFACF)
+# CHECK: CpuType: Arm64 (0x10C)
+# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E (0x2)
+
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x010C
+  cpusubtype:  0x0002
+  filetype:0x0001
+  ncmds:   0
+  sizeofcmds:  0
+  flags:   0x
+  reserved:0x
Index: llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
===
--- llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
+++ llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
@@ -22,7 +22,7 @@
 # CHECK-NEXT: offset 16384
 # CHECK-NEXT: size 384
 # CHECK-NEXT: align 2^14 (16384)
-# CHECK-NEXT: architecture
+# CHECK-NEXT: architecture arm64e
 # CHECK-NEXT: cputype CPU_TYPE_ARM64
 # CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E
 # CHECK-NEXT: capabilities 0x0
Index: llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
@@ -0,0 +1,17 @@
+; RUN: llc -O0 %s -filetype=obj -o - \
+; RUN:   | llvm-dwarfdump -arch arm64e - | FileCheck %s
+; CHECK: file format Mach-O arm64
+
+source_filename = "/tmp/empty.c"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64e-apple-ios"
+
+!llvm.module.flags = !{!1, !2, !3, !4}
+!llvm.dbg.cu = !{!5}
+
+!1 = !{i32 2, !"Dwarf Version", i32 4}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 1, !"wchar_size", i32 4}
+!4 = !{i32 7, !"PIC Level", i32 2}
+!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!6 = !DIFile(filename: "/tmp/empty.c", directory: "/Volumes/Data/llvm-project")
Index: llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
===
--- llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
+++ llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
@@ -1,16 +1,39 @@
 // RUN: llvm-mc -triple arm64-apple-macos10.10.2 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | 

[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-04 Thread James Henderson via Phabricator via cfe-commits
jhenderson added inline comments.



Comment at: llvm/lib/Object/MachOObjectFile.cpp:2745
 ArrayRef MachOObjectFile::getValidArchs() {
-  static const std::array validArchs = {{
+  static const std::array validArchs = {{
   "i386",   "x86_64", "x86_64h",  "armv4t",  "arm","armv5e",

Nit: it's probably worth fixing these two Linter issues, since this function is 
small anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87095

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-03 Thread Ahmed Bougacha via Phabricator via cfe-commits
ab added a comment.

In D87095#2255010 , @pcc wrote:

> But I was wondering: shouldn't this be the *last* patch? I was imagining that 
> you would first upstream support for the `-fptrauth-*` flags, and then at the 
> end you would add an `arm64e` subarch that turns them on by default. 
> Otherwise the upstream compiler will temporarily produce ABI-incompatible 
> objects when targeting `arm64e`.

Good point, you're right.  ABI compatibility has obviously been a major issue 
as we keep iterating on this, so we added the concept of ptrauth ABI versions 
to the arm64e mach-o cpusubtype.  With this patch, upstream clang produces 
"unversioned" binaries, which are rejected on macOS11/iOS14.  Once we're done 
upstreaming, I'll make the final patch to match the ABI version.  In the 
meantime, that means upstream can't produce anything that runs on macOS, which 
should avoid this problem (and lets us use arm64e checks in the remaining 
patches, though I can obviously extract that to have the patches done the other 
way)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87095

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-03 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Hi, thanks for getting started on upstreaming this!

But I was wondering: shouldn't this be the *last* patch? I was imagining that 
you would first upstream support for the `-fptrauth-*` flags, and then at the 
end you would add an `arm64e` subarch that turns them on by default. Otherwise 
the upstream compiler will temporarily produce ABI-incompatible objects when 
targeting `arm64e`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87095

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-03 Thread Ahmed Bougacha via Phabricator via cfe-commits
ab created this revision.
Herald added subscribers: cfe-commits, danielkiss, cmtice, rupprecht, 
dexonsmith, steven_wu, hiraditya, kristof.beyls, arichardson.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added projects: clang, LLVM.
ab requested review of this revision.
Herald added a subscriber: ormris.

This is the first of many Pointer Authentication-related patches we're happy to 
finally upstream =]
For a high-level overview, see our llvm-dev RFC: 
http://lists.llvm.org/pipermail/llvm-dev/2019-October/136091.html, as well as 
the devmtg talk we did at the same time last year.
For concrete code that builds on this, see the staging PR in 
apple/llvm-project: https://github.com/apple/llvm-project/pull/14.  Though 
we've made changes downstream since then, the general concepts and added 
constructs are mostly identical.

Per commit message:

  This also teaches MachO writers/readers about the MachO cpu subtype,
  beyond the minimal subtype reader support present at the moment.
  
  This also defines a preprocessor macro to allow users to distinguish
  __arm64__ from __arm64e__.
  
  arm64e defaults to an "apple-a12" CPU, which supports v8.3a, allowing
  pointer-authentication codegen.
  It also currently defaults to ios14+ and macos11+.

If it helps, we can obviously split this patch further, but I feel like this 
all belongs together, as the core boilerplate needed for new (darwin) targets.

Note that this adds a `Triple::isArm64e()`, which is a bit of a departure from 
prior subarches, in part because we check it more often.  The obvious 
alternative would be to compare `Triple::getArchName()` with "arm64e";  I'm 
fine with either.   However, I would like to preserve the "arm64e" naming, as 
we refer to that extensively in Darwin-land.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87095

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arclite-link.c
  clang/test/Driver/target-triple-deployment.c
  clang/test/Preprocessor/arm64e.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/BinaryFormat/MachO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/LTOModule.cpp
  llvm/lib/Object/MachOObjectFile.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  llvm/test/MC/AArch64/arm64e-subtype.s
  llvm/test/MC/AArch64/arm64e.s
  llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
  llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
  llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
  llvm/test/tools/llvm-readobj/macho-arm64e.test
  llvm/unittests/ADT/TripleTest.cpp
  llvm/utils/UpdateTestChecks/asm.py

Index: llvm/utils/UpdateTestChecks/asm.py
===
--- llvm/utils/UpdateTestChecks/asm.py
+++ llvm/utils/UpdateTestChecks/asm.py
@@ -335,6 +335,7 @@
   'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
   'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
   'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
+  'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
   'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),
Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -1590,5 +1590,10 @@
 Triple T = Triple("aarch64_be");
 EXPECT_EQ(Triple::aarch64_be, T.getArch());
   }
+  {
+Triple T = Triple("arm64e");
+EXPECT_EQ(Triple::aarch64, T.getArch());
+EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
+  }
 }
 } // end anonymous namespace
Index: llvm/test/tools/llvm-readobj/macho-arm64e.test
===
--- /dev/null
+++ llvm/test/tools/llvm-readobj/macho-arm64e.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -h %t.o | FileCheck %s
+
+# CHECK: Magic: Magic64 (0xFEEDFACF)
+# CHECK: CpuType: Arm64 (0x10C)
+# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E (0x2)
+
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x010C
+  cpusubtype:  0x0002
+  filetype:0x0001
+  ncmds:   0
+  sizeofcmds:  0
+  flags:   0x
+  reserved:0x
Index: llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
===
--- llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
+++