From b6ba0a23f975844f412c2b1afc864413719b6d48 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Mon, 27 Jul 2020 12:25:48 -0700 Subject: [PATCH] BR 3392701: outcoff: remove weird padding code It seems that the odd alignment-padding code was simply dead in older versions of NASM. This means that the COFF backend behavior really was the same as the other backends. Remove that stale code and revert to previous/common behavior. Reported-by: ig Signed-off-by: H. Peter Anvin (Intel) --- output/outcoff.c | 36 ++++++------------------------------ test/coffalign.asm | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 30 deletions(-) create mode 100644 test/coffalign.asm diff --git a/output/outcoff.c b/output/outcoff.c index bcd9ff3fe..2ecb97fc7 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -420,36 +420,12 @@ static int32_t coff_section_names(char *name, int *bits) } } - /* Check if alignment might be needed */ - if (align_flags) { - uint32_t sect_align_flags = coff_sects[i]->align_flags; - - /* Compute the actual alignment */ - unsigned int align = coff_alignment(align_flags); - - /* Update section header as needed */ - if (align_flags > sect_align_flags) { - coff_sects[i]->align_flags = align_flags; - } - - /* Check if not already aligned */ - /* XXX: other formats don't do this... */ - if (coff_sects[i]->len % align) { - unsigned int padding = (align - coff_sects[i]->len) % align; - /* We need to write at most 8095 bytes */ - char buffer[8095]; - - nasm_assert(padding <= sizeof buffer); - - if (coff_sects[i]->flags & IMAGE_SCN_CNT_CODE) { - /* Fill with INT 3 instructions */ - memset(buffer, 0xCC, padding); - } else { - memset(buffer, 0x00, padding); - } - saa_wbytes(coff_sects[i]->data, buffer, padding); - coff_sects[i]->len += padding; - } + /* + * Alignment can be increased, but never decreased. However, + * specifying a narrower alignment is permitted and ignored. + */ + if (align_flags > coff_sects[i]->align_flags) { + coff_sects[i]->align_flags = align_flags; } } diff --git a/test/coffalign.asm b/test/coffalign.asm new file mode 100644 index 000000000..621cfc831 --- /dev/null +++ b/test/coffalign.asm @@ -0,0 +1,17 @@ + section .text align=64 +foo: + nop + nop + nop + ret + + section .data align=64 +bar: + db 0, 1, 2 + + section .text align=32 +baz: + nop + nop + nop + ret