What is the reason for having read-only data defined in .text section?

后端 未结 1 892
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 07:14

I am learning assembly and low-level programming itself and reading a book about it. It is said there that we can put any data inside the .text section of a

相关标签:
1条回答
  • 2021-01-06 07:47

    Traditionally, read-only data was placed in the text section for two reasons:

    • the text section is not writable, so memory protection can catch accidental writes to read-only data and make your program crash instead
    • with a memory-management unit (MMU), multiple instances of the same process can share one copy of the text section (as its guaranteed to be the same in all instances of the program), saving memory

    On ELF targets, this scheme was modified a bit. Read-only data is now placed in the new .rodata section which is like the .text section except it also cannot be executed, preventing certain attack vectors. The advantages remain.

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