1a85fe12eSEd Maste.\" Copyright (c) 2010-2011 Joseph Koshy.  All rights reserved.
2a85fe12eSEd Maste.\"
3a85fe12eSEd Maste.\" Redistribution and use in source and binary forms, with or without
4a85fe12eSEd Maste.\" modification, are permitted provided that the following conditions
5a85fe12eSEd Maste.\" are met:
6a85fe12eSEd Maste.\" 1. Redistributions of source code must retain the above copyright
7a85fe12eSEd Maste.\"    notice, this list of conditions and the following disclaimer.
8a85fe12eSEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright
9a85fe12eSEd Maste.\"    notice, this list of conditions and the following disclaimer in the
10a85fe12eSEd Maste.\"    documentation and/or other materials provided with the distribution.
11a85fe12eSEd Maste.\"
12a85fe12eSEd Maste.\" This software is provided by Joseph Koshy ``as is'' and
13a85fe12eSEd Maste.\" any express or implied warranties, including, but not limited to, the
14a85fe12eSEd Maste.\" implied warranties of merchantability and fitness for a particular purpose
15a85fe12eSEd Maste.\" are disclaimed.  in no event shall Joseph Koshy be liable
16a85fe12eSEd Maste.\" for any direct, indirect, incidental, special, exemplary, or consequential
17a85fe12eSEd Maste.\" damages (including, but not limited to, procurement of substitute goods
18a85fe12eSEd Maste.\" or services; loss of use, data, or profits; or business interruption)
19a85fe12eSEd Maste.\" however caused and on any theory of liability, whether in contract, strict
20a85fe12eSEd Maste.\" liability, or tort (including negligence or otherwise) arising in any way
21a85fe12eSEd Maste.\" out of the use of this software, even if advised of the possibility of
22a85fe12eSEd Maste.\" such damage.
23a85fe12eSEd Maste.\"
24d003e0d7SEd Maste.\" $Id: elftc_bfd_find_target.3 3752 2019-06-28 01:12:53Z emaste $
25a85fe12eSEd Maste.\"
2657d7e4ccSEd Maste.Dd February 12, 2020
27ae500c1fSEd Maste.Dt ELFTC_BFD_FIND_TARGET 3
28a85fe12eSEd Maste.Os
29a85fe12eSEd Maste.Sh NAME
30a85fe12eSEd Maste.Nm elftc_bfd_find_target ,
31a85fe12eSEd Maste.Nm elftc_bfd_target_byteorder ,
32a85fe12eSEd Maste.Nm elftc_bfd_target_class ,
33a85fe12eSEd Maste.Nm elftc_bfd_target_flavor ,
34a85fe12eSEd Maste.Nm elftc_bfd_target_machine
35a85fe12eSEd Maste.Nd binary object descriptor handling
36a85fe12eSEd Maste.Sh LIBRARY
37a85fe12eSEd Maste.Lb libelftc
38a85fe12eSEd Maste.Sh SYNOPSIS
39a85fe12eSEd Maste.In libelftc.h
40a85fe12eSEd Maste.Vt struct Elftc_Bfd_Target;
41a85fe12eSEd Maste.Ft "Elftc_Bfd_Target *"
42a85fe12eSEd Maste.Fn elftc_bfd_find_target "const char *target_name"
43a85fe12eSEd Maste.Ft "unsigned int"
44a85fe12eSEd Maste.Fn elftc_bfd_target_class "Elftc_Bfd_Target *target"
45a85fe12eSEd Maste.Ft "unsigned int"
46a85fe12eSEd Maste.Fn elftc_bfd_target_byteorder "Elftc_Bfd_Target *target"
47a85fe12eSEd Maste.Ft Elftc_Bfd_Target_Flavor
48a85fe12eSEd Maste.Fn elftc_bfd_target_flavor "Elftc_Bfd_Target *target"
49a85fe12eSEd Maste.Ft "unsigned int"
50a85fe12eSEd Maste.Fn elftc_bfd_target_machine "Elftc_Bfd_Target *target"
5157d7e4ccSEd Maste.Ft "unsigned int"
5257d7e4ccSEd Maste.Fn elftc_bfd_target_osabi "Elftc_Bfd_Target *target"
53a85fe12eSEd Maste.Sh DESCRIPTION
54a85fe12eSEd MasteFunction
55a85fe12eSEd Maste.Fn elftc_bfd_find_target
56a85fe12eSEd Mastelocates a binary object descriptor corresponding to the descriptor
57a85fe12eSEd Mastename in argument
58a85fe12eSEd Maste.Ar "target_name" .
59a85fe12eSEd MasteBinary object descriptors encapsulate properties of an object format
60a85fe12eSEd Mastesuch as its file representation, ELF class, and byte endianness.
61a85fe12eSEd Maste.Pp
62a85fe12eSEd MasteKnown descriptor names and their properties include:
63839529caSEd Maste.Bl -column -offset "XXXX" ".Li elf32-x86-64-freebsd" "Object format" "Byte Order" "Bit Width"
64839529caSEd Maste.It Em Name Ta Em "Object Format" Ta Em "Byte Order" Ta Em "Bit Width"
65a85fe12eSEd Maste.It Li binary Ta Binary Ta - Ta -
66839529caSEd Maste.It Li efi-app-ia32 Ta PE Ta LSB Ta 32
67839529caSEd Maste.It Li efi-app-x86_64 Ta PE Ta LSB Ta 64
68a85fe12eSEd Maste.It Li elf32-avr Ta ELF Ta LSB Ta 32
69a85fe12eSEd Maste.It Li elf32-big Ta ELF Ta MSB Ta 32
70a85fe12eSEd Maste.It Li elf32-bigarm Ta ELF Ta MSB Ta 32
71a85fe12eSEd Maste.It Li elf32-bigmips Ta ELF Ta MSB Ta 32
72a85fe12eSEd Maste.It Li elf32-i386 Ta ELF Ta LSB Ta 32
73a85fe12eSEd Maste.It Li elf32-i386-freebsd Ta ELF Ta LSB Ta 32
74a85fe12eSEd Maste.It Li elf32-ia64-big Ta ELF Ta MSB Ta 32
75a85fe12eSEd Maste.It Li elf32-little Ta ELF Ta LSB Ta 32
76a85fe12eSEd Maste.It Li elf32-littlearm Ta ELF Ta LSB Ta 32
77a85fe12eSEd Maste.It Li elf32-littlemips Ta ELF Ta LSB Ta 32
78a85fe12eSEd Maste.It Li elf32-powerpc Ta ELF Ta MSB Ta 32
79bee2765cSEd Maste.It Li elf32-powerpc-freebsd Ta ELF Ta MSB Ta 32
80a85fe12eSEd Maste.It Li elf32-powerpcle Ta ELF Ta LSB Ta 32
81e16ea340SMitchell Horne.It Li elf32-riscv Ta ELF Ta LSB Ta 32
82e16ea340SMitchell Horne.It Li elf64-riscv Ta ELF Ta LSB Ta 64
83e16ea340SMitchell Horne.It Li elf64-riscv-freebsd Ta ELF Ta LSB Ta 64
84a85fe12eSEd Maste.It Li elf32-sh Ta ELF Ta MSB Ta 32
85a85fe12eSEd Maste.It Li elf32-shl Ta ELF Ta LSB Ta 32
86a85fe12eSEd Maste.It Li elf32-sh-nbsd Ta ELF Ta MSB Ta 32
87a85fe12eSEd Maste.It Li elf32-shl-nbsd Ta ELF Ta LSB Ta 32
88a85fe12eSEd Maste.It Li elf32-shbig-linux Ta ELF Ta MSB Ta 32
89a85fe12eSEd Maste.It Li elf32-shl-linux Ta ELF Ta LSB Ta 32
90a85fe12eSEd Maste.It Li elf32-sparc Ta ELF Ta MSB Ta 32
91adb25d1eSEd Maste.It Li elf32-tradbigmips Ta ELF Ta MSB Ta 32
923ca2845dSEd Maste.It Li elf32-tradlittlemips Ta ELF Ta LSB Ta 32
93a85fe12eSEd Maste.It Li elf64-alpha Ta ELF Ta LSB Ta 64
94a85fe12eSEd Maste.It Li elf64-alpha-freebsd Ta ELF Ta LSB Ta 64
95a85fe12eSEd Maste.It Li elf64-big Ta ELF Ta MSB Ta 64
96a85fe12eSEd Maste.It Li elf64-bigmips Ta ELF Ta MSB Ta 64
97a85fe12eSEd Maste.It Li elf64-ia64-big Ta ELF Ta MSB Ta 64
98a85fe12eSEd Maste.It Li elf64-ia64-little Ta ELF Ta LSB Ta 64
99a85fe12eSEd Maste.It Li elf64-little Ta ELF Ta LSB Ta 64
100e85c2b0bSEd Maste.It Li elf64-littleaarch64 Ta ELF Ta LSB Ta 64
101a85fe12eSEd Maste.It Li elf64-littlemips Ta ELF Ta LSB Ta 64
102a85fe12eSEd Maste.It Li elf64-powerpc Ta ELF Ta MSB Ta 64
103bee2765cSEd Maste.It Li elf64-powerpc-freebsd Ta ELF Ta MSB Ta 64
104a85fe12eSEd Maste.It Li elf64-powerpcle Ta ELF Ta LSB Ta 64
105a85fe12eSEd Maste.It Li elf64-sh64 Ta ELF Ta MSB Ta 64
106a85fe12eSEd Maste.It Li elf64-sh64l Ta ELF Ta LSB Ta 64
107a85fe12eSEd Maste.It Li elf64-sh64-nbsd Ta ELF Ta MSB Ta 64
108a85fe12eSEd Maste.It Li elf64-sh64l-nbsd Ta ELF Ta LSB Ta 64
109a85fe12eSEd Maste.It Li elf64-sh64big-linux Ta ELF Ta MSB Ta 64
110a85fe12eSEd Maste.It Li elf64-sh64-linux Ta ELF Ta LSB Ta 64
111a85fe12eSEd Maste.It Li elf64-sparc Ta ELF Ta MSB Ta 64
112a85fe12eSEd Maste.It Li elf64-sparc-freebsd Ta ELF Ta MSB Ta 64
113adb25d1eSEd Maste.It Li elf64-tradbigmips Ta ELF Ta MSB Ta 64
1143ca2845dSEd Maste.It Li elf64-tradlittlemips Ta ELF Ta LSB Ta 64
115a85fe12eSEd Maste.It Li elf64-x86-64 Ta ELF Ta LSB Ta 64
116a85fe12eSEd Maste.It Li elf64-x86-64-freebsd Ta ELF Ta LSB Ta 64
117a85fe12eSEd Maste.It Li ihex Ta IHEX Ta - Ta -
118839529caSEd Maste.It Li pei-i386 Ta PE Ta LSB Ta 32
119839529caSEd Maste.It Li pei-x86-64 Ta PE Ta LSB Ta 64
120a85fe12eSEd Maste.It Li srec Ta SREC Ta - Ta -
121a85fe12eSEd Maste.It Li symbolsrec Ta SREC Ta - Ta -
122a85fe12eSEd Maste.El
123a85fe12eSEd Maste.Pp
124a85fe12eSEd MasteFunction
125a85fe12eSEd Maste.Fn elftc_bfd_target_byteorder
126a85fe12eSEd Mastereturns the ELF byte order associated with target descriptor
127a85fe12eSEd Maste.Ar target .
128a85fe12eSEd Maste.Pp
129a85fe12eSEd MasteFunction
130a85fe12eSEd Maste.Fn elftc_bfd_target_class
131a85fe12eSEd Mastereturns the ELF class associated with target descriptor
132a85fe12eSEd Maste.Ar target .
133a85fe12eSEd Maste.Pp
134a85fe12eSEd MasteFunction
135a85fe12eSEd Maste.Fn elftc_bfd_target_flavor
136a85fe12eSEd Mastereturns the object format associated with target descriptor
137a85fe12eSEd Maste.Ar target .
138a85fe12eSEd MasteThe known object formats are:
139a85fe12eSEd Maste.Bl -tag -offset "XXXX" -width ".Dv ETF_BINARY" -compact
140a85fe12eSEd Maste.It Dv ETF_ELF
141a85fe12eSEd MasteAn ELF object.
142a85fe12eSEd Maste.It Dv ETF_BINARY
143a85fe12eSEd MasteRaw binary.
144a85fe12eSEd Maste.It Dv ETF_IHEX
145a85fe12eSEd MasteAn object encoded in
146a85fe12eSEd Maste.Tn Intel
147a85fe12eSEd Mastehex format.
148a85fe12eSEd Maste.It Dv ETF_NONE
149a85fe12eSEd MasteAn unknown object format.
150a85fe12eSEd Maste.It Dv ETF_SREC
151a85fe12eSEd MasteAn object encoded as S-records.
152a85fe12eSEd Maste.El
153a85fe12eSEd Maste.Sh RETURN VALUES
154a85fe12eSEd MasteFunction
155a85fe12eSEd Maste.Fn elftc_bfd_find_target
156a85fe12eSEd Mastereturns a valid pointer to an opaque binary target descriptor if
157a85fe12eSEd Mastesuccessful, or NULL in case of an error.
158a85fe12eSEd Maste.Pp
159a85fe12eSEd MasteFunction
160a85fe12eSEd Maste.Fn elftc_bfd_target_byteorder
161a85fe12eSEd Mastereturns the ELF byte order associated with the target descriptor; one of
162a85fe12eSEd Maste.Dv ELFDATA2MSB
163a85fe12eSEd Masteor
164a85fe12eSEd Maste.Dv ELFDATA2LSB .
165a85fe12eSEd Maste.Pp
166a85fe12eSEd MasteFunction
167a85fe12eSEd Maste.Fn elftc_bfd_target_class
168a85fe12eSEd Mastereturns the ELF class associated with the target descriptor; one of
169a85fe12eSEd Maste.Dv ELFCLASS32
170a85fe12eSEd Masteor
171a85fe12eSEd Maste.Dv ELFCLASS64 .
172a85fe12eSEd Maste.Pp
173a85fe12eSEd MasteFunction
174a85fe12eSEd Maste.Fn elftc_bfd_target_machine
175a85fe12eSEd Mastereturns the ELF architecture associated with the target descriptor.
176a85fe12eSEd Maste.Pp
177a85fe12eSEd MasteFunction
178a85fe12eSEd Maste.Fn elftc_bfd_target_flavor
179a85fe12eSEd Mastereturns one of
180a85fe12eSEd Maste.Dv ETF_BINARY ,
181a85fe12eSEd Maste.Dv ETF_ELF ,
182a85fe12eSEd Maste.Dv ETF_IHEX
183a85fe12eSEd Masteor
184a85fe12eSEd Maste.Dv ETF_SREC
185a85fe12eSEd Masteif successful or
186a85fe12eSEd Maste.Dv ETF_NONE
187a85fe12eSEd Mastein case of error.
188a85fe12eSEd Maste.Sh EXAMPLES
189a85fe12eSEd MasteTo return descriptor information associated with target name
190a85fe12eSEd Maste.Dq elf64-big
191a85fe12eSEd Masteuse:
192a85fe12eSEd Maste.Bd -literal -offset indent
193a85fe12eSEd Mastestruct Elftc_Bfd_Target *t;
194a85fe12eSEd Maste
195a85fe12eSEd Masteif ((t = elftc_bfd_find_target("elf64-big")) == NULL)
196a85fe12eSEd Maste	errx(EXIT_FAILURE, "Cannot find target descriptor");
197a85fe12eSEd Maste
198a85fe12eSEd Masteprintf("Class: %s\\n", elftc_bfd_target_class(t) == ELFCLASS32 ?
199a85fe12eSEd Maste    "ELFCLASS32" : "ELFCLASS64");
200a85fe12eSEd Masteprintf("Byteorder: %s\\n",
201a85fe12eSEd Maste    elftc_bfd_target_byteorder(t) == ELFDATA2LSB ? "LSB" : "MSB");
202a85fe12eSEd Masteprintf("Flavor: %d\\n", elftc_bfd_target_flavor(t));
203a85fe12eSEd Maste.Ed
204a85fe12eSEd Maste.Sh SEE ALSO
205a85fe12eSEd Maste.Xr elf 3
206