audk/MdePkg/Library/BasePrintLib
Ard Biesheuvel a2433243fb MdePkg/BasePrintLib: avoid absolute addresses for error strings
The mStatusString[] array is constructed as an array of pointer-to-char,
which means that on X64 or AARCH64, it is emitted as a single linear list
of 64-bit quantities, each containing the absolute address of one of the
string literals in memory.

This means that each string takes up 8 bytes of additional space, along
with 2 bytes of relocation data. It also means that extra work needs to
be done at runtime to process these relocations, every time a module is
loaded that incorporates this library.

So fix both issues, by splitting mStatusString into two arrays of char
arrays. The memory footprint decreases from 955 to 843 bytes, and given
that in the latter case, the overhead consists of 278 NUL characters rather
than 390 bytes worth of absolute addresses and relocation records, the size
of a compressed image is reduced even further. For example, when building
ArmVirtQemu.dsc in RELEASE mode for AARCH64 with the GCC5 profile, I get:

  Before

  FV Space Information
  FVMAIN [100%Full] 5329920 total, 5329920 used, 0 free
  FVMAIN_COMPACT [38%Full] 2093056 total, 811840 used, 1281216 free

  After

  FV Space Information
  FVMAIN [100%Full] 5321728 total, 5321728 used, 0 free
  FVMAIN_COMPACT [38%Full] 2093056 total, 809696 used, 1283360 free

So the uncompressed contents of the compressed image are 8 KB smaller,
whereas the resulting flash image (consisting of the compressed image
along with SEC, PEI_CORE and a set of PEIMs that execute in place) is
2 KB smaller.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2020-06-16 09:14:17 +00:00
..
BasePrintLib.inf MdePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:13 -07:00
BasePrintLib.uni MdePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:13 -07:00
PrintLib.c MdePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:13 -07:00
PrintLibInternal.c MdePkg/BasePrintLib: avoid absolute addresses for error strings 2020-06-16 09:14:17 +00:00
PrintLibInternal.h MdePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:13 -07:00