6

I have a constant array that the linker places into the .rodata section. I need it to go into the .text section. Is it possible? I have already tried to define it as static const but it didn't change anything. I am using the Green Hills linker and compiler.

Thank you!

Harry
  • 188
  • 1
  • 12
  • 1
    *brain storming*: **maybe** something like this: `goto skipdata; asm("db 1, 1, 2, 3, 5, 8, 13, ..."); skipdata: /* ... */` ... then somehow find where data starts and assign that address to `char *constantarray` – pmg Feb 17 '20 at 14:47
  • 5
    There's typically no way to do this with pure standard C. There will be some non-standard thing: #pragma, declspec, attribute etc. It's compiler-specific and I don't know Green Hills, so I can't help there. – Lundin Feb 17 '20 at 14:49
  • I could use #pragma to place data into a custom section. But I could't use it to move from a section to an already existing one. – Harry Feb 17 '20 at 14:51
  • 1
    ***Why*** do you need it in a different section? What exactly is wrong with the section its in? – abelenky Feb 17 '20 at 14:51
  • You could probably also compile to assembly, patch the assembly to change section there and then assemble to an object? And do this once to go in a library you link in rather than having to do this for every build. Or maybe even patch the object file directly. – Rup Feb 17 '20 at 14:51
  • 3
    I understand your question that you want to "camouflage" some data as code. If you could give some reasoning background for why you want to do that, it might allow users here to help you achieve your goal, even if it is not the way you imagine to pursue it. I.e. I suspect we might be looking at https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Yunnosch Feb 17 '20 at 15:20
  • 1
    I believe you can combine the .rodata section into .text with a linker script, yes. When you are telling the linker what goes in .text, you just tell it to include .rodata from the object files there. I don't remember what the syntax looks like in the GNU linker and I've never heard of Green Hills. Maybe you should post your linker script here. – user253751 Feb 17 '20 at 15:42
  • Put useful info into the question please. – Yunnosch Feb 17 '20 at 15:55
  • Just let the linker put it wherever it wants to, and be done. – Mike Robinson Feb 17 '20 at 16:02
  • 2
    Commonly both .text and .rodata go into the same memory. Please [edit] your question and answer @abelenky's question, *why* you want the other section. – the busybee Feb 17 '20 at 18:30
  • That's because I have different areas of memory that contain different sections and I just wanted to know If I was free to move code and data wherever I want (because of size limitations). The answer is yes. I just added a section containing the data I want to move and I put it into the .text section. I just had to find the right sintax and I found it into the Green Hills manual. Thanks everyone for your help and support. – Harry Feb 18 '20 at 10:13
  • Post your linker script here and a link to the Green Hills compiler user manual. – Gabriel Staples Nov 22 '21 at 08:27

0 Answers0