LAKITU: grub: Strip .interp from diskboot

boot.img and diskboot.img both need to be smaller than 512 bytes. Clang
inserts a .interp section into these binaries, which brings the binary
size over 512 bytes. Let's strip the .interp section since it is not
needed and breaks grub-install.

We cannot remove the .interp section from all build targets of type
"image" in grub, because some images are very much not
position-independent. In particular, the LZMA decompressor relies on the
symbol "L_decompressor_end" referencing the end of the LZMA decompressor
image in memory. If we remove the .interp section after linking, the
value for "L_decompressor_end" that was filled in everywhere in the
program by the linker will be invalid, because the "L_decompressor_end"
value initially accounted for the .interp section. In this case, we can
leave the .interp section in to keep the program correct. The LZMA
decompressor also has no 512 byte requirement, so we don't need to
remove .interp from it.

After we land the new ChromeOS version in COS, I'll follow up with
ChromeOS on how best to upstream this fix. It might make sense to update
clang/lld to not insert .interp if -nostdlib is provided.

BUG=b/192265868
TEST=local BE run
RELEASE_NOTE=None

Change-Id: I99a0177bdc7877d676e5037ad24497c51f107aaf
Reviewed-on: https://cos-review.googlesource.com/c/third_party/overlays/chromiumos-overlay/+/19114
Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
3 files changed