I have a binary depending on several shared libraries and I would like to produce a PIC binary except for one read-only table.
I want all code sections to be able to access this table without adhering to .GOTPCREL
. I do not care in what kind of data section (.bss
, .data
, or etc) this table resides, but I want it to be read-only for sure and can be accessed directly by all shared libraries and the main binary. Therefore, I guess it should goes into the binary not in one of the shared libraries.
Currently I have it in .data.rel.ro
section and it is read-only, however for accessing its data I need to get its address through .GOT
like this: TABLENAME@GOTPCREL(%rip)
and use the address afterwards. The reason I am asking that is that I would like to use bt
instruction and for giving it the address of the table I need to have two instructions, and also one temporary register. If the table was not relocatable I was able to give the address of it in linking phase like: bt %REG, TABLENAME
, requiring just one instruction without any extra register.
Is this something achievable at all?
Here is a more concrete example:
Main program code:
.text
### SOME CODE
.section .data.rel.ro,"aw",@progbits
.globl MYTABLE
MYTABLE:
.zeros 128 # my table of 128 bytes all zeros for illustration
One of the shared-libraries:
.text
.globl myfun
.type myfun, @function
myfun:
xor %rax, %rax
movq MYTABLE@GOTPCREL(%rip), %rcx ### I like to have "bt %r11, MYABLE"
bt %r11, (%rcx) ### instead of these two lines
jb label
movq $1, %rax
label:
ret