[nasm:nasm-2.15.xx] BR 3392701: outcoff: remove weird padding code

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Mon Jul 27 12:30:04 PDT 2020


Commit-ID:  b6ba0a23f975844f412c2b1afc864413719b6d48
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=b6ba0a23f975844f412c2b1afc864413719b6d48
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Mon, 27 Jul 2020 12:25:48 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Mon, 27 Jul 2020 12:28:09 -0700

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 <glucksmann at avast.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 output/outcoff.c   | 36 ++++++------------------------------
 test/coffalign.asm | 17 +++++++++++++++++
 2 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/output/outcoff.c b/output/outcoff.c
index bcd9ff3f..2ecb97fc 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 00000000..621cfc83
--- /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


More information about the Nasm-commits mailing list