xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_producer_init.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: dwarf_producer_init.3,v 1.6 2024/03/03 17:37:32 christos Exp $
2e81373b4Schristos.\"
39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang
49dd9d0cfSchristos.\" All rights reserved.
59dd9d0cfSchristos.\"
69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without
79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions
89dd9d0cfSchristos.\" are met:
99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright
109dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer.
119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
129dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer in the
139dd9d0cfSchristos.\"    documentation and/or other materials provided with the distribution.
149dd9d0cfSchristos.\"
159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189dd9d0cfSchristos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259dd9d0cfSchristos.\" SUCH DAMAGE.
269dd9d0cfSchristos.\"
27cdbf1fe1Sjkoshy.\" Id: dwarf_producer_init.3 3963 2022-03-12 16:07:32Z jkoshy
289dd9d0cfSchristos.\"
299dd9d0cfSchristos.Dd August 20, 2011
309dd9d0cfSchristos.Dt DWARF_PRODUCER_INIT 3
31604b0842Sjkoshy.Os
329dd9d0cfSchristos.Sh NAME
33604b0842Sjkoshy.Nm dwarf_producer_init ,
349dd9d0cfSchristos.Nm dwarf_producer_init_b
359dd9d0cfSchristos.Nd allocate a DWARF producer descriptor
369dd9d0cfSchristos.Sh LIBRARY
379dd9d0cfSchristos.Lb libdwarf
389dd9d0cfSchristos.Sh SYNOPSIS
399dd9d0cfSchristos.In libdwarf.h
409dd9d0cfSchristos.Ft Dwarf_P_Debug
419dd9d0cfSchristos.Fo dwarf_producer_init
429dd9d0cfSchristos.Fa "Dwarf_Unsigned flags"
439dd9d0cfSchristos.Fa "Dwarf_Callback_Func func"
449dd9d0cfSchristos.Fa "Dwarf_Handler errhand"
459dd9d0cfSchristos.Fa "Dwarf_Ptr errarg"
469dd9d0cfSchristos.Fa "Dwarf_Error *err"
479dd9d0cfSchristos.Fc
489dd9d0cfSchristos.Ft Dwarf_P_Debug
499dd9d0cfSchristos.Fo dwarf_producer_init_b
509dd9d0cfSchristos.Fa "Dwarf_Unsigned flags"
519dd9d0cfSchristos.Fa "Dwarf_Callback_Func_b func"
529dd9d0cfSchristos.Fa "Dwarf_Handler errhand"
539dd9d0cfSchristos.Fa "Dwarf_Ptr errarg"
549dd9d0cfSchristos.Fa "Dwarf_Error *error"
559dd9d0cfSchristos.Fc
569dd9d0cfSchristos.Sh DESCRIPTION
579dd9d0cfSchristosThese functions allocate and return a
589dd9d0cfSchristos.Vt Dwarf_P_Debug
599dd9d0cfSchristosdescriptor representing a DWARF producer instance.
609dd9d0cfSchristos.Pp
619dd9d0cfSchristosThe argument
62cdbf1fe1Sjkoshy.Fa errhand
6342bd3019Schristosshould contain the address of a function to be called in case of an
649dd9d0cfSchristoserror.
659dd9d0cfSchristosIf this argument is
669dd9d0cfSchristos.Dv NULL ,
679dd9d0cfSchristosthe default error handling scheme is used, see
689dd9d0cfSchristos.Xr dwarf 3 .
699dd9d0cfSchristos.Pp
709dd9d0cfSchristosThe argument
71cdbf1fe1Sjkoshy.Fa errarg
729dd9d0cfSchristoswill be passed to the error handler function when it is invoked.
739dd9d0cfSchristos.Pp
749dd9d0cfSchristosThe argument
75cdbf1fe1Sjkoshy.Fa err
769dd9d0cfSchristosreferences a memory location that would hold a
779dd9d0cfSchristos.Vt Dwarf_Error
789dd9d0cfSchristosdescriptor in case of an error.
799dd9d0cfSchristos.Pp
809dd9d0cfSchristosThe argument
81cdbf1fe1Sjkoshy.Fa flags
829dd9d0cfSchristosspecifies additional characteristics of the DWARF producer instance.
839dd9d0cfSchristosThe following flags are recognized:
849dd9d0cfSchristos.Bl -tag -width "Dv DW_DLC_ISA_MIPS"
859dd9d0cfSchristos.It Dv DW_DLC_ISA_IA64
869dd9d0cfSchristos.Pq Deprecated
879dd9d0cfSchristosThe target instruction set architecture is IA64.
889dd9d0cfSchristosThis flag is deprecated.
899dd9d0cfSchristosApplication code should use the
909dd9d0cfSchristos.Xr dwarf_producer_set_isa 3
919dd9d0cfSchristosfunction to specify target instruction set architecture.
929dd9d0cfSchristos.It Dv DW_DLC_ISA_MIPS
939dd9d0cfSchristos.Pq Deprecated
949dd9d0cfSchristosThe target instruction set architecture is MIPS.
959dd9d0cfSchristosThis flag is deprecated.
969dd9d0cfSchristosApplication code should use the
979dd9d0cfSchristos.Xr dwarf_producer_set_isa 3
989dd9d0cfSchristosfunction to specify target instruction set architecture.
999dd9d0cfSchristos.It Dv DW_DLC_SIZE_32
1009dd9d0cfSchristos.Pq Default
1019dd9d0cfSchristosThe target address size is 32-bit.
1029dd9d0cfSchristos.It Dv DW_DLC_SIZE_64
1039dd9d0cfSchristosThe target address size is 64-bit.
1049dd9d0cfSchristos.It Dv DW_DLC_STREAM_RELOCATIONS
1059dd9d0cfSchristos.Pq Default
1069dd9d0cfSchristosGenerate stream relocations.
1079dd9d0cfSchristos.It Dv DW_DLC_SYMBOLIC_RELOCATIONS
1089dd9d0cfSchristosGenerate symbolic relocations.
1099dd9d0cfSchristos.It Dv DW_DLC_TARGET_BIGENDIAN
1109dd9d0cfSchristosThe target is big endian.
1119dd9d0cfSchristos.It Dv DW_DLC_TARGET_LITTLEENDIAN
1129dd9d0cfSchristosThe target is little endian.
1139dd9d0cfSchristos.It Dv DW_DLC_WRITE
1149dd9d0cfSchristos.Pq Required
1159dd9d0cfSchristosPermit writing of DWARF information.
1169dd9d0cfSchristos.El
1179dd9d0cfSchristos.Pp
1189dd9d0cfSchristosThe following flags are mutually exclusive.
1199dd9d0cfSchristos.Bl -bullet -compact
1209dd9d0cfSchristos.It
1219dd9d0cfSchristosFlags
1229dd9d0cfSchristos.Dv DW_DLC_ISA_IA64
1239dd9d0cfSchristosand
1249dd9d0cfSchristos.Dv DW_DLC_ISA_MIPS .
1259dd9d0cfSchristos.It
1269dd9d0cfSchristosFlags
1279dd9d0cfSchristos.Dv DW_DLC_SIZE_32
1289dd9d0cfSchristosand
1299dd9d0cfSchristos.Dv DW_DLC_SIZE_64 .
1309dd9d0cfSchristos.It
1319dd9d0cfSchristosFlags
1329dd9d0cfSchristos.Dv DW_DLC_STREAM_RELOCATIONS
1339dd9d0cfSchristosand
1349dd9d0cfSchristos.Dv DW_DLC_SYMBOLIC_RELOCATIONS .
1359dd9d0cfSchristos.It
1369dd9d0cfSchristosFlags
1379dd9d0cfSchristos.Dv DW_DLC_TARGET_BIGENDIAN
1389dd9d0cfSchristosand
1399dd9d0cfSchristos.Dv DW_DLC_TARGET_LITTLEENDIAN .
1409dd9d0cfSchristos.El
1419dd9d0cfSchristosIf neither of the flags
1429dd9d0cfSchristos.Dv DW_DLC_TARGET_BIGENDIAN
1439dd9d0cfSchristosand
1449dd9d0cfSchristos.Dv DW_DLC_TARGET_LITTLEENDIAN
1459dd9d0cfSchristosis set, the target's endianness is assumed to be the same as the host's
1469dd9d0cfSchristosendianness.
1479dd9d0cfSchristos.Pp
1489dd9d0cfSchristosArgument
149cdbf1fe1Sjkoshy.Fa func
1509dd9d0cfSchristosshould point to an application-provided callback function of type
1519dd9d0cfSchristos.Vt Dwarf_Callback_Func_b .
1529dd9d0cfSchristosThe type
1539dd9d0cfSchristos.Vt Dwarf_Callback_Func_b
1549dd9d0cfSchristosis defined in the header file
1559dd9d0cfSchristos.In libdwarf.h
1569dd9d0cfSchristosas:
1579dd9d0cfSchristos.Bd -literal -offset indent
1589dd9d0cfSchristostypedef int (*Dwarf_Callback_Func_b)(char *name, int size,
1599dd9d0cfSchristos    Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link,
1609dd9d0cfSchristos    Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error);
1619dd9d0cfSchristos.Ed
1629dd9d0cfSchristos.Pp
1639dd9d0cfSchristosThis function is called by the
1649dd9d0cfSchristos.Lb libdwarf
1659dd9d0cfSchristosonce for each section in the object file that the library needs to
1669dd9d0cfSchristoscreate.
1679dd9d0cfSchristosThe arguments to this callback function specify the values in the ELF
1689dd9d0cfSchristossection header for the section being created:
1699dd9d0cfSchristos.Pp
1709dd9d0cfSchristos.Bl -tag -width indent -compact -offset indent
1719dd9d0cfSchristos.It Ar name
1729dd9d0cfSchristosThe name of the section being created.
1739dd9d0cfSchristos.It Ar size
1749dd9d0cfSchristosThe
1759dd9d0cfSchristos.Va sh_size
1769dd9d0cfSchristosvalue in the section header.
1779dd9d0cfSchristos.It Ar type
1789dd9d0cfSchristosThe
1799dd9d0cfSchristos.Va sh_type
1809dd9d0cfSchristosvalue in the section header.
1819dd9d0cfSchristos.It Ar flags
1829dd9d0cfSchristosThe
1839dd9d0cfSchristos.Va sh_flags
1849dd9d0cfSchristosvalue in the section header.
1859dd9d0cfSchristos.It Ar link
1869dd9d0cfSchristosThe
1879dd9d0cfSchristos.Va sh_link
1889dd9d0cfSchristosvalue in the section header.
1899dd9d0cfSchristos.It Ar info
1909dd9d0cfSchristosThe
1919dd9d0cfSchristos.Va sh_info
1929dd9d0cfSchristosvalue in the section header.
1939dd9d0cfSchristos.El
1949dd9d0cfSchristos.Pp
1959dd9d0cfSchristosOn success, the callback function should return the section index
1969dd9d0cfSchristosvalue of the created section, and set the location pointed to by
1979dd9d0cfSchristosargument
198cdbf1fe1Sjkoshy.Fa index
1999dd9d0cfSchristosto the symbol table index of the symbol that associated with the newly
2009dd9d0cfSchristoscreated section.
2019dd9d0cfSchristosThis symbol table index will be used in relocation entries
2029dd9d0cfSchristosreferring to the created section.
2039dd9d0cfSchristos.Pp
2049dd9d0cfSchristosIn case of failure, the callback function should return -1 and set the
2059dd9d0cfSchristoslocation pointed to by argument
206cdbf1fe1Sjkoshy.Fa error
2079dd9d0cfSchristosto an application-defined error code.
2089dd9d0cfSchristosThis application returned error code is currently ignored by the
2099dd9d0cfSchristoslibrary.
2109dd9d0cfSchristos.Pp
2119dd9d0cfSchristosFunction
2129dd9d0cfSchristos.Fn dwarf_producer_init
2139dd9d0cfSchristosis deprecated.
2149dd9d0cfSchristosFunction
2159dd9d0cfSchristos.Fn dwarf_producer_init
2169dd9d0cfSchristosis identical to function
2179dd9d0cfSchristos.Fn dwarf_producer_init_b
2189dd9d0cfSchristosexcept that the callback function it expects can not properly handle
2199dd9d0cfSchristosarbitrary section symbol index values.
2209dd9d0cfSchristos.Ss Memory Management
2219dd9d0cfSchristosThe
2229dd9d0cfSchristos.Vt Dwarf_P_Debug
2239dd9d0cfSchristosinstance returned by these functions should be freed using the
2249dd9d0cfSchristosfunction
2259dd9d0cfSchristos.Fn dwarf_producer_finish .
2269dd9d0cfSchristos.Sh RETURN VALUES
2279dd9d0cfSchristosOn success, these functions return the created DWARF producer
2289dd9d0cfSchristosdescriptor.
2299dd9d0cfSchristosIn case of an error, they return
2309dd9d0cfSchristos.Dv DW_DLV_BADADDR
2319dd9d0cfSchristosand set the argument
232cdbf1fe1Sjkoshy.Fa err .
233604b0842Sjkoshy.Sh EXAMPLES
234604b0842SjkoshyTo initialize a
235604b0842Sjkoshy.Vt Dwarf_P_Debug
236604b0842Sjkoshyinstance for a MIPS32 big endian object, use:
237604b0842Sjkoshy.Bd -literal -offset indent
238604b0842SjkoshyDwarf_P_Debug dbg;
239604b0842SjkoshyDwarf_Unsigned flags;
240604b0842SjkoshyDwarf_Error de;
241604b0842Sjkoshy
242604b0842Sjkoshy/* ... assume cb_func points to the callback function ... */
243604b0842Sjkoshy
244604b0842Sjkoshyflags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS |
245604b0842Sjkoshy    DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN;
246604b0842Sjkoshyif ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) ==
247604b0842Sjkoshy    DW_DLV_BADADDR)
248604b0842Sjkoshy	warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1));
249604b0842Sjkoshy.Ed
2509dd9d0cfSchristos.Sh ERRORS
2519dd9d0cfSchristosThese functions can fail with:
2529dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
2539dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2549dd9d0cfSchristosArgument
255cdbf1fe1Sjkoshy.Fa func
256cdbf1fe1Sjkoshywas
257cdbf1fe1Sjkoshy.Dv NULL .
2589dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2599dd9d0cfSchristosThe flag
2609dd9d0cfSchristos.Dv DW_DLC_WRITE
2619dd9d0cfSchristoswas not set in argument
262cdbf1fe1Sjkoshy.Fa flags .
2639dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2649dd9d0cfSchristosThe flags
2659dd9d0cfSchristos.Dv DW_DLC_SIZE_32
2669dd9d0cfSchristosand
2679dd9d0cfSchristos.Dv DW_DLC_SIZE_64
2689dd9d0cfSchristoswere both set in argument
269cdbf1fe1Sjkoshy.Fa flags .
2709dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2719dd9d0cfSchristosThe flags
2729dd9d0cfSchristos.Dv DW_DLC_ISA_IA64
2739dd9d0cfSchristosand
2749dd9d0cfSchristos.Dv DW_DLC_ISA_MIPS
2759dd9d0cfSchristoswere both set in argument
276cdbf1fe1Sjkoshy.Fa flags .
2779dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2789dd9d0cfSchristosThe flags
2799dd9d0cfSchristos.Dv DW_DLC_TARGET_BIGENDIAN
2809dd9d0cfSchristosand
2819dd9d0cfSchristos.Dv DW_DLC_TARGET_LITTLEENDIAN
2829dd9d0cfSchristoswere both set in argument
283cdbf1fe1Sjkoshy.Fa flags .
2849dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
2859dd9d0cfSchristosThe flags
2869dd9d0cfSchristos.Dv DW_DLC_STREAM_RELOCATIONS
2879dd9d0cfSchristosand
2889dd9d0cfSchristos.Dv DW_DLC_SYMBOLIC_RELOCATIONS
2899dd9d0cfSchristoswere both set in argument
290cdbf1fe1Sjkoshy.Fa flags .
2919dd9d0cfSchristos.It Bq Er DW_DLE_MEMORY
2929dd9d0cfSchristosAn out of memory condition was encountered.
2939dd9d0cfSchristos.El
2949dd9d0cfSchristos.Sh SEE ALSO
2959dd9d0cfSchristos.Xr dwarf 3 ,
2969dd9d0cfSchristos.Xr dwarf_errmsg 3 ,
2979dd9d0cfSchristos.Xr dwarf_producer_finish 3 ,
2989dd9d0cfSchristos.Xr dwarf_producer_set_isa 3 ,
2999dd9d0cfSchristos.Xr dwarf_transform_to_disk_form 3
300