From: Heinrich Schuchardt Date: Thu, 4 Feb 2021 14:54:15 +0100 Subject: [PATCH v2 02/37] linker_lists: Allow use in data structures In-Reply-To: <20210203094345.v2.2.If4b6aad281b0987643878ab428b5120dbdbbecfb@changeid> References: <20210203164353.2577985-1-sjg@chromium.org> <20210203094345.v2.2.If4b6aad281b0987643878ab428b5120dbdbbecfb@changeid> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 03.02.21 17:43, Simon Glass wrote: > At present linker lists are designed for use in code. They make use of > statements within expressions ({...}), for example. > > It is possible to generate a reference to a linker_list entry that can > be used in data structures, where such features are not permitted. It > requires that the reference first be declared as extern. In other > words the existing macro needs to be split into two parts. > > Add new macros to support this. > > Signed-off-by: Simon Glass > --- > > (no changes since v1) > > include/linker_lists.h | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/include/linker_lists.h b/include/linker_lists.h > index fd98ecd297c..55631f0240c 100644 > --- a/include/linker_lists.h > +++ b/include/linker_lists.h > @@ -211,6 +211,34 @@ > _ll_result; \ > }) > > +/** > + * ll_entry_decl() - Declare a linker-generated array entry reference as extern > + * > + * This declares a reference to a list entry so that it can be used later, > + * without needing the code in ll_entry_get(). > + * > + * To use this, put ll_entry_decl() somewhere in your file, then use > + * ll_entry_ref() later on, to reference the entry. > + * > + * @_type: Data type of the entry > + * @_name: Name of the entry > + * @_list: Name of the list in which this entry is placed > + */ > +#define ll_entry_decl(_type, _name, _list) \ > + extern _type _u_boot_list_2_##_list##_2_##_name Can't you simply add the extern keyword to ll_entry_declare()? Why do we need entries with and entries without extern? Best regards Heinrich > + > +/** > + * ll_entry_ref() - Get a reference to a linker-generated array entry > + * > + * Once ll_entry_decl() has been used to declare the reference, this macro > + * allows the entry to be accessed. > + * > + * This is like ll_entry_get(), but without the extra code, so it is suitable > + * for putting into data structures. > + */ > +#define ll_entry_ref(_type, _name, _list) \ > + ((_type *)&_u_boot_list_2_##_list##_2_##_name) > + > /** > * ll_start() - Point to first entry of first linker-generated array > * @_type: Data type of the entry >