How to force linker to keep section? [message #1786590] |
Mon, 07 May 2018 23:51  |
Eclipse User |
|
|
|
I have some problem about linker optimization.
I am using:
Eclipse IDE for C/C++ Developers Oxygen Release (4.7.0)
GNU Tools ARM Embedded(Compiler, Linker)
In my project:
IncludeBin.S:
.section .rawdata
.global _binary_mydata_start
.align 4
_binary_mydata_start:
.incbin "./P0_0Toggle.bin"
.global _binary_mydata_end
_binary_mydata_end:
main.cpp:
...
extern uint8_t _binary_mydata_start[];
extern int _binary_mydata_end;
extern int _binary_mydata_size;
...
int
main (int argc, char* argv[])
{
trace_printf ("_binary_mydata[0]=0x%02x\n", _binary_mydata_start[0]);
trace_printf ("_binary_mydata[1]=0x%02x\n", _binary_mydata_start[1]);
...
}
section.ld:
...
.myvars :
{
*(.rawdata)
} > MYVARS
...
I want to using _binary_mydata_start[] in main.cpp, but it seems linker optimize .rawdata section when building project.
Map file contains .rawdata section information. But I do not see .rawdata section in .hex file.
Map file:
...
.myvars 0x60200000 0x800
*(.rawdata)
.rawdata 0x60200000 0x800 ./src/IncludeBin.o
0x60200000 _binary_mydata_start
0x60200800 _binary_mydata_end
...
I tried to add KEEP in linker script, but it doesn't work.
Any advice on how to force keep section? I would be grateful for any suggestions.
|
|
|
|
Re: How to force linker to keep section? [message #1786677 is a reply to message #1786631] |
Wed, 09 May 2018 04:41  |
Eclipse User |
|
|
|
Thank you for your hint.
I should add "a" flag for section in assembler file.
.section .rawdata, "a" <=======
...
With this flag, GNU tools will include the section into the elf file.
This is elf headers without "a" flag:
Elf file type is EXEC (Executable file)
Entry point 0x45
There are 3 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00000000 0x00000000 0x01117 0x01117 RWE 0x10000
LOAD 0x020000 0x20000000 0x00001118 0x00078 0x00078 RW 0x10000
LOAD 0x020078 0x20000078 0x20000078 0x00000 0x001a0 RW 0x10000
Section to Segment mapping:
Segment Sections...
00 .isr_vector .inits .text
01 .data
02 .bss ._check_stack
And this is elf header with "a" flag:
Elf file type is EXEC (Executable file)
Entry point 0x45
There are 4 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00000000 0x00000000 0x01117 0x01117 RWE 0x10000
LOAD 0x020000 0x20000000 0x00001118 0x00078 0x00078 RW 0x10000
LOAD 0x020078 0x20000078 0x20000078 0x00000 0x001a0 RW 0x10000
LOAD 0x030000 0x60200000 0x60200000 0x00800 0x00800 R 0x10000
Section to Segment mapping:
Segment Sections...
00 .isr_vector .inits .text
01 .data
02 .bss ._check_stack
03 .myvars
Thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.52639 seconds