Question

Background

I am using the GNU Tools for ARM Embedded Processors compiler, which is a GCC compiler. I am currently working in a Windows environment.

I am building a relatively large project, and have successfully compiled all the source code, but am facing a challenge during the link stage. This particular platform as two separate regions of RAM, and I need to map certain sections of the object code to specific regions.

I think I should be able to use a linker script such as:

SECTIONS
{
   ER_CCM 0x10000000:
   {
      * (.bss)
   }
   ER_SRAM 0x20000000:
   {
      someLib.obj (.bss)
   }
}

However, my problem is that the compiler is outputting .lib files (archives) instead of .obj files. The linker is being invoked in the current directory of all the archive files with the following syntax:

ld.exe --library-path=C:\SomePath\lib --Map C:\Somepath\bin\mapfile.map --script=C:\Somepath\bin\linkscript.ldf -( file1.lib file2.lib ... -)

Even though the .lib files contain references to the .obj files, the linker complains that it cannot find the file someLib.obj probably because it does not have the full path given to know what file the mapping is referring to.

Supplying the linker with the full path in the linker script also does not appear to work; the symbols contained within the specified object file are still showing up in the first section of memory.

Questions

Is the syntax in the sample linker script valid? Will the wildcard in the first section prevent the specified file in the section section from being mapped correctly?

How can I specify to the linker to take certain object files within archive files to map to specific regions? Is this even possible?

Was it helpful?

Solution

Well as it turns out, my main question is a duplicate of Put gcc libs .data in specific section?, though since I also asked about the wildcard placement / order I will leave this question posted.

The answer to my first quest: placing a wildcard entry before other sections will prevent those other sections from properly importing the specified object file. This behavior is linker-specific, since I have seen other linkers where this is not the case.

The way to resolve this is to be sure to place the generic section last in the linker script:

SECTIONS
{
   ER_SRAM 0x20000000:
   {
      someLib.obj (.bss)
   }
   ER_CCM 0x10000000:
   {
      * (.bss)
   }
}

As for referring to the object files contained in archive (.lib) files. The answer was given in the linked post, but here it is again:

Add a wildcard to the embedded object file in the section delcaration:

ER_SRAM 0x20000000:
{
   *someLib.obj (.bss)
}

The caveat here is that since a wildcard is used in the object file name, if the file is missing or the entry is misspelled, the linker will not throw an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top