[compiler-rt] [compiler-rt] Do not assume pthread_key_t to be a scalar type. (PR #70786)

Carlo Bramini via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 03:59:47 PDT 2023


https://github.com/carlo-bramini created https://github.com/llvm/llvm-project/pull/70786

`pthread_key_t` must be assumed to be an opaque object.
Some platforms have declare this type as an alias of a scalar type, like `int` or `long`, but others do not.
When compiling compiler-rt for those systems, an error is returned because a structure and a scalar type are not the same thing. CYGWIN is an example of platform showing this error.

See also issue #62717 for more details.

The patch does not produce any difference in compiled code when `pthread_key_t` is a scalar type, as I verified with Debian 11.
On the systems with different declaration of this type, the patch fixes two of the four errors signaled into issue #62717.


>From 65b7f4ca2f6e7e5103b0c1ffd1727bdd1d59c91b Mon Sep 17 00:00:00 2001
From: Carlo Bramini <30959007+carlo-bramini at users.noreply.github.com>
Date: Tue, 31 Oct 2023 11:57:31 +0100
Subject: [PATCH] [compiler-rt] Do not assume pthread_key_t to be a scalar
 type.

pthread_key_t must be assumed to be an opaque object.
Some platforms have declare this type as an alias of a scalar type, like int or long, but others do not. When compiling compiler-rt for those systems, an error is returned because a structure and a scalar type are not the same thing.
CYGWIN is an example of platform showing this error.

See also issue #62717 for more details.

The patch does not produce any difference in compiled code when pthread_key_t is a scalar type, as I verified with Debian 11.
On the systems with different declaration of this type, the patch fixes two of the four errors signaled into issue #62717.
---
 compiler-rt/lib/orc/elfnix_platform.cpp | 2 +-
 compiler-rt/lib/orc/macho_platform.cpp  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/orc/elfnix_platform.cpp b/compiler-rt/lib/orc/elfnix_platform.cpp
index c087e71038f9504..3c80a7a150bceb0 100644
--- a/compiler-rt/lib/orc/elfnix_platform.cpp
+++ b/compiler-rt/lib/orc/elfnix_platform.cpp
@@ -72,7 +72,7 @@ Error runInitArray(const std::vector<ExecutorAddrRange> &InitArraySections,
 }
 
 struct TLSInfoEntry {
-  unsigned long Key = 0;
+  pthread_key_t Key = { 0 };
   unsigned long DataAddress = 0;
 };
 
diff --git a/compiler-rt/lib/orc/macho_platform.cpp b/compiler-rt/lib/orc/macho_platform.cpp
index 679163140e70045..d0058f36be52abd 100644
--- a/compiler-rt/lib/orc/macho_platform.cpp
+++ b/compiler-rt/lib/orc/macho_platform.cpp
@@ -143,7 +143,7 @@ class SPSSerializationTraits<SPSUnwindSectionInfo, UnwindSectionInfo> {
 namespace {
 struct TLVDescriptor {
   void *(*Thunk)(TLVDescriptor *) = nullptr;
-  unsigned long Key = 0;
+  pthread_key_t Key = { 0 };
   unsigned long DataAddress = 0;
 };
 



More information about the llvm-commits mailing list