0

I am only starting to learn assembly, and i have read in the book that only .text section can be executed. So why am i allowed to execute instructions what are stored in .data section? Here is the code:

global _start

section .data
msg: db "hello world",10
msg_len: equ $-msg

proc_write_and_exit:
        mov eax, 4      ;write syscall
        mov ebx, 1      ;stdout handle number
        mov ecx, msg
        mov edx, msg_len
        int 80h         ;call program interrupt

        mov eax, 1      ;_exit syscall
        mov ebx, 0      ;program exit code
        int 80h

section .text
_start: jmp proc_write_and_exit

Running on Ubuntu 18.04.4 LTS.

build: nasm -f elf execute_data_section.asm && ld -m elf_i386 execute_data_section.o

run: ./a.out

output: "hello world"

So which sections can really be executed, and which sections can't? And where can i read it to be sure? I am pretty confused at this point.

Vadim
  • 11
  • 1
  • Interesting question, but unfortunately not new. See the linked duplicates for why `.data` gets mapped with exec permission with your source + toolchain behaviour + kernel version. – Peter Cordes Feb 28 '21 at 12:12

0 Answers0