gcc linker - map all object files in an archive to

2019-08-12 04:42发布

问题:

In a gcc linker file, how do you map all functions of all .objs in an archive to a certain section?

I know how to do it function-by-function inside the source file but I'd like to do it in the linker file by .obj name.

I found this post in the gcc mailing lists but for me it's not working.

I modified my .ld by copying what the poster did...

.dflash_code :
  {
    *archive.dlb: // this is my archive file
  } >dflash

...but it didn't work.

When I add __attribute__((section(".dflash_code"))) to a function, amount of overflow the linker reports decreases so I know the linker is paying attention to the __attribute__.

However, I'd really like to do it for an entire archive (that's the .dlb).

I tried to do it just based on one .obj file and even that doesn't work

.dflash_code :
  {
    *compile.doj //my object file
  } >dflash

UPDATE

Actually, looks like it is working (kinda): it is outputting the contents of ATI_micropython.dlb to .dflash_code except for the .text sections.

回答1:

The syntax I tried was correct.
The problem was that in my linker file, I had a SECTION statement above the following SECTION statement

.dflash_code :
  {
    *archive.dlb: // this is my archive file
  } >dflash

that put all *.text sections in a section that was getting overfull.

Even in this errored condition, the linker produced a .map and examining this .map showed that all sections of the objects inside archive.dlb except for .text were being placed in the intended .dflash_code.

I moved the .dflash_code section above the portion that was referencing *.text and it now works.



标签: c++ c gcc linker