How to put a lib in specifiled postion (gcc arm)?

Asked by 孙华

I want to put a (staitc )lib in specifiled postion (gcc arm).
but i don't know how to do it .

the lib is libxx.a, it should be puted at 0x00000400 addr.

is there anyone do like this before ?

I try it like follow,but failled .

/* Specify the memory areas */
MEMORY
{
  FLASH_BOOT (rx) : ORIGIN = 0x00000000, LENGTH = 1K
  FLASH_LIB (rx) : ORIGIN = 0x00000400, LENGTH = 3K
  FLASH (rx) : ORIGIN = 0x00001000, LENGTH = 124K
  RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
  MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}

/* Define output sections */
SECTIONS
{
...

   lib :
   {
       libxx.a (.text, .rodata)
   } > FLASH_LIB

  .text :
  {
    *(.text*)
    *(.rodata*)
  } 〉FLASH

...

}

I know that lib is located at FLASH section from the map file.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
孙华
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi 孙华,

In the extract you gave, FLASH_LIB starts at 0x400 (see ORIGIN) rather than 0x1000. Is it a typo when copying or the value is the same in your real code?

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#2

Hi Thomas Preud'homme (thomas-preudhomme),

   Thanks for your Promption.
   I correct the mistake.
   :-)

Revision history for this message
孙华 (sun-hua-cx) said :
#3

Hi Thomas Preud'homme (thomas-preudhomme),

   Thanks for your Promption.
   I correct the mistake.
   :-)

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#4

Hi 孙华,

Can you show how you link your application and what is the output of readelf -S ?

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#5

Hi Thomas Preud'homme (thomas-preudhomme),

  I‘m sorry.
  I can't copy the link file and the ouput , because the program is in intranet pc .

  But i will do my best to let you know the phenomenon .

  I know that lib is located at FLASH section from the map file and the lib section is null.
  How to change the linker file ?

Best regards.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#6

Hi 孙华,

Can you try with "libxx.a: (.text, .rodata)" (ie adding a colon after the name of the library)?

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#7

Hi Thomas Preud'homme (thomas-preudhomme),

  I‘m sorry.
  It does't work.

Best regards.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#8

Hi,

I'm not sure whether a comma can be included when specifying the input sections. Can you try:

   lib :
   {
       libxx.a (.text .rodata)
   } > FLASH_LIB

If it still does'nt work maybe you can try libxx.a:*.

Best regards

Revision history for this message
孙华 (sun-hua-cx) said :
#9

Hi Thomas Preud'homme (thomas-preudhomme),

   I tryed both methods, but all failed .
   Does it support to put a libxx.a in a specifiled postion?

   I know ARM MDK scatter just put many xx.o (+RO) (xx.o is one of obj in lib),
 and then lib is puted in a a specifiled postion.

Best regards.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#10

Hi 孙华,

Yes, this toolchain allows to control where a code will be found in memory. It's a bit difficult to debug without being able to reproduce. Let's try something simpler. Select one of the file in your archive that contains a .text section (I'll suppose the file is foo.o). Then rewrite the lib output section to:

.lib :
{
  libxx.a:foo.o (.text)
} > FLASH_LIB

And look if the .text of the foo.o file in libxx.a is in .lib section of the output file. If not there is something really strange going on as this is an almost direct example from the documentation.

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#11

Hi Thomas Preud'homme (thomas-preudhomme),

   I have tryed again, but failed .
   Foo.o file stills in .text section ( > FLASH) not in .lib section (〉FLASH_LIB).

Best regards.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#12

Can you also try to replace *(.text*) with *(EXCLUDE_FILE (libxx.a:*) .text) from the FLASH output section?

If it still does not work, what about using *libxx.a:foo.o?

Best regards,

Thomas

Revision history for this message
孙华 (sun-hua-cx) said :
#13

Hi Thomas Preud'homme (thomas-preudhomme),

    It also does't work .It's so strange,why does't work on libxx.a?
    Is there somebody do like that successfully?

    Thanks for your kind help!

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#14

Hi Thomas Preud'homme (thomas-preudhomme),

SECTIONS
{
...

   lib :
   {
      not_in_lib.o (.text, .rodata)
   } > FLASH_LIB

  .text :
  {
    *(EXCLUDE_FILE (not_in_lib.o) .text*)
    *(.rodata*)
  } 〉FLASH

...

}

 I know not_in_lib.o is in lib section by read map file .

Best regards.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#15

Alright, that's progress. So now try to remove the EXCLUDE_FILE and see if it still works. If yes, try to put not_in_lib.o into its own archive (with only one member) and see if it works. By building progressively we'll figure out what's missing in the syntax.

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#16

Hi Thomas Preud'homme (thomas-preudhomme),

when remove the EXCLUDE_FILE , it stall works(Becase FLASH_LIB section is front of .text section).

  foo.o is a obj file cheated by a lib project , not one of the member in libxx.a.
  I have tryed below case ( *(EXCLUDE_FILE ( libxx.a:foo.o) .text*) or *(.text*)) , the result is same.
(many mulitiple definition of 'xxx',because lib section links a foo.o and .text section links libxx.a(contain foo.o))

SECTIONS
{
...

   lib :
   {
      foo.o (.text)
   } > FLASH_LIB

  .text :
  {
    *(EXCLUDE_FILE ( libxx.a:foo.o) .text*) or *(.text*)
    *(.rodata*)
  } 〉FLASH

...

}

It semms some operations of libxx.a have been ignored.

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#17

Hi Thomas Preud'homme (thomas-preudhomme),

when remove the EXCLUDE_FILE , it stall works(Becase FLASH_LIB section is front of .text section).

  foo.o is a obj file cheated by a lib project , not one of the member in libxx.a.
  I have tryed below case ( *(EXCLUDE_FILE ( libxx.a:foo.o) .text*) or *(.text*)) , the result is same.
(many mulitiple definition of 'xxx',because lib section links a foo.o and .text section links libxx.a(contain foo.o))

SECTIONS
{
...

   lib :
   {
      foo.o (.text)
   } > FLASH_LIB

  .text :
  {
    *(EXCLUDE_FILE ( libxx.a:foo.o) .text*) or *(.text*)
    *(.rodata*)
  } 〉FLASH

...

}

It semms some operations of libxx.a have been ignored.

Best regards.

Revision history for this message
孙华 (sun-hua-cx) said :
#19

Hi Thomas Preud'homme (thomas-preudhomme),
   The correct method is like following code.

SECTIONS
{
...
   lib :
   {
      *foo.o (.text .rodata)
   } > FLASH_LIB
  .text :
  {
    *(.text*)
    *(.rodata*)
  } 〉FLASH
...

Thanks for your help again!
Best regards.

}