[PATCH] D83812: [clang][RelativeVTablesABI] Do not emit stubs for architectures that support a PLT relocation

2020-07-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83812



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


[PATCH] D83812: [clang][RelativeVTablesABI] Do not emit stubs for architectures that support a PLT relocation

2020-07-20 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 279354.
leonardchan marked an inline comment as done.
leonardchan added a comment.

Add a method to `TargetCodeGenInfo` the returns if the target supports PC 
relative PLT relocations,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83812

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inline-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inlined-key-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/no-stub-when-dso-local.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/override-pure-virtual-method.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/overriden-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-flag.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp

Index: clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
===
--- clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
+++ clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
@@ -6,8 +6,6 @@
 // CHECK: %class.B = type { %class.A }
 // CHECK: %"class.std::type_info" = type { i32 (...)**, i8* }
 
-// CHECK: $_ZN1A3fooEv.stub = comdat any
-// CHECK: $_ZN1B3fooEv.stub = comdat any
 // CHECK: $_ZTI1A.rtti_proxy = comdat any
 // CHECK: $_ZTI1B.rtti_proxy = comdat any
 
Index: clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
@@ -0,0 +1,31 @@
+// Stubs shouldn't be used on architectures we know support 32-bit PLT relocations.
+
+// RUN: %clang_cc1 %s -triple=aarch64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,NOSTUB
+// RUN: %clang_cc1 %s -triple=x86_64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,NOSTUB
+// RUN: %clang_cc1 %s -triple=riscv64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,STUB
+
+// We should be emitting comdats for each of the virtual function stubs and RTTI proxies
+// NOSTUB-NOT: $_ZN1A3fooEv.stub
+// STUB:  $_ZN1A3fooEv.stub = comdat any
+
+// STUB: @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 0, i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3fooEv.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [3 x i32] }, { [3 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4
+// NOSTUB: @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 0, i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3fooEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [3 x i32] }, { [3 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4
+
+// NOSTUB-NOT: @_ZN1A3fooEv.stub
+
+// Stub is in its own comdat group.
+// STUB:  define hidden void @_ZN1A3fooEv.stub(%class.A* nocapture %0) unnamed_addr #{{[0-9]+}} comdat
+// STUB-NEXT: entry:
+// STUB-NEXT:   ret void
+// STUB-NEXT: }
+
+class A {
+public:
+  virtual void foo();
+};
+
+void A::foo() {}
+
+void A_foo(A *a) {
+  a->foo();
+}
Index: clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp
===
--- clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp
+++ clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp
@@ -1,7 +1,7 @@
 // If the linkage of the class is internal, then the stubs and proxies should
 // also be internally linked.
 
-// RUN: %clang_cc1 %s -triple=x86_64-unknown-fuchsia -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s
+// RUN: %clang_cc1 %s -triple=riscv64 -S -o - -emit-llvm 

[PATCH] D83812: [clang][RelativeVTablesABI] Do not emit stubs for architectures that support a PLT relocation

2020-07-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGVTables.cpp:633
+  auto Arch = targetTriple.getArch();
+  if (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::x86_64)
+return false;

Could you add a method to TargetCodeGenInfo for this instead of hard-coding a 
list of architectures here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83812



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


[PATCH] D83812: [clang][RelativeVTablesABI] Do not emit stubs for architectures that support a PLT relocation

2020-07-14 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: rjmccall, pcc, phosek, mcgrathr, rsmith.
leonardchan added a project: clang.
Herald added subscribers: s.egerton, simoncook, kristof.beyls.
Herald added a reviewer: jdoerfert.

Now that LLVM and LLD support the `R_AARCH64_PLT32` relocation, the relative 
vtables ABI does not require emitting dso_local stubs for AArch64. The stubs 
were needed initially because we couldn't guarantee a static relocation for a 
function slot in the vtable if the function was not guaranteed to be dso_local. 
Not emitting these stubs saves a lot of extra binary size.

This patch adds a helper function which checks if stubs should be added and 
updates various tests that initially used stubs when targeting AArch64. Most of 
these tests should not be checking for stubs anymore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83812

Files:
  clang/lib/CodeGen/CGVTables.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inline-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inlined-key-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/no-stub-when-dso-local.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/override-pure-virtual-method.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/overriden-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-flag.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp

Index: clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
===
--- clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
+++ clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
@@ -6,8 +6,6 @@
 // CHECK: %class.B = type { %class.A }
 // CHECK: %"class.std::type_info" = type { i32 (...)**, i8* }
 
-// CHECK: $_ZN1A3fooEv.stub = comdat any
-// CHECK: $_ZN1B3fooEv.stub = comdat any
 // CHECK: $_ZTI1A.rtti_proxy = comdat any
 // CHECK: $_ZTI1B.rtti_proxy = comdat any
 
Index: clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/RelativeVTablesABI/stub-usage.cpp
@@ -0,0 +1,31 @@
+// Stubs shouldn't be used on architectures we know support 32-bit PLT relocations.
+
+// RUN: %clang_cc1 %s -triple=aarch64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,NOSTUB
+// RUN: %clang_cc1 %s -triple=x86_64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,NOSTUB
+// RUN: %clang_cc1 %s -triple=riscv64 -fno-rtti -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s --check-prefixes CHECK,STUB
+
+// We should be emitting comdats for each of the virtual function stubs and RTTI proxies
+// NOSTUB-NOT: $_ZN1A3fooEv.stub
+// STUB:  $_ZN1A3fooEv.stub = comdat any
+
+// STUB: @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 0, i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3fooEv.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [3 x i32] }, { [3 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4
+// NOSTUB: @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 0, i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3fooEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [3 x i32] }, { [3 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4
+
+// NOSTUB-NOT: @_ZN1A3fooEv.stub
+
+// Stub is in its own comdat group.
+// STUB:  define hidden void @_ZN1A3fooEv.stub(%class.A* nocapture %0) unnamed_addr #{{[0-9]+}} comdat
+// STUB-NEXT: entry:
+// STUB-NEXT:   ret void
+// STUB-NEXT: }
+
+class A {
+public:
+  virtual void foo();
+};
+
+void A::foo() {}
+
+void A_foo(A *a) {
+  a->foo();
+}
Index: clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp