tag system

9
1 Using a tag system GAYET Thierry

Upload: thierry-gayet

Post on 11-May-2015

355 views

Category:

Technology


1 download

DESCRIPTION

Tag system

TRANSCRIPT

Page 1: Tag system

1

Using a tag system

GAYET Thierry

Page 2: Tag system

2

PLAN

GoalELF-file layoutTagging processExtracting a tagTools availableLinks about

Page 3: Tag system

3

Goal

For an ELF make by the build system (buildroot + autotools) this is possible to customize its

Sections (data or others) ; it can be easily integrated into the autotools template.

It could be information about the build process such as the toolchain release, the datetime, and so on.

It may be only an unique ID stored in a database for tracing the build specification

The aim is to add a traceability for each build objects in order to know how a binary have been compile by/with (what toolchain kind/version :version of gcc, libc, … ).

Page 4: Tag system

4

ELF-file layout

Each ELF file is made up of one ELF header, followed by file data. The file data can include:

Program header table, describing zero or more segments

Section header table, describing zero or more sections

Data referred to by entries in the program header table, or the section header table

The segments contain information that is necessary for runtime execution of the file, while sections contain important data for linking and relocation. Each byte in the entire file is taken by no more than one section at a time, but there can be orphan bytes, which are not covered by a section. In the normal case of a Unix executable one or more sections are enclosed in one segment.

Page 5: Tag system

5

Tagging process

Example for creating a temporally TAG file:

touch ./myTag

echo "SDK = " $(NOM_PROJET) $(VERSION_PROJET) - $(RELEASE_DATE) >> ./myTag

echo "TOOLCHAIN = " $(TOOLCHAIN_VERSION) GCC v$(GCC_VERSION) >> ./myTag

echo "TARGET = " $(TARGET_ID) >> ./myTag

echo "BUILT = " $(shell date +"%Y/%m/%d %H:%M:%S") on $(BUILD_HOST) $(BUILD_KIND) >> ./myTag

This TAG can be easily updated according to our specifications.

Revove any previous MYTAG section from the ELF header of the file :

objcopy --remove-section MYTAG ./MyElfFileToModify

Adding a new section called MYTAG in the ELF file and update the ELF file with the previous tag created :

objcopy --add-section MYTAG=./myTag --set-section-flags MYTAG=contents ./MyElfFileToModify

Removing the temporally file:

rm -f ./myTag

Page 6: Tag system

6

Extracting a tag (using the libELF)

Example of source code available here :http://www.nextinnovation.org/doku.php?id=search_elf_symbol&s[]=tag#source_code_searchsymc

Page 7: Tag system

7

Build the extraction tool

Compilation:

gcc -g -Wall -I$LIB_ELF_PATH/include -c searchsym.c -o searchsym.o

Linking:

gcc -L$LIB_ELF_PATH/lib -lelf searchsym.o -o searchsym

Page 8: Tag system

8

Tools available

Lot of tools exist for managing/extracting ELF formats :

Libelf

Objcopy

Objdump

Readelf

And many others...

Page 9: Tag system

9

Links about

http://manpagesfr.free.fr/man/man5/elf.5.html

http://elftoolchain.sourceforge.net/for-review/libelf-by-example-20100111.pdf

http://developers.sun.com/solaris/articles/elf.html