[02/11] Disable __USE_EXTERN_INLINES for clang

Message ID 20221028173532.876027-3-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Initial fixes for clang build support |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Oct. 28, 2022, 5:35 p.m. UTC
  From: Fangrui Song <maskray@google.com>

clang does not allow to redefine attributes after function declaration.
Although it work for external usage, its breaks the build for internal
symbol that glibc provides as optimization (for instance bsearch with
stdlib-bsearch.h or __cmsg_nxthdr).

Disable such optimization for clang.
---
 include/features.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Joseph Myers Oct. 28, 2022, 9:06 p.m. UTC | #1
On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:

> From: Fangrui Song <maskray@google.com>
> 
> clang does not allow to redefine attributes after function declaration.
> Although it work for external usage, its breaks the build for internal
> symbol that glibc provides as optimization (for instance bsearch with
> stdlib-bsearch.h or __cmsg_nxthdr).

If it works for external usage, I'd expect the disabling to be only when 
_LIBC is defined and not for building normal applications using this 
installed header file.
  
Fangrui Song Oct. 28, 2022, 10:02 p.m. UTC | #2
On 2022-10-28, Joseph Myers wrote:
>On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>
>> From: Fangrui Song <maskray@google.com>
>>
>> clang does not allow to redefine attributes after function declaration.
>> Although it work for external usage, its breaks the build for internal
>> symbol that glibc provides as optimization (for instance bsearch with
>> stdlib-bsearch.h or __cmsg_nxthdr).
>
>If it works for external usage, I'd expect the disabling to be only when
>_LIBC is defined and not for building normal applications using this
>installed header file.

Thanks for mentioning _LIBC (I did not know).  Then it looks like we can use this:

/* Decide whether we can define 'extern inline' functions in headers.  */
#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
     && defined __extern_inline && !(defined __clang__ && defined _LIBC)
# define __USE_EXTERN_INLINES   1
#endif

https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/clang builds with this change.
  
Adhemerval Zanella Oct. 31, 2022, 6:33 p.m. UTC | #3
On 28/10/22 19:02, Fangrui Song wrote:
> On 2022-10-28, Joseph Myers wrote:
>> On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> From: Fangrui Song <maskray@google.com>
>>>
>>> clang does not allow to redefine attributes after function declaration.
>>> Although it work for external usage, its breaks the build for internal
>>> symbol that glibc provides as optimization (for instance bsearch with
>>> stdlib-bsearch.h or __cmsg_nxthdr).
>>
>> If it works for external usage, I'd expect the disabling to be only when
>> _LIBC is defined and not for building normal applications using this
>> installed header file.
> 
> Thanks for mentioning _LIBC (I did not know).  Then it looks like we can use this:
> 
> /* Decide whether we can define 'extern inline' functions in headers.  */
> #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
>     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
>     && defined __extern_inline && !(defined __clang__ && defined _LIBC)
> # define __USE_EXTERN_INLINES   1
> #endif
> 
> https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/clang builds with this change.

Right, I will check and resend it.
  

Patch

diff --git a/include/features.h b/include/features.h
index 123de9fd47..8d5a7cef5d 100644
--- a/include/features.h
+++ b/include/features.h
@@ -502,7 +502,7 @@ 
 /* Decide whether we can define 'extern inline' functions in headers.  */
 #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
-    && defined __extern_inline
+    && defined __extern_inline && !defined __clang__
 # define __USE_EXTERN_INLINES	1
 #endif