Linker Script - Placing a section at the end of a memory region

前端 未结 5 1528
后悔当初
后悔当初 2020-12-24 09:15

I have searched far and wide for how to do this and have failed to come up with an answer.

My memory layout is as follows:

Fake Address | Section
            


        
5条回答
  •  不知归路
    2020-12-24 10:15

    I was able to accomplish something similar by making linking a two-step process. First I compile the section in question to its own object file. In my case I had a metadata section generated from an assembly file. gcc -c will compile the source into object files, but not link them.

    gcc -c  metadata.s  -o metadata.o
    

    You could also build your whole program, then extract just the section in question with objcopy.

    gcc -c  main.cc  -o main.o
    objcopy --only-section=.metadata  main.o  metadata.o
    

    Now I build and link the rest of the program, and include the object file among the linker's input.

    gcc metadata.o  ../main.o  -o Program.elf  -T linkerscript.ld   
    

    The linker reads the section .metadata from the object file, and I can reference its size in the linker script.

提交回复
热议问题