Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set dllstorage on ObjectiveC ivar offsets #77385

Merged
merged 1 commit into from Jan 9, 2024

Conversation

qmfrederik
Copy link
Contributor

Mark instance variable offset symbols with dllexport/dllimport if they are not hidden and the interface declaration is marked with dllexport/dllimport, when using the GNUstep 2.x ABI.

/cc @davidchisnall

Copy link

github-actions bot commented Jan 8, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Jan 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 8, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Frederik Carlier (qmfrederik)

Changes

Mark instance variable offset symbols with dllexport/dllimport if they are not hidden and the interface declaration is marked with dllexport/dllimport, when using the GNUstep 2.x ABI.

/cc @davidchisnall


Full diff: https://github.com/llvm/llvm-project/pull/77385.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+2)
  • (modified) clang/test/CodeGenObjC/dllstorage.m (+29)
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..9443fecf9b7946 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1851,6 +1851,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
                     llvm::GlobalValue::HiddenVisibility :
                     llvm::GlobalValue::DefaultVisibility;
         OffsetVar->setVisibility(ivarVisibility);
+        if (ivarVisibility != llvm::GlobalValue::HiddenVisibility)
+          CGM.setGVProperties(OffsetVar, OID->getClassInterface());
         ivarBuilder.add(OffsetVar);
         // Ivar size
         ivarBuilder.addInt(Int32Ty,
diff --git a/clang/test/CodeGenObjC/dllstorage.m b/clang/test/CodeGenObjC/dllstorage.m
index 64ba21f9769ae2..0dbf1881caa9c0 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-NF %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=objfw -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-FW %s
 
@@ -12,6 +13,8 @@ + (instancetype) new;
 // CHECK-IR-DAG: @"OBJC_METACLASS_$_I" = external dllimport global %struct._class_t
 // CHECK-IR-DAG: @"OBJC_CLASS_$_I" = external dllimport global %struct._class_t
 
+// CHECK-NF-DAG: @"$_OBJC_CLASS_I" = external dllimport global ptr
+
 __declspec(dllexport)
 @interface J : I
 @end
@@ -22,6 +25,9 @@ @interface J : I
 // CHECK-FW-DAG: @_OBJC_METACLASS_J = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_J = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_J" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_J" = dllexport global
+
 @implementation J {
   id _ivar;
 }
@@ -29,6 +35,8 @@ @implementation J {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.\01" = hidden global i32
+
 @interface K : J
 @end
 
@@ -38,6 +46,9 @@ @interface K : J
 // CHECK-FW-DAG: @_OBJC_METACLASS_K = dso_local global
 // CHECK-FW-DAG: @_OBJC_CLASS_K = dso_local global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_K" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_K" = global
+
 @implementation K {
   id _ivar;
 }
@@ -45,6 +56,8 @@ @implementation K {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.\01" = hidden global i32
+
 __declspec(dllexport)
 @interface L : K
 @end
@@ -55,6 +68,9 @@ @interface L : K
 // CHECK-FW-DAG: @_OBJC_METACLASS_L = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_L = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_L" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_L" = dllexport global
+
 @implementation L {
   id _none;
 
@@ -78,6 +94,12 @@ @implementation L {
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._none.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._public.\01" = dso_local dllexport global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._protected.\01" = dso_local dllexport global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._package.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._private.\01" = hidden global i32
+
 __declspec(dllimport)
 @interface M : I {
   @public
@@ -89,6 +111,9 @@ @interface M : I {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
+// CHECK-NF-DAG: @"$_OBJC_REF_CLASS_M" = external dllimport global ptr
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32
+
 __declspec(dllexport)
 __attribute__((__objc_exception__))
 @interface N : I
@@ -97,6 +122,8 @@ @interface N : I
 // CHECK-FW-DAG: @_OBJC_METACLASS_N = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_N = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_CLASS_N" = dllexport global
+
 @implementation N : I
 @end
 
@@ -124,6 +151,8 @@ id f(Q *q) {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32
+
 int g(void) {
   @autoreleasepool {
     M *mi = [M new];

@qmfrederik
Copy link
Contributor Author

Thanks @davidchisnall . Do you plan to get this merged?

@davidchisnall davidchisnall reopened this Jan 9, 2024
@davidchisnall
Copy link
Contributor

I didn’t intentional hit close, not sure what happened there.

@davidchisnall davidchisnall merged commit b81ba52 into llvm:main Jan 9, 2024
9 checks passed
@qmfrederik
Copy link
Contributor Author

No worries, thanks! :-)

justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
Mark instance variable offset symbols with `dllexport`/`dllimport` if
they are not hidden and the interface declaration is marked with
`dllexport`/`dllimport`, when using the GNUstep 2.x ABI.

/cc @davidchisnall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants