From 7f2569246c81d5f88e74c142b8fbdc0ee601bffe Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 5 Aug 2016 10:51:37 +0200 Subject: [PATCH] linuxboot_dma: avoid guest ABI breakage on gcc vs. clang compilation Recent GCC compiles linuxboot_dma.c to 921 bytes, while CentOS 6 needs 1029 and clang needs 1527. Because the size of the ROM, rounded to the next 512 bytes, must match, this causes the API to break between a <1K ROM and one that is bigger. We want to make the ROM 1.5 KB in size, but it's better to make clang produce leaner ROMs, because currently it is worryingly close to the limit. To fix this prevent clang's happy inlining (which -Os cannot prevent). This only requires adding a noinline attribute. Second, the patch makes sure that the ROM has enough padding to prevent ABI breakage on different compilers. The size is now hardcoded in the file that is passed to signrom.py, as was the case before commit 6f71b77 ("scripts/signrom.py: Allow option ROM checksum script to write the size header.", 2016-05-23); signrom.py however will still pad the input to the requested size. This ensures that the padding goes beyond the next multiple of 512 if necessary, and also avoids the need for -fno-toplevel-reorder which clang doesn't support. signrom.py can then error out if the requested size is too small for the actual size of the compiled ROM. Signed-off-by: Paolo Bonzini --- pc-bios/linuxboot_dma.bin | Bin 1024 -> 1536 bytes pc-bios/optionrom/linuxboot_dma.c | 8 ++++++-- scripts/signrom.py | 27 +++++++++++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin index e1f623a1245efff0d46ea5b685e0f18e4ef98d74..238a195d3869995067f158d243d852778d38a736 100644 GIT binary patch literal 1536 zcmeHFO=}ZT6n#mjn#9N?ZK{K0k;PaL-DD+#E`)TKK>SF%@QZ?;pp*(SMO{f8vv`CI z_!9&-x)zKBLZ%f_LNuh%S`|r(v{S59T@^nv-g)U07ybYjeTz4D&OPs(`|i7ihXW1v z&y{3)emWlr%H&aYT!!qlh)#^<3M_khdgexI>gwdhOV?7FoX`3Gb8V4T4OV^17z*G` zOn^I3n-~Xwj#DUg8S@xQE3`AD-$A|K(7+ertc1X4;Vf$ie}Jj?IftcP?P z=6ZtIvqam3<7z0a3aQvV%fdk;)OF zd{0P_V?yG)1kU@?8C~hi6fr;?lBo<)AHR4WO3UI?t{W35w~doH(lT=XJJbR$+43du zx6Kjoh43q=nR%#VPPwh#*%zRfiBT!H$tO_6LEl;^Qi;M&6PFP6(lryXhx%9clkV4F zTOA6?dUuL?mn5!9JS1>O;H0C$j!T^o+y{~$mHc7Bzbo;i#1jI)+1JVFQP?AWovfaO zJK4t*I(6nOC3y=6=4q%Dn4e?=0EZ1s*zc=ft{1q{%>6iWxrfC#EH)uF?F&uL= cH&7qfG012%;B+Eu-5wcjuk8-}=N-898@_u-5C8xG literal 1024 zcmd6mziX307{@Q^tG-DiZ>p(g$dKVIh%T9=qM-1)wGcJY!KxJW`(h~-Bt;!#jBtbm z9lAI>If`HmD0vg9wINblk!l@67gN$=2eDW*ug_gPT>JyP;dt+J&wZbtZ~C#n!Tz~o zj3=j(KEJ*^#!l)_mQr7*PmQM8$hE2ITk*;3<5#ZUh})ymX8Y&b7go%$;tR&$u7;7u zd7Q&ph$V;`5*|d8xQX0)4B`i}tBiRJVivhZ(1A#CL)y8mD6B{CjnC`{bTm=MXKl`$#}Z zhxPS-dEM@GB`+A9wh{9%R=26W}#UCn8I#H!Vog7g7j= 65536: - sys.exit("%s: option ROM size too large" % sys.argv[1]) +size = size_byte * 512 +if len(data) > size: + sys.stderr.write('error: ROM is too large (%d > %d)\n' % (len(data), size)) + sys.exit(1) +elif len(data) < size: + # Add padding if necessary, rounding the whole input to a multiple of + # 512 bytes according to the third byte of the input. # size-1 because a final byte is added below to store the checksum. data = data.ljust(size-1, '\0') - data = data[:2] + chr(size/512) + data[3:] else: - # Otherwise the input file specifies the size so use it. - # -1 because we overwrite the last byte of the file with the checksum. - size = size_byte * 512 - 1 - data = fin.read(size) + if ord(data[-1:]) != 0: + sys.stderr.write('WARNING: ROM includes nonzero checksum\n') + data = data[:size-1] fout.write(data)