1

Is it possible to position a particular C library function at a specified memory location with GNU GCC compiler.?

I am using avr-gcc for compiling application. The exact purpose of this is I need to write a code snippet which contain a call to fscanf function, And I want all code for this application and dependent functions should be in a particular range of address.

1 Answer 1

2

Not a specific function, but if you have control of the source code for the library you can place the function in a specific segment, and then use a linker script to place that segment at a specific location.

Sign up to request clarification or add additional context in comments.

5 Comments

I want to move fscanf function, Is it possible to position a C library function(its already compiled) ?
@ted Unfortunately no. You can't access single functions, only segments, using linker scripts. Unless the function already is in a specific segment then it's not possible. This is very unusual, normally all code segments (both from your program and from libraries) are placed together in memory anyway, can you please elaborate on why you want to place some few specific functions separate from the rest of the code? (Please see "What is the XY problem").
The goal is to put the whole program to a particular memory range in memory. In my code I am calling sscanf function. And I was able to place the main function i wrote in a particular section, say 0x1E000, But my problem is that the sscanf function is defined in a different memory, say 0x200. My goal is to put all my code in 0x1E000 -> 0x1F000 range.
@ted That is possible, just write a custom linker script (please read the link in my answer) and place all .text* segments at the desired location. That will place all code in that memory location.
Thanks @Joachim I was trying to create a new section for main and position it in the memory, So linker was placing only main contents in that section not library functions. With .text segment placing it works perfectly fine :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.