How to relocate standard libary code to a new section

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I have relocated code to a new section called .mysection using the following linker flag in Atmel Studio

-Wl,--section-start=.mysection=0x6000 

 

and using the section attribute for my own functions

__attribute__ ((section (".mysection")))

 

How can I achieve the same result for dependencies of those same functions such as avr-libc.fplib?

My project's output memory map shows that they remain in the .text section.

This topic has a solution.
Last Edited: Sat. Oct 7, 2017 - 03:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that avr-objcopy will do what you want.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

Last Edited: Fri. Oct 6, 2017 - 03:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

macdoma1 wrote:
such as avr-libc.fplib?
As you say the fplib have already been built to an assigned section. For example:

fixsfdi.o:     file format elf32-avr
rwxrwxr-- -1/-1    976 Apr 02 04:14 2016 fixsfdi.o
architecture: avr:5, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000034  2**0
                  ALLOC
  3 .text.avr-libc.fplib 00000078  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
SYMBOL TABLE:
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .text.avr-libc.fplib   00000000 .text.avr-libc.fplib
00000000 g     F .text.avr-libc.fplib   00000078 __fixsfdi
0000000a g       .text.avr-libc.fplib   00000000 __fixunssfdi
00000000         *UND*  00000000 __fp_splitA
00000000         *UND*  00000000 __fp_negdi

So the code is already in .text.avr-libc.fplib so can't you simply specify a section start for that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Thanks both for responding!

So the code is already in .text.avr-libc.fplib so can't you simply specify a section start for that?

 

I tried the following linker flags:

 -Wl,--section-start=.mysection=0x6000 -Wl,--section-start=.text.avr-libc.fplib=0x5500

 

but the only change I observe in the linker map output file is the following text appended to the end

 

.text.avr-libc.fplib
                0x00005500        0x0

 

 

 

Last Edited: Fri. Oct 6, 2017 - 03:31 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I seem to obtain the desired result by additionally using a modified linker script with the following entry within SECTIONS, but I'm not sure if this is good practice:

 

  .mysection :
  {
 *(.text.avr-libc.fplib)
  }

 

/* text section entry follows below*/

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
So the code is already in .text.avr-libc.fplib so can't you simply specify a section start for that?
Probaly he can.

That said, OP might want the linker to do the math.

It seems to me the issue is similar to selecting a temporary register for inline assembly:

Use a clobber or use a dummy variable as a parameter.

macdoma1 wrote:
I tried the following linker flags:

 -Wl,--section-start=.mysection=0x6000 -Wl,--section-start=.text.avr-libc.fplib=0x5500

 

but the only change I observe in the linker map output file is the following text appended to the end

 

.text.avr-libc.fplib
                0x00005500        0x0

Is the fplib object code showing up anywhere?

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the fplib object code showing up anywhere?

Yes in that attempt, the original entries for .text.avr-libc.fplib still appeared in the same place as before amongst other code built into the .text section.

 

Last Edited: Fri. Oct 6, 2017 - 04:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm curious. Why would you want to do this? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a temporary work around for a bootloader that doesn't fit in the boot flash section of a particular device.  For demonstration purposes, I want to put some of the overflow (which is not critical for self-programming) into the RWW section of flash, protecting it with software measures only. Although this is approach is not recommended in your FAQ,  the demonstration would justify the move to new hardware with an appropriate boot flash section size.

 

Thanks for your advice!

Last Edited: Sat. Oct 7, 2017 - 02:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK. I'll bite again. Why would something as simple as a bootloader ever need FP? Sounds like you are making it over complicated.
.
But, yes, doing it in the linker script rather than trying to use section-start 's looks like the best solution

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

macdoma1 wrote:
Thanks both for responding!

So the code is already in .text.avr-libc.fplib so can't you simply specify a section start for that?

 

I tried the following linker flags:

 -Wl,--section-start=.mysection=0x6000 -Wl,--section-start=.text.avr-libc.fplib=0x5500

 

but the only change I observe in the linker map output file is the following text appended to the end

 

.text.avr-libc.fplib
                0x00005500        0x0

I think the reason that --section-start did not work is that it applies to output sections and .text-avr-libc.fplib is an input section.

It becomes part of the .text output section.

A gcc attribute can specify an input section.

If the input section is not mentioned in the relevant linker script(s),

it becomes an output section with the same name.

--section-start works.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?