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