NASM Segmentation fault when modifying a variable that should be in the read-write .data section (section .data doesn't work without a space?)

前端 未结 1 694
死守一世寂寞
死守一世寂寞 2020-12-22 01:28

I\'m having an issue with a program I\'m writing in NASM using SASM, I\'m using a variable as a counter and once I modified it and try to to save the new value at the used a

相关标签:
1条回答
  • 2020-12-22 02:04

    You forgot the space in section.data (and .text), so everything went into the read-only .text section by default.

    section.data is parsed as a label, like foo.bar: would be, not a section directive. The colon at the end of a label is optional when the label name isn't also a valid instruction mnemonic like loop:

    The opposite error (valid section .data but buggy section.text) leads to putting your code into the .data, which gets linked into non-executable memory pages. In that case you'd segfault on code-fetch from the first instruction!


    You should have gotten a warning from NASM like this:

    warning: label alone on a line without a colon might be in error [-w+orphan-labels]
    

    If your NASM didn't warn, use a newer version where it's on by default,
    or run NASM with -Worphan-labels to enable that useful warning.

    0 讨论(0)
提交回复
热议问题