diff mbox series

[RFC,u-boot,03/12] linker_lists: declare entries and lists externally visible

Message ID 20210303041211.26945-4-marek.behun@nic.cz
State RFC
Delegated to: Tom Rini
Headers show
Series U-Boot LTO (Sandbox + ARM Nokia RX-51) | expand

Commit Message

Marek Behún March 3, 2021, 4:12 a.m. UTC
Use the `__visible` macro to declare entires and lists declared by
ll_entry_declare() and ll_entry_declare_list() externally visible, so
that when building with LTO the compiler does not optimize this data
away.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 include/linker_lists.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Marek Behún March 4, 2021, 1:47 p.m. UTC | #1
We need to use the __ADDRESSABLE() macro from linux/compiler.h like
Linux does in order to make it work even with clang's LTO.
Bin Meng March 5, 2021, 3:04 a.m. UTC | #2
On Wed, Mar 3, 2021 at 12:13 PM Marek Behún <marek.behun@nic.cz> wrote:
>
> Use the `__visible` macro to declare entires and lists declared by
> ll_entry_declare() and ll_entry_declare_list() externally visible, so
> that when building with LTO the compiler does not optimize this data
> away.
>

__visible is defined like this:

/*
 * Optional: not supported by clang
 *
 *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute
 */
#if __has_attribute(__externally_visible__)
# define __visible                      __attribute__((__externally_visible__))
#else
# define __visible
#endif

It says clang does not support this. So what about clang?

> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> ---
>  include/linker_lists.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Regards,
Bin
Marek Behún March 5, 2021, 3:49 p.m. UTC | #3
On Fri, 5 Mar 2021 11:04:08 +0800
Bin Meng <bmeng.cn@gmail.com> wrote:

> On Wed, Mar 3, 2021 at 12:13 PM Marek Behún <marek.behun@nic.cz> wrote:
> >
> > Use the `__visible` macro to declare entires and lists declared by
> > ll_entry_declare() and ll_entry_declare_list() externally visible, so
> > that when building with LTO the compiler does not optimize this data
> > away.
> >  
> 
> __visible is defined like this:
> 
> /*
>  * Optional: not supported by clang
>  *
>  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute
>  */
> #if __has_attribute(__externally_visible__)
> # define __visible                      __attribute__((__externally_visible__))
> #else
> # define __visible
> #endif
> 
> It says clang does not support this. So what about clang?
> 
> > Signed-off-by: Marek Behún <marek.behun@nic.cz>
> > ---
> >  include/linker_lists.h | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)  
> 
> Regards,
> Bin

Bin, this is already changed to something different on my github. I
will send new version once I am satisfied with CI tests.

Marek
diff mbox series

Patch

diff --git a/include/linker_lists.h b/include/linker_lists.h
index fd98ecd297..9d44dab2e5 100644
--- a/include/linker_lists.h
+++ b/include/linker_lists.h
@@ -70,7 +70,8 @@ 
 #define ll_entry_declare(_type, _name, _list)				\
 	_type _u_boot_list_2_##_list##_2_##_name __aligned(4)		\
 			__attribute__((unused,				\
-			section(".u_boot_list_2_"#_list"_2_"#_name)))
+			section(".u_boot_list_2_"#_list"_2_"#_name)))	\
+			__visible
 
 /**
  * ll_entry_declare_list() - Declare a list of link-generated array entries
@@ -93,7 +94,8 @@ 
 #define ll_entry_declare_list(_type, _name, _list)			\
 	_type _u_boot_list_2_##_list##_2_##_name[] __aligned(4)		\
 			__attribute__((unused,				\
-			section(".u_boot_list_2_"#_list"_2_"#_name)))
+			section(".u_boot_list_2_"#_list"_2_"#_name)))	\
+			__visible
 
 /*
  * We need a 0-byte-size type for iterator symbols, and the compiler