x86: Update the check for Forbidden global variables

Add a section .illegal_globals to romstage and check that the section does not
contain any variables while creating romstage.

BUG=None
BRANCH=None
TEST=Compiles for falco and boots to kernel. No size change for romstage with
and without this check.

Change-Id: Ib2ac0c9b8106547f286f5202682a431e2ce886f9
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/226190
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
Furquan Shaikh 2014-10-28 22:04:56 -07:00 committed by chrome-internal-fetch
commit f2b4fdf631
2 changed files with 18 additions and 2 deletions

View file

@ -211,9 +211,10 @@ endif # CONFIG_ROMCC
$(objcbfs)/romstage_null.debug: $$(romstage-objs) $(LIBGCC_FILE_NAME_romstage) $(objgenerated)/romstage_null.ld
@printf " LINK $(subst $(obj)/,,$(@))\n"
$(call link,romstage,$(filter %.o %.a,$(^)),-o $(@) -L$(obj) -T $(objgenerated)/romstage_null.ld,$(LIBGCC_WRAP_LDFLAGS))
$(NM_romstage) $@ | grep -q " [DdBb] "; if [ $$? -eq 0 ]; then \
$(OBJCOPY_romstage) --only-section .illegal_globals $(@) $(objcbfs)/romstage_null.offenders && \
$(NM_romstage) $(objcbfs)/romstage_null.offenders | grep -q ""; if [ $$? -eq 0 ]; then \
echo "Forbidden global variables in romstage:"; \
$(NM_romstage) $@ | grep " [DdBb] "; test "$(CONFIG_CPU_AMD_AGESA)" = y; \
$(NM_romstage) $(objcbfs)/romstage_null.offenders; test "$(CONFIG_CPU_AMD_AGESA)" = y; \
else true; fi
$(objcbfs)/romstage_xip.debug: $$(romstage-objs) $(LIBGCC_FILE_NAME_romstage) $(objgenerated)/romstage_xip.ld

View file

@ -42,6 +42,21 @@ SECTIONS
_erom = .;
}
#if !IS_ENABLED(CONFIG_CPU_AMD_AGESA)
/* Global variables are not allowed in romstage
* This section is checked during stage creation to ensure
* that there are no global variables present
*/
.illegal_globals . : {
*(.data)
*(.data.*)
*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)
}
#endif
/DISCARD/ : {
*(.comment)
*(.note)