[Dprglist] gcc compiler/linker question - how to force code at given memory location?

Kipton Moravec kip at kdream.com
Tue Feb 11 10:51:41 PST 2020


Am I confused, or Did Clay ask about Microchip and Dave gave him the 
answer for ST chips?

I do not check the list very often. So sorry for the delay.

Clay did you find the answer you wanted? if not I can probably help with 
a little research.

I think there is an ABSOLUTE macro when you define the variable that 
lets you define the address of the variable. They use it in the .h files 
that you include for HW, as many of them are memory mapped. I do not 
have a Microchip project handy to look, but if you are still having 
problems let me know. I think it will take 30 minutes to get the exact 
answer.

It is documented in the Compiler Reference for the compiler you are 
using C8, C16, C32. Go to the compiler directory and find the docs 
subdirectory and get the PDF.

Kip

On 1/30/20 11:32 PM, Dave Hylands via DPRGlist wrote:
> You need to create a linker script file and use that to control where 
> things go.
>
> The linker controls things using object files and sections. By 
> default, functions go into .text sections. There are compiler options 
> which cause each function to go into a separate section.
>
> The syntax in the linker script files is a bit arcane.
> https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html#SEC6
>
> Here's an example linker file used on an STM32F103 microcontroller and 
> it places the isr vectors at address 0x8002000.
> https://github.com/dhylands/stm32-test/blob/master/board-STM32F103-Mini/STM32F103RBTx_FLASH.ld
>
> This linker file shows putting particular object files into a 
> particular section:
> https://github.com/micropython/micropython/blob/master/ports/stm32/boards/common_ifs.ld#L35
>
>
> On Thu, Jan 30, 2020 at 12:55 PM Clayton Timmons via DPRGlist 
> <dprglist at lists.dprg.org <mailto:dprglist at lists.dprg.org>> wrote:
>
>
>     I'm searching for an answer to a simple question.  My friend
>     Google tried to help but so far Google hasn't given me a good
>     answer.   I'm hoping some savvy DPRG member probably has the
>     wisdom I seek.
>
>
>
>     I'm using a microchip processor writing code in C.  The code
>     consists of several C source files which are compiled into object
>     code then linked together.  Something like this simplified example.
>
>     gcc -c   foo.c             <<<  compile C code into object file
>     gcc -c   bar.c             <<<  compile C code into object file
>
>     gcc   foo.o  bar.o   -o  foobar.cof     <<< link all object files
>     together
>
>     The final output is in cof format which is converted to hex format
>     used by the programmer.   There is a map file created by the
>     linker which allows me to see where all the C functions end up in
>     memory, something like this.
>
>     External Symbols in Program Memory (by address):
>
>                          .  .  .
>                       0x003b18                  _foo
>                          .  .  .
>                       0x003e1e                  _bar
>
>
>     My question is -   How can I force the linker to put a specific
>     function at a specific location?     Say I want the function bar
>     to start at 0x004000.
>
>     There should be some compiler or linker directives to accomplish that.
>
>     Any help is appreciated.
>
>     -Clay Timmons-
>
>
>
>
>
>
>
>
>
>     _______________________________________________
>     DPRGlist mailing list
>     DPRGlist at lists.dprg.org <mailto:DPRGlist at lists.dprg.org>
>     http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org
>
>
>
> -- 
> Dave Hylands
> Peachland, BC, Canada
> http://www.davehylands.com
>
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at lists.dprg.org
> http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dprg.org/pipermail/dprglist-dprg.org/attachments/20200211/0dfe8156/attachment.html>


More information about the DPRGlist mailing list