[compiler-rt] [PAC][compiler-rt] Do not use `__has_feature` with non-clang (PR #102154)

Daniil Kovalev via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 07:29:37 PDT 2024


https://github.com/kovdan01 created https://github.com/llvm/llvm-project/pull/102154

See compile failure with gcc:
https://github.com/llvm/llvm-project/pull/96478#issuecomment-2271358148

The `__has_feature` directive was not supported in gcc until ~ Nov 2023 https://github.com/gcc-mirror/gcc/commit/06280a906cb3dc80cf5e07cf3335b758848d488d

>From d1d19826cc23c43759efd4bd7db2a3386466a33d Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Tue, 6 Aug 2024 17:25:18 +0300
Subject: [PATCH] [PAC][compiler-rt] Do not use `__has_feature` with non-clang

See compile failure with gcc:
https://github.com/llvm/llvm-project/pull/96478#issuecomment-2271358148

The `__has_feature` directive was not supported in gcc until ~ Nov 2023
https://github.com/gcc-mirror/gcc/commit/06280a906cb3dc80cf5e07cf3335b758848d488d
---
 compiler-rt/lib/builtins/crtbegin.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/compiler-rt/lib/builtins/crtbegin.c b/compiler-rt/lib/builtins/crtbegin.c
index d5f7756308b09..1f61a0475186c 100644
--- a/compiler-rt/lib/builtins/crtbegin.c
+++ b/compiler-rt/lib/builtins/crtbegin.c
@@ -54,6 +54,7 @@ static void __attribute__((used)) __do_init(void) {
 }
 
 #ifdef CRT_HAS_INITFINI_ARRAY
+#ifdef __clang__
 #if __has_feature(ptrauth_init_fini)
 // TODO: use __ptrauth-qualified pointers when they are supported on clang side
 #if __has_feature(ptrauth_init_fini_address_discrimination)
@@ -70,6 +71,10 @@ __attribute__((section(".init_array"), used)) static void *__init =
 __attribute__((section(".init_array"),
                used)) static void (*__init)(void) = __do_init;
 #endif
+#else
+__attribute__((section(".init_array"),
+               used)) static void (*__init)(void) = __do_init;
+#endif
 #elif defined(__i386__) || defined(__x86_64__)
 __asm__(".pushsection .init,\"ax\", at progbits\n\t"
         "call __do_init\n\t"
@@ -125,6 +130,7 @@ static void __attribute__((used)) __do_fini(void) {
 }
 
 #ifdef CRT_HAS_INITFINI_ARRAY
+#ifdef __clang__
 #if __has_feature(ptrauth_init_fini)
 // TODO: use __ptrauth-qualified pointers when they are supported on clang side
 #if __has_feature(ptrauth_init_fini_address_discrimination)
@@ -141,6 +147,10 @@ __attribute__((section(".fini_array"), used)) static void *__fini =
 __attribute__((section(".fini_array"),
                used)) static void (*__fini)(void) = __do_fini;
 #endif
+#else
+__attribute__((section(".fini_array"),
+               used)) static void (*__fini)(void) = __do_fini;
+#endif
 #elif defined(__i386__) || defined(__x86_64__)
 __asm__(".pushsection .fini,\"ax\", at progbits\n\t"
         "call __do_fini\n\t"



More information about the llvm-commits mailing list