[coreboot] global variables in romstage

Marc Jones marcj303 at gmail.com
Sun Aug 15 00:10:18 CEST 2010

On Sat, Aug 14, 2010 at 3:40 AM, Stefan Reinauer
<stefan.reinauer at coresystems.de> wrote:
>  On 8/12/10 9:27 PM, Patrick Georgi wrote:
>> 1.  _bogus = ASSERT((SIZEOF(.bss) + SIZEOF(.data)) == 0, "Do not use
>> global variables in romstage");
>> This one looks for the size of .bss and .data (initialized and
>> uninitialized globals) and breaks the build if it finds any. It doesn't
>> tell, which global variables are involved.
>> 2. Add .bss and .data to /DISCARD/.
>> That way, the linker complains about "missing" symbols (as they were
>> discarded), but only if they were used by any surviving code. This
>> means, it's no problem that the global is defined. If you use it
>> later-on, it "mysteriously" breaks. The error message is rather cryptic,
>> too:
>> `variable' referenced in section `.rom.text' of
>> coreboot-builds/kontron_986lcd-m/mainboard/kontron/986lcd-m/crt0.initobj.o:
>> defined in discarded section
>> `.data' of
>> coreboot-builds/kontron_986lcd-m/mainboard/kontron/986lcd-m/crt0.initobj.o
>> collect2: ld returned 1 exit status
>> I tend to prefer the first option, but it doesn't give _any_ clues which
>> variable is responsible (except for "look for globals"), but at least it
>> does tell the user what the real problem is.
> I prefer option one, too, as
> - it catches all global variables, not just the used ones. We want to be
> sure that no such code sneaks in even if it's not used.
> - it provides a clear error message on what is wrong, inszead of the
> more cryptic one saying that a variable is defined in a discarded section.

I agree too. The problem was that a global variable was added
unintentionally. Once the problem is indicated, it isn't hard to find
the offending code.



More information about the coreboot mailing list