Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc: __DATA,__const vs __TEXT,__const

Tags:

gcc

According to the Mac OS X ABI Mach-O File Format Reference, __DATA,__const holds Initialized relocatable constant variables. I poked around a bit and it looks like gcc places initialized const structures and arrays in __DATA, __const. Why not __TEXT,__const, though?

Koi8rModel and CI_nsJSCID, for example, are initialized const structures, whereas AlignStrings is an array.

nm -m MinefieldNoPic.app/Contents/MacOS/firefox-bin |grep Koi8rModel
000000010156ce80 (__DATA,__const) non-external _Koi8rModel

nm -m MinefieldNoPic.app/Contents/MacOS/firefox-bin |grep CI_nsJSCID
0000000101441060 (__DATA,__const) non-external __ZL10CI_nsJSCID

nm -m MinefieldNoPic.app/Contents/MacOS/firefox-bin |grep AlignStrings
000000010154f8c0 (__DATA,__const) non-external __ZL13sAlignStrings
like image 974
Joel Reymont Avatar asked Mar 14 '26 19:03

Joel Reymont


2 Answers

The __TEXT, __const section is for non-relocatable initialized constant data. An example would be a jumtable. Relocatable read-only data, like the examples you gave, go to __DATA, __const.

like image 60
Gunther Piez Avatar answered Mar 17 '26 16:03

Gunther Piez


I just realized that my question contained the answer. __DATA,__const is for relocatable bits indeed but the reason the bits in my question are relocatable is because they are pointers and thus need to be fixed up at runtime.

like image 25
Joel Reymont Avatar answered Mar 17 '26 15:03

Joel Reymont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!