Atmel studio position-indepenent-code generate unwanted code

79 views Asked by At

I'm using Atmel studio and programing a ATSAMV71 board.

For some reason, I need to generate position-independent-code. Although, when I add the -fpic tag, it also generates some code that I don't understand at the end of the allocated memory.

0x00408200  10 69 40 20 99 1c 40 00 61 39 40 00 2d 1a 40 00 95 0e 40 00 6b 29 40 00 a9 34 40 00 35 10 40 00  .i@ ™[email protected]@.-.@[email protected])@.©[email protected].@.
0x00408220  d5 1a 40 00 a9 16 40 00 ac 67 40 20 29 14 40 00 a8 00 40 20 fd 0d 40 00 d1 13 40 00 61 14 40 00  Õ.@.©.@.¬g@ ).@.¨.@ ý.@.Ñ[email protected].@.
0x00408240  05 39 40 00 99 1f 40 00 00 69 40 20 95 0c 40 00 3d 3b 40 00 65 34 40 00 a9 18 40 00 dd 18 40 00  .9@.™[email protected]@ ..@.=;@.e4@.©.@.Ý.@.
0x00408260  f1 24 40 00 f1 20 40 00 29 17 40 00 9c 57 40 20 bc 00 40 20 00 00 40 00 c9 2e 40 00 0d 13 40 00  ñ$@.ñ @.).@.œW@ ..@ ..@.É.@...@.
0x00408280  75 16 40 00 d8 3f 40 00 85 2b 40 00 10 6d 40 20 00 01 40 20 f5 27 40 00 13 3d 40 00 20 00 40 20  u.@.Ø?@[email protected]@ ..@ õ'@..=@. .@ 
0x004082A0  1d 3a 40 00 cd 27 40 00 f4 67 40 20 2c 03 40 20 91 19 40 00 7d 06 40 00 00 80 40 00 41 1d 40 00  .:@.Í'@.ôg@ ,.@ ‘.@.}.@..€@.A.@.
0x004082C0  cf 2e 40 00 b9 0f 40 00 d5 01 40 00 49 20 40 00 91 2b 40 00 21 33 40 00 ad 3c 40 00 41 1c 40 00  Ï.@...@.Õ[email protected] @.‘+@.!3@..<@.A.@.
0x004082E0  2d 2b 40 00 c9 0c 40 00 00 27 40 20 e9 02 40 00 e9 28 40 00 99 28 40 00 61 35 40 00 65 29 40 00  -+@.É.@..'@ é.@.é(@.™(@[email protected])@.
0x00408300  79 0e 40 00 39 06 40 00 3d 0c 40 00 3c 05 40 20 6d 26 40 00 8d 15 40 00 61 1a 40 00 45 21 40 00  [email protected].@.=.@.<.@ m&@[email protected][email protected]!@.
0x00408320  05 27 40 00 31 22 40 00 71 23 40 00 2d 36 40 00 11 37 40 00 30 68 40 20 4d 03 40 00 70 27 40 20  .'@.1"@.q#@[email protected]@.0h@ [email protected]'@ 
0x00408340  b9 26 40 00 c7 2a 40 00 35 39 40 00 79 2a 40 00 a0 57 40 20 a9 15 40 00 6d 05 40 00 d1 1d 40 00  .&@.Ç*@[email protected]*@. W@ ©[email protected].@.Ñ.@.
0x00408360  31 28 40 00 27 32 40 00 9f 19 40 00 71 1b 40 00 a1 04 40 00 59 3a 40 00 81 12 40 00 b9 14 40 00  1(@.'2@.Ÿ[email protected].@.¡[email protected]:@...@...@.
0x00408380  f0 6e 40 20 09 05 40 00 30 03 40 20 65 38 40 00 f5 3c 40 00 9d 20 40 00 d5 2e 40 00 bd 2a 40 00  ðn@ [email protected].@ e8@.õ<@.. @.Õ.@..*@.
0x004083A0  3d 04 40 00 1d 23 40 00 01 15 40 00 29 3d 40 00 45 28 40 00 59 3b 40 00 b5 1b 40 00 19 37 40 00  =.@..#@...@.)[email protected](@.Y;@.µ[email protected]@.
0x004083C0  15 1b 40 00 35 2d 40 00 3d 12 40 00 35 24 40 00 25 14 40 00 b5 03 40 00 f0 72 40 20 9d 2a 40 00  [email protected]@[email protected]$@.%.@.µ.@.ðr@ .*@.
0x004083E0  e9 14 40 00 39 3d 40 00 38 68 40 20 95 29 40 00 e9 22 40 00 d3 27 40 00 d9 15 40 00 b5 14 40 00  é[email protected][email protected]@ .)@.é"@.Ó'@.Ù.@.µ.@.
0x00408400  7d 2e 40 00 6d 22 40 00 f5 21 40 00 51 15 40 00 55 0f 40 00 7d 14 40 00 b5 21 40 00 1c 03 40 20  }[email protected]"@.õ[email protected][email protected].@.}.@.µ!@...@ 
0x00408420  8b 2b 40 00 f4 00 40 20 39 28 40 00 d5 06 40 00 b5 0e 40 00 21 19 40 00 7d 21 40 00 84 27 40 20  .+@.ô.@ 9(@.Õ.@.µ.@.!.@.}!@..'@ 
0x00408440  90 3f 40 20 e9 16 40 00 59 16 40 00 71 29 40 00 a9 22 40 00 15 32 40 00 19 16 40 00 f0 70 40 20  .?@ é[email protected][email protected])@.©"@..2@...@.ðp@ 
0x00408460  09 30 40 00 d9 05 40 00 59 37 40 00 54 68 40 20 25 37 40 00 69 18 40 00 c1 38 40 00 19 07 40 00  .0@.Ù[email protected]@.Th@ %[email protected].@.Á8@...@.
0x00408480  35 29 40 00 35 32 40 00 cd 2a 40 00 c9 19 40 00 7c 68 40 20 7d 37 40 00 d5 2b 40 00 80 68 40 20  5)@.52@.Í*@.É.@.|h@ }7@.Õ+@.€h@ 
0x004084A0  21 2f 40 00 95 1a 40 00 81 02 40 00 95 38 40 00 9c 68 40 20 ed 13 40 00 c4 68 40 20 00 00 00 00  !/@...@[email protected]@.œh@ í.@.Äh@ ....

