tag system
DESCRIPTION
Tag systemTRANSCRIPT
![Page 1: Tag system](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/1.jpg)
1
Using a tag system
GAYET Thierry
![Page 2: Tag system](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/2.jpg)
2
PLAN
GoalELF-file layoutTagging processExtracting a tagTools availableLinks about
![Page 3: Tag system](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/8.jpg)
8
Tools available
Lot of tools exist for managing/extracting ELF formats :
Libelf
Objcopy
Objdump
Readelf
And many others...
![Page 9: Tag system](https://reader036.vdocuments.us/reader036/viewer/2022082920/5550c9c8b4c905e8318b47f5/html5/thumbnails/9.jpg)
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