On 22/05/2022 17:50, Tom Rini wrote:
> On Sun, May 22, 2022 at 04:56:08PM +0300, Alper Nebi Yasak wrote:
>> It looks like we should be able to change things in common/spl/spl.c to:
>>
>>     #if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
>>     /* See spl.h for information about this */
>>     binman_sym_declare_optional(ulong, u_boot_any, image_pos);
>>     binman_sym_declare_optional(ulong, u_boot_any, size);
>>     #endif
>>
>> which would mark the symbol as 'weak' and turn the error into a warning
>> on the binman side. But that is somehow being undone by LTO.
> 
> So, looking at binman_sym_declare_optional we tell the linker that it's
> weak and might even be unused.  LTO gets very aggressive about finding
> things that aren't used in the resulting binary and discarding them.
> Typically we have the problem of a function that is used but it's hard
> for LTO to see it, so we give it the "used" attribute.  But for
> something we're already saying is "unused" this would be wrong.  So why
> do we mark things as unused here?  I assume it's marked weak as it could
> be overridden at link time by a definition elsewhere.

I don't know, but the GCC manual says marking things 'unused' will
suppress a warning if the variable is actually unused. I guess binman
symbols may become unused due to some other config options being unset,
and it's done for those cases?

I think the optional symbols are marked weak just to signal the python
side that they are optional. If I understand it right, binman:

1. Packs an image using the finalized 'spl/u-boot-spl.bin'
2. Figures out the image-pos and size values of every entry
3. Inspects the 'spl/u-boot-spl' ELF file for declared binman symbols
4. Raises an error if any non-'weak' symbol's value is undetermined
5. Updates the u-boot-spl.bin (in memory) with the calculated values
6. Recreates the final image based on that updated bin file.

Reply via email to