c - Disable .rodata indirection for local constants -
when have local data defined inside function, gets placed .rodata section. means .text section contain relative reference (//1) absolute address (//2) inside .text, in turn points data (//3) inside .rodata.
int function() { int a[] = {97, 98, 99, 100, 101, 103}; } // undesirable: 00000000 <.text.function>: /---/ 6: 4b07 ldr r3, [pc, #28] ; (24 <function+0x24>) //1 /---/ 24: 00000000 .word 0x00000000 //2 absolute address of .rodata 00000000 <.rodata>: // absolute address replaced linker 0: 00000061 .word 0x00000061 //3 4: 00000062 .word 0x00000062 8: 00000063 .word 0x00000063 c: 00000064 .word 0x00000064 10: 00000065 .word 0x00000065 14: 00000067 .word 0x00000067
i understand keeping data , code separate admirable in general, in case of embedded system want have local data , function code entangled. want [pc, #28] relative pointer point directly data location , array values should directly in .text section.
i can similar using linkerscript absolute address still in there, , don't want function .text section contain absolute addresses.
// undesirable: .text.function : { *(.text.function) filename.o(.rodata) } 00000000 <.text.function>: /---/ 6: 4b07 ldr r3, [pc, #28] ; (24 <function+0x24>) /---/ 24: 00000000 .word 0x00000028 // address of next line 28: 00000061 .word 0x00000061 /---/
are there compiler flags or other methods force gcc include data alongside code , skip additional indirection?
edit: further clarify asking, i'd point out solutions, won't work. adding static const
array force stored inside .rodata section , therefore exact opposite of want. adding __attribute__((section(".text")))
won't work because question local variables , local variables can't have section attributes. unfortunately -fpic
or -fpie
don't seem work either, instead depend on runtime linker replace absolute addresses.
Comments
Post a Comment