5

I need to include a binary program in my project. I use objcopy to create an object file from a binary file. The object file can be linked in my program. objcopy creates appropriate symbols to access the binary data.

Example

objcopy -I binary -O elf32-littlearm --binary-architecture arm D:\Src\data.jpg data.o

The generated symbols are:

_binary_D__Src_data_jpg_end
_binary_D__Src_data_jpg_size
_binary_D__Src_data_jpg_start

The problem is that the symbols include the path to the binary file D__Src_. This may help when binary files are included from different location. But it bothers me that the symbols changes when I get the file from a different location. Since this shall run on several build stations, the path can't be stripped with the --redefine-sym option.

How do I get rid of the path in the symbol name?

harper
  • 13,345
  • 8
  • 56
  • 105
  • 1
    possible duplicate of [objcopy prepends directory pathname to symbol name](http://stackoverflow.com/questions/15594988/objcopy-prepends-directory-pathname-to-symbol-name) – Daniel Dec 17 '13 at 18:28
  • @Daniel Did you read, *why* I rejected the `--redefine-sym` approach? – harper Dec 18 '13 at 09:58
  • I agree that --redefine-sym is not a good solution, but I think your question is substantively the same as the OP. BTW: I'm looking for an answer to the same question. My current workaround is to copy the file to the directory, do the objcopy then rm the copy in the Makefile -- Ugly kludge. I think you could also cd to the source directory and redirect the output of objcopy back to the orignal directory. -- still a kludge IMO. – Daniel Dec 19 '13 at 15:27

2 Answers2

2

I solved this problem by using this switch in objcopy:

--prefix-sections=abc

This gives a way to uniquely identify the data in your binary object file (ex. binary.o)

In your linker script you can then define your own labels around where you include the binary.o. Since you are no longer referencing anything in binary.o the binary will be thrown out by the linker if you use -gc-sections switch. The section in binary.o will now be abc.data. Use KEEP in your linker script to tell the linker not to throw out binary.o. Your linker script will contain the following:

__binary_start__ = .;
KEEP(*(abc.data))
binary.o
*(abc.data)
. = ALIGN(4);
__binary_end__ = .;
Blanco
  • 86
  • 4
0

The switch --localize-symbols works for me.

bardi
  • 1
  • 1