What is the difference between .rodata and .rdata

6k Views Asked by At

I've seen both .rodata and .rdata being used as segments. Which one should I use and what are the differences between them?

2

There are 2 best solutions below

0
On BEST ANSWER

RODATA is used in ELF and RDATA is used in COFF. The closest equivalent in Mach-O would be __TEXT,__const.

1
On

What is the difference between .rodata and .rdata

The main (only?) difference is cultural.

For linkers and loaders (and object file formats), you can use whatever name you like. It doesn't matter as long as (during linking) things that should be in the same section use the same name for that section, and the properties of that section are adequately described (e.g. using a linker script, including the default linker script for the OS). There also isn't anything preventing you from having multiple separate sections (e.g. maybe "rdata_initialization", "rdata_frequently_used" and "rdata_rarely_used" to improve cache locality) if you're willing to deal with the extra hassle.

However, for convenience (given that most people don't do anything special with sections), to ensure tools use the same name for the same section compilers use whatever is "normal" for a certain OS as the default, and will assume ".rdata" for Windows (because that's normal for Windows) and "rodata" for *nix clones (because that's normal for Unix).