Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » How to force linker to keep section?
How to force linker to keep section? [message #1786590] Tue, 08 May 2018 03:51 Go to next message
Wilson Wang is currently offline Wilson WangFriend
Messages: 4
Registered: April 2018
Junior Member
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.
KEEP(*(.rawdata))

Any advice on how to force keep section? I would be grateful for any suggestions.
Re: How to force linker to keep section? [message #1786631 is a reply to message #1786590] Tue, 08 May 2018 19:37 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
It seems that the section is there, it has been allocated 0x800 bytes. The linker map should include a list of discarded sections, and if your raw data is not mentioned there, it is not discarded. You can check by disassembling the ELF file:
arm-none-eabi-objdump -D myfile.elf >myfile.dis

(I made a guess that the toolkit you're using is the arm-none-eabi version of GNU tools).

My guess is the the code changing the ELF to hex does not know to include the section into the hex file. Usually, the tool is the objcopy utility of the GNU binutils package.

You should get the GNU binutils manual from the GNU website, and read the parts of ld, objcopy and objdump.


--

Tauno Voipio
Re: How to force linker to keep section? [message #1786677 is a reply to message #1786631] Wed, 09 May 2018 08:41 Go to previous message
Wilson Wang is currently offline Wilson WangFriend
Messages: 4
Registered: April 2018
Junior Member
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!
Previous Topic:How to link our own libararies in eclipse?
Next Topic:Code indexing based on build output
Goto Forum:
  


Current Time: Thu Apr 25 23:28:34 GMT 2024

Powered by FUDForum. Page generated in 0.04523 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top