|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 1/3] x86/mkelf32: tidy what is written out
First, replace an open-coded literal number by an expression.
Then adjust tail padding: Don't write up to 4 bytes (and at least one),
but truly only pad to the next 4-byte boundary. And pad with zeroes, not
with whatever is left in buffer[].
Finally drop the explicit nul character in out_shstrtab_extra[] - the one
which is being appended anyway will do fine.
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: New.
--- a/xen/arch/x86/boot/mkelf32.c
+++ b/xen/arch/x86/boot/mkelf32.c
@@ -68,7 +68,7 @@ static Elf32_Phdr note_phdr = {
static uint8_t out_shstrtab[] = "\0.text\0.shstrtab";
/* If num_phdrs >= 2, we need to tack the .note. */
-static uint8_t out_shstrtab_extra[] = ".note\0";
+static uint8_t out_shstrtab_extra[] = ".note";
static Elf32_Shdr out_shdr[] = {
{ 0 },
@@ -97,11 +97,11 @@ static Elf32_Shdr out_shdr[] = {
};
/*
- * The 17 points to the '.note' in the out_shstrtab and out_shstrtab_extra
+ * .sh_name points to the '.note' in the out_shstrtab and out_shstrtab_extra
* laid out in the file.
*/
static Elf32_Shdr out_shdr_note = {
- 17, /* sh_name */
+ sizeof(out_shstrtab), /* sh_name */
SHT_NOTE, /* sh_type */
0, /* sh_flags */
DYNAMICALLY_FILLED, /* sh_addr */
@@ -468,13 +468,21 @@ int main(int argc, char **argv)
do_write(outfd, out_shstrtab, sizeof(out_shstrtab));
/* Our .note */
do_write(outfd, out_shstrtab_extra, sizeof(out_shstrtab_extra));
- do_write(outfd, buffer,
4-((sizeof(out_shstrtab)+sizeof(out_shstrtab_extra)+dat_siz)&3));
+ bytes = sizeof(out_shstrtab) + sizeof(out_shstrtab_extra) + dat_siz;
}
else
{
do_write(outfd, out_shstrtab, sizeof(out_shstrtab));
- do_write(outfd, buffer, 4-((sizeof(out_shstrtab)+dat_siz)&3));
+ bytes = sizeof(out_shstrtab) + dat_siz;
}
+
+ /* Pad to a multiple of 4 bytes, whatever that's good for. */
+ if ( bytes & 3 )
+ {
+ memset(buffer, 0, 4);
+ do_write(outfd, buffer, 4 - (bytes & 3));
+ }
+
close(infd);
close(outfd);
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |