Build system: implement REUSE with SPDX identifiers
[lttng-ust.git] / tests / unit / ust-elf / README.md
CommitLineData
e03d7c66
MJ
1<!--
2SPDX-FileCopyrightText: 2016 Antoine Busque <abusque@efficios.com>
3
4SPDX-License-Identifier: CC-BY-4.0
5-->
6
7# lttng\_ust\_elf unit tests
22609c7a
AB
8
9This is a series of unit tests for LTTng UST's ELF parser. The parser
10is used to retrieve memory size, build ID, and debug link information
11from ELF objects (standalone executable or shared object) for base
12address statedump or dl events.
13
14The parser should technically be able to read ELF files from any 32-
15or 64-bit architecture, little- or big- endian.
16
17However, to restrict the total amount of testing done, only 4
18architectures representing all combinations of bitness and endianness
19are currently tested:
20
21* x86
e03d7c66 22* x86\_64
22609c7a 23* armeb
e03d7c66 24* aarch64\_be
22609c7a
AB
25
26For each architecture, there is a corresponding subdirectory under
27`data`, and each of these directories contains exactly 2 files,
28`main.elf` and `main.elf.debug`.
29
30The ELF files are generated from the trivial `main.c` program found in
31`data/`, using GNU toolchains. The program contains a static array in
32order to ensure the creation of a `.bss` section in the ELF file,
33which is one of the multiple factors leading to different file and
34in-memory size.
35
36The program is compiled with `gcc -g main.c -o main.elf`. On certain
37architectures, it is necessary to explicitly specify the
38`-Wl,--build-id=sha1` flags to include a build ID in the resulting
39executable.
40
41The debug information bundled in `main.elf` is then copied into
42`main.elf.debug` and stripped, and a debug link pointing to this file
43is added to the executable. The commands used are as follow:
44
e03d7c66
MJ
45```
46$ objcopy --only-keep-debug main.elf main.elf.debug
47$ strip -g main.elf
48$ objcopy --add-gnu-debuglink=main.elf.debug main.elf
49```
968f523d
AB
50
51There is also a series of tests used to check detection of
52position-independent code (PIC). These tests use three pre-compiled
53ELF files found under `data/pic/`, namely `hello.exec`, `hello.pie`,
54and `hello.pic`. These can be re-generated using the files `hello.c`
55and `libhello.c`, with the following commands:
56
e03d7c66
MJ
57```
58$ gcc hello.c -o hello.exec
59$ gcc hello.c -fPIC -pie -o hello.pie
60$ gcc -shared -o hello.pic -fPIC libhello.c
61```
This page took 0.031667 seconds and 4 git commands to generate.