When I look at the disassembly, this code makes no sense. For example, the first lines are:

00408200 10.69                 ldr  r0, [r2, #16]        
00408202 40.20                 movs r0, #64      
00408204 99.1c                 adds r1, r3, #2       
00408206 40.00                 lsls r0, r0, #1       
00408208 61.39                 subs r1, #97      
0040820A 40.00                 lsls r0, r0, #1       
0040820C 2d.1a                 subs r5, r5, r0       
0040820E 40.00                 lsls r0, r0, #1
00408210 95.0e                 lsrs r5, r2, #26      
00408212 40.00                 lsls r0, r0, #1       
00408214 6b.29                 cmp  r1, #107         
00408216 40.00                 lsls r0, r0, #1       
00408218 a9.34                 adds r4, #169

Did I miss something? Because, in addition to the space taken by this unwanted code, it goes to one of the sections that I reserved in the linker script and make this section overflow ("Error region `ApplicationFooter' overflowed by 712 bytes"). I need to increase this section length in order to compile the code.

When I disable "-fpic", this part of code is not generated and I don't have to increase the section - that I have created - size.

Here is the code related to this section:

linker script:

....
/* Memory Spaces Definitions */

    MEMORY
    {
      rom (rx)              : ORIGIN = 0x00400000, LENGTH = 0x00007E00
      ApplicationFooter(rx) : ORIGIN = 0x00407E00, LENGTH = 0x00000200
      ram (rwx)             : ORIGIN = 0x20400020, LENGTH = 0x00060000
    }
    
   ...
    
    /* Section Definitions */
    SECTIONS
    {
        .ApplicationFooter : 
        { 
            KEEP(*(.ApplicationFooterData .ApplicationFooterData.*)) 
        } > ApplicationFooter
        .text :
        {
        ...

In my code:

/* sizeof(TU_ApplicationFooter) = 0x200 */
typedef union
{
    TS_ApplicationFooter sApplicationFooter;
    uint8_t au8ApplicationFooter[512];
}TU_ApplicationFooter;

__attribute__ ((section(".ApplicationFooterData")))
const TU_ApplicationFooter uBootLoaderFooter =
{
    /* Some init values */
};
0

There are 0 answers