mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-02-17 17:19:35 +08:00
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@avast.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
parent
9abbaa133d
commit
b6ba0a23f9
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
17
test/coffalign.asm
Normal file
17
test/coffalign.asm
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user