public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>,
	Fangrui Song <maskray@google.com>
Cc: Nicholas Guriev <nicholas@guriev.su>, libc-alpha@sourceware.org
Subject: Re: [PATCH v3] elf: Rewrite long RESOLVE_MAP macro to a debug friendly function
Date: Mon, 23 May 2022 13:56:17 -0300	[thread overview]
Message-ID: <a8cc2f0e-153d-6361-7ccf-e6041ed92a8c@linaro.org> (raw)
In-Reply-To: <d49fb8b9-c4bf-7a70-b14a-40fd6703106a@gotplt.org>



On 23/05/2022 13:33, Siddhesh Poyarekar wrote:
> On 23/05/2022 21:52, Adhemerval Zanella wrote:
>>  From ed159672eb3cd650a32b7e5cb4d5ec1fe0e63802 I take that even always_inline
>> might fail for some reason.  So we need to keep using always_inline on function
>> that need to be inline to get a compiler warning if it can not be done.
>>
>> I think by using -Winline with stardand C99 static inline, besides being
>> slight more portable code is also less error prone (since it is one less
>> annotation to take care of).  It would be slight better to setup -Winline
>> per TU, instead of global since we only need always_inline semantic for
>> specific usages.
>>
>> In the end I think both a pretty equivalent.
> 
> That is surprising, and kinda defeats the "always" in the always_inline.  The documentation for the attribute also states that failure to inline a function is diagnosed as an error[1], except when the function is called indirectly and maybe some more context is needed for ed159672eb3cd650a32b7e5cb4d5ec1fe0e63802 to understand the nature of the warnings.

I think ed159672eb3cd650a32b7e5cb4d5ec1fe0e63802 change makes sense once we
commit to use __always_inline where applicable.

> 
> So I can't agree yet that it's equivalent, but I do agree that the always_inline semantic is for specific use cases.

They are not indeed, it seems that __always_inline will try harder to inline
different even for specific usages that 'static inline' might fail:

$ cat inline.c
extern int bar (char *, int *);

static inline
#ifdef USE_ALWAYS_INLINE
__attribute__ ((__always_inline__))
#endif
int func (int *a)
{
  char *p = __builtin_alloca (128);
  return bar (p, a);
}

int foo (int *a)
{
  return func (a);
}
$ gcc -Wall -O2 -std=gnu11 inline.c -c -S -o inline.S
$ gcc -Wall -O2 -std=gnu11 inline.c -c -S -o always_inline.S -DUSE_ALWAYS_INLINE
$ diff -u inline.S always_inline.S 
--- inline.S	2022-05-23 13:52:50.617859866 -0300
+++ always_inline.S	2022-05-23 13:52:55.157865832 -0300
@@ -1,10 +1,12 @@
 	.file	"inline.c"
 	.text
 	.p2align 4
-	.type	func, @function
-func:
-.LFB0:
+	.globl	foo
+	.type	foo, @function
+foo:
+.LFB1:
 	.cfi_startproc
+	endbr64
 	pushq	%rbp
 	.cfi_def_cfa_offset 16
 	.cfi_offset 6, -16
@@ -40,17 +42,6 @@
 	.cfi_restore_state
 	call	__stack_chk_fail@PLT
 	.cfi_endproc
-.LFE0:
-	.size	func, .-func
-	.p2align 4
-	.globl	foo
-	.type	foo, @function
-foo:
-.LFB1:
-	.cfi_startproc
-	endbr64
-	jmp	func
-	.cfi_endproc
 .LFE1:
 	.size	foo, .-foo
 	.ident	"GCC: (Ubuntu 11.2.0-19ubuntu1) 11.2.0"


So '__attribute__ ((__always_inline__))' will force inline in such cases where
static inline might not.  So I agree that we need __always_inline and using the
C99 static inline might not be suffice.

> 
> Thanks,
> Siddhesh
> 
> [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

  reply	other threads:[~2022-05-23 16:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 14:51 [PATCH] " Nicholas Guriev
2022-05-02 21:20 ` Fangrui Song
2022-05-03 10:04   ` Nicholas Guriev
2022-05-03 20:12     ` Fāng-ruì Sòng
2022-05-07 13:33       ` [PATCH v3] " Nicholas Guriev
2022-05-09 13:38         ` Siddhesh Poyarekar
2022-05-14 14:27           ` Nicholas Guriev
2022-05-14 22:48             ` Fangrui Song
2022-05-15  0:58               ` Siddhesh Poyarekar
2022-05-22 22:24                 ` Fangrui Song
2022-05-23  7:28                   ` Siddhesh Poyarekar
2022-05-23 12:35                   ` Adhemerval Zanella
2022-05-23 13:02                     ` Siddhesh Poyarekar
2022-05-23 16:22                       ` Adhemerval Zanella
2022-05-23 16:33                         ` Siddhesh Poyarekar
2022-05-23 16:56                           ` Adhemerval Zanella [this message]
2022-05-03 19:14   ` [PATCH v2] " Nicholas Guriev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8cc2f0e-153d-6361-7ccf-e6041ed92a8c@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    --cc=nicholas@guriev.su \
    --cc=siddhesh@gotplt.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).