Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between data and data1 sections and the difference between rodata and rodata1 sections in a ELF file?

Tags:

linker

elf

I checked ELF spec here http://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf But, there is no difference mentioned.

like image 598
appleleaf Avatar asked Sep 30 '22 10:09

appleleaf


2 Answers

I am not finding a single document mandating this, but .rodata1 typically comes after everything starting with .rodata. You can look at the linker scripts on your system to verify this (usually /usr/lib/ldscripts/).

This makes some nice things possible, like placing a variable for a checksum in this section. This ensures its behind the remaining read-only stuff, a tool can then calculate the checksum and patch in into the binary.

During runtime you can check your code against the checksum. This sound stupid for a PC, but its common in embedded firmwares. My guess the section was motivated by having a section "outside" of the code produced by a compiler for various reasons, but was never fully documented.

like image 136
Norbert Lange Avatar answered Oct 05 '22 08:10

Norbert Lange


As I know, they're the same.

It's also compiler-dependent. Some compilers will concatenate this 2 sections (and maybe more sections) into ".data".

like image 29
Mickey Avatar answered Oct 05 '22 08:10

Mickey