xref: /aosp_15_r20/external/OpenCSD/decoder/docs/build_libs.md (revision 02ca8ccacfba7e0df68f3332a95f3180334d6649)
1*02ca8ccaSAndroid Build Coastguard WorkerBuilding and using the Library   {#build_lib}
2*02ca8ccaSAndroid Build Coastguard Worker==============================
3*02ca8ccaSAndroid Build Coastguard Worker
4*02ca8ccaSAndroid Build Coastguard Worker@brief How to build the library and test programs and include the library in an application
5*02ca8ccaSAndroid Build Coastguard Worker
6*02ca8ccaSAndroid Build Coastguard WorkerPlatform Support
7*02ca8ccaSAndroid Build Coastguard Worker----------------
8*02ca8ccaSAndroid Build Coastguard Worker
9*02ca8ccaSAndroid Build Coastguard WorkerThe current makefiles and build projects support building the library on:
10*02ca8ccaSAndroid Build Coastguard Worker - Linux and Windows, x86 or x64 hosts.
11*02ca8ccaSAndroid Build Coastguard Worker - ARM linux - AArch32 and AArch64
12*02ca8ccaSAndroid Build Coastguard Worker - ARM aarch32 and aarch64 libs, x-compiled on x86/64 hosts.
13*02ca8ccaSAndroid Build Coastguard Worker
14*02ca8ccaSAndroid Build Coastguard WorkerIn addition to building the library from the project, the library may be installed into the standard
15*02ca8ccaSAndroid Build Coastguard Worker`/usr/lib/` area in Linux, and will soon be available as a package from Linux Distros.
16*02ca8ccaSAndroid Build Coastguard Worker
17*02ca8ccaSAndroid Build Coastguard WorkerBuilding the Library
18*02ca8ccaSAndroid Build Coastguard Worker--------------------
19*02ca8ccaSAndroid Build Coastguard Worker
20*02ca8ccaSAndroid Build Coastguard WorkerThe library and test programs are built from the library `./build/<platform>` directory, where
21*02ca8ccaSAndroid Build Coastguard Worker<platform> is either 'linux' or 'win-vs2022'
22*02ca8ccaSAndroid Build Coastguard Worker
23*02ca8ccaSAndroid Build Coastguard WorkerSee [`./docs/test_progs.md`](@ref test_progs) for further information on use of the test
24*02ca8ccaSAndroid Build Coastguard Workerprograms.
25*02ca8ccaSAndroid Build Coastguard Worker
26*02ca8ccaSAndroid Build Coastguard Worker### Linux x86/x64/ARM ###
27*02ca8ccaSAndroid Build Coastguard Worker
28*02ca8ccaSAndroid Build Coastguard WorkerLibraries are built into a <tgt_dir>. This is used as the final output directory for the
29*02ca8ccaSAndroid Build Coastguard Workerlibraries in `decoder/lib/<tgt_dir>`, and also as a sub-directory of the build process for
30*02ca8ccaSAndroid Build Coastguard Workerintermediate files - `decoder/build/linux/ref_trace_decode_lib/<tgt_dir>`.
31*02ca8ccaSAndroid Build Coastguard Worker
32*02ca8ccaSAndroid Build Coastguard WorkerFor a standard build, go to the `./build/linux/` and run `make` in that directory.
33*02ca8ccaSAndroid Build Coastguard Worker
34*02ca8ccaSAndroid Build Coastguard WorkerThis will set <tgt_dir> to `builddir` for all build variants of the library. Using this only one variant of the library can be built at any one time.
35*02ca8ccaSAndroid Build Coastguard Worker
36*02ca8ccaSAndroid Build Coastguard WorkerFor development, alternatively use `make -f makefile.dev`
37*02ca8ccaSAndroid Build Coastguard Worker
38*02ca8ccaSAndroid Build Coastguard WorkerThis will set <tgt_dir> to `linux<bit-variant>/<dbg|rel>` and therefore build libraries into the
39*02ca8ccaSAndroid Build Coastguard Worker`decoder/lib/linux<bit-variant>/<dbg|rel>` directories, allowing multiple variants of the library
40*02ca8ccaSAndroid Build Coastguard Workerto be present during development.
41*02ca8ccaSAndroid Build Coastguard Worker
42*02ca8ccaSAndroid Build Coastguard Workere.g.
43*02ca8ccaSAndroid Build Coastguard Worker
44*02ca8ccaSAndroid Build Coastguard Worker`./lib/linux64/rel` will contain the linux 64 bit release libraries.
45*02ca8ccaSAndroid Build Coastguard Worker
46*02ca8ccaSAndroid Build Coastguard Worker`./lib/linux-arm64/dbg` will contain the linux aarch 64 debug libraries for ARM.
47*02ca8ccaSAndroid Build Coastguard Worker
48*02ca8ccaSAndroid Build Coastguard WorkerOptions to pass to both makefiles are:-
49*02ca8ccaSAndroid Build Coastguard Worker- `DEBUG=1`   : build the debug version of the library.
50*02ca8ccaSAndroid Build Coastguard Worker
51*02ca8ccaSAndroid Build Coastguard WorkerOptions to pass to makefile.dev are:-
52*02ca8ccaSAndroid Build Coastguard Worker- ARCH=<arch> : sets the bit variant in the delivery directories. Set if cross compilation for ARCH
53*02ca8ccaSAndroid Build Coastguard Worker                other than host. Otherwise ARCH is auto-detected.
54*02ca8ccaSAndroid Build Coastguard Worker                <arch> can be x86, x86_64, arm, arm64, aarch64, aarch32
55*02ca8ccaSAndroid Build Coastguard Worker
56*02ca8ccaSAndroid Build Coastguard WorkerFor cross compilation, set the environment variable `CROSS_COMPILE` to the name path/prefix for the
57*02ca8ccaSAndroid Build Coastguard Workercompiler to use. The following would set the environment to cross-compile for ARM
58*02ca8ccaSAndroid Build Coastguard Worker
59*02ca8ccaSAndroid Build Coastguard Worker         export PATH=$PATH:~/work/gcc-x-aarch64-6.2/bin
60*02ca8ccaSAndroid Build Coastguard Worker         export ARCH=arm64
61*02ca8ccaSAndroid Build Coastguard Worker         export CROSS_COMPILE=aarch64-linux-gnu-
62*02ca8ccaSAndroid Build Coastguard Worker
63*02ca8ccaSAndroid Build Coastguard WorkerThe makefile will scan the `ocsd_if_version.h` to get the library version numbers and use these
64*02ca8ccaSAndroid Build Coastguard Workerin the form Major.minor.patch when naming the output .so files.
65*02ca8ccaSAndroid Build Coastguard Worker
66*02ca8ccaSAndroid Build Coastguard WorkerMain C++ library names:
67*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced.so.M.m.p` : shared library containing the main C++ based decoder library
68*02ca8ccaSAndroid Build Coastguard Worker- `libcstrace.so.M`      : symbolic link name to library - major version only.
69*02ca8ccaSAndroid Build Coastguard Worker- `libcstrace.so`        : symbolic link name to library - no version.
70*02ca8ccaSAndroid Build Coastguard Worker
71*02ca8ccaSAndroid Build Coastguard WorkerC API wrapper library names:
72*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced_c_api.so.M.m.p` : shared library containing the C-API wrapper library. Dependent on `libcstraced.so.M`
73*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced_c_api.so.M`     : symbolic link name to library - major version only.
74*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced_c_api.so`       : symbolic link name to library - no version.
75*02ca8ccaSAndroid Build Coastguard Worker
76*02ca8ccaSAndroid Build Coastguard WorkerStatic versions of the libraries:
77*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced.a`        : static library containing the main C++ based decoder library.
78*02ca8ccaSAndroid Build Coastguard Worker- `libcstraced_c_api.a`  : static library containing the C-API wrapper library.
79*02ca8ccaSAndroid Build Coastguard Worker
80*02ca8ccaSAndroid Build Coastguard WorkerTest programs are delivered to the `./tests/bin/<tgt_dir>` directories.
81*02ca8ccaSAndroid Build Coastguard Worker
82*02ca8ccaSAndroid Build Coastguard WorkerThe test programs are built to used the .so versions of the libraries.
83*02ca8ccaSAndroid Build Coastguard Worker-  `trc_pkt_lister`         - dependent on `libcstraced.so`.
84*02ca8ccaSAndroid Build Coastguard Worker-  `simple_pkt_print_c_api` - dependent on `libcstraced_c_api.so` & hence `libcstraced.so`.
85*02ca8ccaSAndroid Build Coastguard Worker
86*02ca8ccaSAndroid Build Coastguard WorkerThe test program build for `trc_pkt_lister` also builds an auxiliary library used by this program for test purposes only.
87*02ca8ccaSAndroid Build Coastguard WorkerThis is the `libsnapshot_parser.a` library, delivered to the `./tests/lib/<tgt_dir>` directories.
88*02ca8ccaSAndroid Build Coastguard Worker
89*02ca8ccaSAndroid Build Coastguard Worker**Note on Linux Build Directory Names**
90*02ca8ccaSAndroid Build Coastguard Worker
91*02ca8ccaSAndroid Build Coastguard WorkerDue to tool limitations, the makefiles will not operate correctly if the path to the opencsd directories contains spaces.
92*02ca8ccaSAndroid Build Coastguard Worker
93*02ca8ccaSAndroid Build Coastguard Workere.g. checking out the project into a directory such as ` /home/name/my opencsd/` will result in build failures.
94*02ca8ccaSAndroid Build Coastguard Worker
95*02ca8ccaSAndroid Build Coastguard Worker__Installing on Linux__
96*02ca8ccaSAndroid Build Coastguard Worker
97*02ca8ccaSAndroid Build Coastguard WorkerThe libraries can be installed on linux using the `make install` command. This will usually require root privileges. Installation will be the version in the `./lib/<tgt_dir>` directory, according to options chosen.
98*02ca8ccaSAndroid Build Coastguard Worker
99*02ca8ccaSAndroid Build Coastguard Workere.g.  ` make -f makefile.dev DEBUG=1 install`
100*02ca8ccaSAndroid Build Coastguard Worker
101*02ca8ccaSAndroid Build Coastguard Workerwill install from `./lib/linux64/dbg`
102*02ca8ccaSAndroid Build Coastguard Worker
103*02ca8ccaSAndroid Build Coastguard WorkerThe libraries `libopencsd` and `libopencsd_c_api` are installed to `/usr/lib`.
104*02ca8ccaSAndroid Build Coastguard Worker
105*02ca8ccaSAndroid Build Coastguard WorkerSufficient header files to build using the C-API library will be installed to `/usr/include/opencsd`.
106*02ca8ccaSAndroid Build Coastguard Worker
107*02ca8ccaSAndroid Build Coastguard WorkerThe installation can be removed using `make clean_install`. No additional options are necessary.
108*02ca8ccaSAndroid Build Coastguard Worker
109*02ca8ccaSAndroid Build Coastguard Worker
110*02ca8ccaSAndroid Build Coastguard Worker### Windows (x86/x64)  ###
111*02ca8ccaSAndroid Build Coastguard Worker
112*02ca8ccaSAndroid Build Coastguard WorkerUse the `.\build\win\ref_trace_decode_lib\ref_trace_decode_lib.sln` file to load a solution
113*02ca8ccaSAndroid Build Coastguard Workerwhich contains all library and test build projects.
114*02ca8ccaSAndroid Build Coastguard Worker
115*02ca8ccaSAndroid Build Coastguard WorkerLibraries are delivered to the `./lib/win<bitsize>/<dbg\rel>` directories.
116*02ca8ccaSAndroid Build Coastguard Workere.g. `./lib/win64/rel` will contain the windows 64 bit release libraries.
117*02ca8ccaSAndroid Build Coastguard Worker
118*02ca8ccaSAndroid Build Coastguard WorkerThe solution contains four configurations:-
119*02ca8ccaSAndroid Build Coastguard Worker- *Debug* : builds debug versions of static C++ main library and C-API libraries, test programs linked to the static library.
120*02ca8ccaSAndroid Build Coastguard Worker- *Debug-dll* : builds debug versions of static main library and C-API DLL. C-API statically linked to the main library.
121*02ca8ccaSAndroid Build Coastguard WorkerC-API test built as `c_api_pkt_print_test_dll.exe` and linked against the DLL version of the C-API library.
122*02ca8ccaSAndroid Build Coastguard Worker- *Release* : builds release static library versions, test programs linked to static libraries.
123*02ca8ccaSAndroid Build Coastguard Worker- *Release-dll* : builds release C-API DLL, static main library.
124*02ca8ccaSAndroid Build Coastguard Worker
125*02ca8ccaSAndroid Build Coastguard Worker_Note_: Currently there is no Windows DLL version of the main C++ library. This may follow once
126*02ca8ccaSAndroid Build Coastguard Workerthe project is nearer completion with further decode protocols, and the classes requiring export are established..
127*02ca8ccaSAndroid Build Coastguard Worker
128*02ca8ccaSAndroid Build Coastguard WorkerLibraries built are:-
129*02ca8ccaSAndroid Build Coastguard Worker- `libopencsd.lib` : static main C++ decoder library.
130*02ca8ccaSAndroid Build Coastguard Worker- `libopencsd_c_api.lib` : C-API static library.
131*02ca8ccaSAndroid Build Coastguard Worker- `libopencsd_c_api.dll` : C-API DLL library. Statically linked against `libcstraced.lib` at .DLL build time. Built using the release-dll or debug-dll solution configurations.
132*02ca8ccaSAndroid Build Coastguard Worker
133*02ca8ccaSAndroid Build Coastguard Worker
134*02ca8ccaSAndroid Build Coastguard WorkerThere is also a project file to build an auxiliary library used `trc_pkt_lister` for test purposes only.
135*02ca8ccaSAndroid Build Coastguard WorkerThis is the `snapshot_parser_lib.lib` library, delivered to the `./tests/lib/win<bitsize>/<dgb\rel>` directories.
136*02ca8ccaSAndroid Build Coastguard Worker
137*02ca8ccaSAndroid Build Coastguard Worker
138*02ca8ccaSAndroid Build Coastguard Worker### Additional Build Options ###
139*02ca8ccaSAndroid Build Coastguard Worker
140*02ca8ccaSAndroid Build Coastguard Worker__Library Virtual Address Size__
141*02ca8ccaSAndroid Build Coastguard Worker
142*02ca8ccaSAndroid Build Coastguard WorkerThe ocsd_if_types.h file includes a #define that controls the size of the virtual addresses
143*02ca8ccaSAndroid Build Coastguard Workerused within the library. By default this is a 64 bit `uint64_t` value.
144*02ca8ccaSAndroid Build Coastguard Worker
145*02ca8ccaSAndroid Build Coastguard WorkerWhen building for ARM architectures that have only a 32 bit Virtual Address, and building on
146*02ca8ccaSAndroid Build Coastguard Worker32 bit ARM architectures it may be desirable to build a library that uses a v-addr size of
147*02ca8ccaSAndroid Build Coastguard Worker32 bits. Define `USE_32BIT_V_ADDR` to enable this option
148*02ca8ccaSAndroid Build Coastguard Worker
149*02ca8ccaSAndroid Build Coastguard Worker
150*02ca8ccaSAndroid Build Coastguard WorkerIncluding the Library in an Application
151*02ca8ccaSAndroid Build Coastguard Worker---------------------------------------
152*02ca8ccaSAndroid Build Coastguard Worker
153*02ca8ccaSAndroid Build Coastguard WorkerThe user source code includes a header according to the API to be used:-
154*02ca8ccaSAndroid Build Coastguard Worker
155*02ca8ccaSAndroid Build Coastguard Worker- Main C++ decoder library - include `opencsd.h`. Link to C++ library.
156*02ca8ccaSAndroid Build Coastguard Worker- C-API library - include `opencsd_c_api.h`. Link to C-API library.
157*02ca8ccaSAndroid Build Coastguard Worker
158*02ca8ccaSAndroid Build Coastguard Worker### Linux build ###
159*02ca8ccaSAndroid Build Coastguard Worker
160*02ca8ccaSAndroid Build Coastguard WorkerBy default linux builds will link against the .so versions of the library. Using the C-API library will also
161*02ca8ccaSAndroid Build Coastguard Workerintroduce a dependency on the main C++ decoder .so. Ensure that the library paths and link commands are part of the
162*02ca8ccaSAndroid Build Coastguard Workerapplication makefile.
163*02ca8ccaSAndroid Build Coastguard Worker
164*02ca8ccaSAndroid Build Coastguard WorkerTo use the static versions use appropriate linker options.
165*02ca8ccaSAndroid Build Coastguard Worker
166*02ca8ccaSAndroid Build Coastguard Worker### Windows build ###
167*02ca8ccaSAndroid Build Coastguard Worker
168*02ca8ccaSAndroid Build Coastguard WorkerTo link against the C-API DLL, include the .DLL name as a dependency in the application project options.
169*02ca8ccaSAndroid Build Coastguard Worker
170*02ca8ccaSAndroid Build Coastguard WorkerTo link against the C-API static library, include the library name in the dependency list, and define the macro
171*02ca8ccaSAndroid Build Coastguard Worker`OCSD_USE_STATIC_C_API` in the preprocessor definitions. This ensures that the correct static bindings are declared in
172*02ca8ccaSAndroid Build Coastguard Workerthe header file. Also link against the main C++ library.
173*02ca8ccaSAndroid Build Coastguard Worker
174*02ca8ccaSAndroid Build Coastguard WorkerTo link against the main C++ library include the library name in the dependency list.
175*02ca8ccaSAndroid Build Coastguard Worker
176*02ca8ccaSAndroid Build Coastguard Worker
177*02ca8ccaSAndroid Build Coastguard WorkerLibrary Performance Options
178*02ca8ccaSAndroid Build Coastguard Worker---------------------------
179*02ca8ccaSAndroid Build Coastguard Worker
180*02ca8ccaSAndroid Build Coastguard WorkerThe library caches parts of the memory images requested during the decode process, to improve performance by reducing the number of requests to the memory accessor (memacc) objects or callbacks.
181*02ca8ccaSAndroid Build Coastguard Worker
182*02ca8ccaSAndroid Build Coastguard WorkerThe default settings can be adjusted at runtime either by programmable API, or using environment variables.
183*02ca8ccaSAndroid Build Coastguard Worker
184*02ca8ccaSAndroid Build Coastguard WorkerCache parameters can be set in terms of page size and number of pages.
185*02ca8ccaSAndroid Build Coastguard WorkerCaching can also be disabled.
186*02ca8ccaSAndroid Build Coastguard Worker
187*02ca8ccaSAndroid Build Coastguard WorkerPage size can vary between 64 bytes and 16384 bytes.
188*02ca8ccaSAndroid Build Coastguard WorkerNumber of pages can vary between 4 and 256.
189*02ca8ccaSAndroid Build Coastguard Worker
190*02ca8ccaSAndroid Build Coastguard WorkerDefault values are set at 16 pages of 2048 bytes.
191*02ca8ccaSAndroid Build Coastguard Worker
192*02ca8ccaSAndroid Build Coastguard Worker### Environment variables to control caching ###
193*02ca8ccaSAndroid Build Coastguard Worker
194*02ca8ccaSAndroid Build Coastguard Worker- `OPENCSD_MEMACC_CACHE_PAGE_SIZE` : Page size in bytes.
195*02ca8ccaSAndroid Build Coastguard Worker- `OPENCSD_MEMACC_CACHE_PAGE_NUM`  : number of pages.
196*02ca8ccaSAndroid Build Coastguard Worker- `OPENCSD_MEMACC_CACHE_OFF`       : disable memacc caching.
197*02ca8ccaSAndroid Build Coastguard Worker
198*02ca8ccaSAndroid Build Coastguard Worker
199*02ca8ccaSAndroid Build Coastguard WorkerLibrary Debug Options
200*02ca8ccaSAndroid Build Coastguard Worker---------------------
201*02ca8ccaSAndroid Build Coastguard Worker
202*02ca8ccaSAndroid Build Coastguard Worker### ETMv4 / ETE instruction run limit ###
203*02ca8ccaSAndroid Build Coastguard Worker
204*02ca8ccaSAndroid Build Coastguard WorkerThe ETMv4 / ETE decoder has an optional run length limit for the amount of instructions in a range permitted before an error code will be returned.
205*02ca8ccaSAndroid Build Coastguard Worker
206*02ca8ccaSAndroid Build Coastguard WorkerThis option allows debug of potential runaway decode if incorrect memory image imformation is provided to the debuger.
207*02ca8ccaSAndroid Build Coastguard Worker
208*02ca8ccaSAndroid Build Coastguard WorkerOption controlled by environment variable `OPENCSD_INSTR_RANGE_LIMIT`. Set value to number of instructions as the limit.
209*02ca8ccaSAndroid Build Coastguard Worker
210*02ca8ccaSAndroid Build Coastguard Worker### AA64 Invalid opcode detection ###
211*02ca8ccaSAndroid Build Coastguard Worker
212*02ca8ccaSAndroid Build Coastguard WorkerThe instruction decode part of the library can be set to detect invalid aarch64 opcodes and throw an error.
213*02ca8ccaSAndroid Build Coastguard Worker
214*02ca8ccaSAndroid Build Coastguard WorkerIn the aarch64 opcodes define any opcode with the top 16 bits as 0x0000 as an invalid opcode range - which is the range detected by the library.
215*02ca8ccaSAndroid Build Coastguard WorkerAny other opcodes that are undefined or invalid that are not in this range will not be detected.
216*02ca8ccaSAndroid Build Coastguard Worker
217*02ca8ccaSAndroid Build Coastguard WorkerThis also allows the potential to detect runaway decode where incorrect memory information is supplied which contains data sections initilised with 0x00000000.
218*02ca8ccaSAndroid Build Coastguard Worker
219*02ca8ccaSAndroid Build Coastguard WorkerOption is controlled by environment variable `OPENCSD_ERR_ON_AA64_BAD_OPCODE`. If this is set then the invalid opcodes will be detected.
220*02ca8ccaSAndroid Build Coastguard Worker
221