1

In the course of learning, I learned that const data is placed in the .rodata segment, but does the .rodata segment belong to the code segment or the data segment? Or is there something wrong with the way I understand it?

When learning the memory segmentation of C++, I have some doubts about whether the constant data should be placed in the data segment or the code segment. After searching for relevant information on the Internet, I found out that the constant data is actually placed in the .rodata section, but there is no unified answer as to whether the .rodata section belongs to the data section or the code section, so I hope to get a clear answer when I ask this question.

Sleeping
  • 43
  • 5
  • 4
    Why not its own read-only data segment? Which is what `rodata` really is. And it's really an implementation details that depends on not only the compiler and linker but also on the target OS and hardware. – Some programmer dude Aug 04 '23 at 10:04
  • 10
    This question is about compilers, not C/C++. Both of those languages has no mention of segments. – Fredrik Aug 04 '23 at 10:07
  • 1
    @Fredrik is right but doesn't go far enough. It's not a C/C++ language thing. It's not a Linux thing. It's not even a compiler implementation thing, as a compiler can tag sections for specific purposes but it's usually up to the linker how it organises and combines sections. And it's not even a linker thing since that allocation can be controlled by config files :-) – paxdiablo Aug 04 '23 at 10:10
  • 2
    With the focus on Linux, interesting discussion [here](https://stackoverflow.com/questions/44938745/rodata-section-loaded-in-executable-page). I was surprised by what I read there. But that answer was written 6 years ago so may no longer be accurate. – Paul Sanders Aug 04 '23 at 10:28

0 Answers0