Re: [RFC 00/31] objtool, livepatch: Livepatch module generation

From: Song Liu
Date: Sun Sep 08 2024 - 01:04:48 EST


On Sat, Sep 7, 2024 at 1:14 PM Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> On Sat, Sep 07, 2024 at 10:43:10AM -0700, Song Liu wrote:
> > clang gives the following:
> >
> > elf.c:102:1: error: unused function '__sym_remove' [-Werror,-Wunused-function]
> > 102 | INTERVAL_TREE_DEFINE(struct symbol, node, unsigned long, __subtree_last,
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 103 | __sym_start, __sym_last, static inline, __sym)
> > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > /data/users/songliubraving/kernel/linux-git/tools/include/linux/interval_tree_generic.h:65:15:
> > note: expanded from macro 'INTERVAL_TREE_DEFINE'
> > 65 | ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node,
> > \
> > | ^~~~~~~~~~~~~~~~~~~
> > <scratch space>:155:1: note: expanded from here
> > 155 | __sym_remove
> > | ^~~~~~~~~~~~
> > 1 error generated.
>
> Here's how __sym_remove() is created:
>
> #define INTERVAL_TREE_DEFINE(ITSTRUCT, ITRB, ITTYPE, ITSUBTREE, \
> ITSTART, ITLAST, ITSTATIC, ITPREFIX) \
> ...
>
> ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node, \
> struct rb_root_cached *root) \
>
> INTERVAL_TREE_DEFINE(struct symbol, node, unsigned long, __subtree_last,
> __sym_start, __sym_last, static inline, __sym)
>
> ITSTATIC is 'static inline' so it shouldn't be complaining about it
> being unused, right?

I think gcc doesn't complain, but clang does:

$ cat ttt.c
static inline void ret(void)
{
return;
}

int main(void)
{
return 0;
}

$ gcc ttt.c -Werror -Wunused-function
$ clang ttt.c -Werror -Wunused-function
ttt.c:1:20: error: unused function 'ret' [-Werror,-Wunused-function]
1 | static inline void ret(void)
| ^~~
1 error generated.

>
> If you add -E to the cflags to get preprocessed output, can you confirm
> __sym_remove() is 'static inline'?

Yes, it is 'static inline'.

Song