I'm learning GAS Assembler on Windows with MinGW-64 and I have a question about MinGW. Why does this compiler generate extra instructions in the end of .text section? I found some answers where people explain it is required for alignment reasons (the compiler does it to align next function by 8, 16 or 32 boundary). But I have the following simplest code
.text.global _start_start: xorq %rax, %rax retq
objdump shows this
test.exe: file format pei-x86-64Disassembly of section .text:0000000000401000 <.text>: 401000: 48 31 c0 xor %rax,%rax 401003: c3 retq 401004: 90 nop 401005: 90 nop 401006: 90 nop 401007: 90 nop 401008: 90 nop 401009: 90 nop 40100a: 90 nop 40100b: 90 nop 40100c: 90 nop 40100d: 90 nop 40100e: 90 nop 40100f: 90 nop 401010: ff (bad) 401011: ff (bad) 401012: ff (bad) 401013: ff (bad) 401014: ff (bad) 401015: ff (bad) 401016: ff (bad) 401017: ff 00 incl (%rax) 401019: 00 00 add %al,(%rax) 40101b: 00 00 add %al,(%rax) 40101d: 00 00 add %al,(%rax) 40101f: 00 ff add %bh,%bh 401021: ff (bad) 401022: ff (bad) 401023: ff (bad) 401024: ff (bad) 401025: ff (bad) 401026: ff (bad) 401027: ff 00 incl (%rax) 401029: 00 00 add %al,(%rax) 40102b: 00 00 add %al,(%rax) 40102d: 00 00 add %al,(%rax) ...
If it is done for alignment reasons then I could just replace these extra instructions with any bytes except null-bytes and the program would execute properly, right? But when I replace all these extra bytes with, for example, 90 (nop instruction), the program stops to work correctly. Please explain me what's happening! Thanks in advance!