1.\" SPDX-License-Identifier: BSD-2-Clause
2.\"
3.\" Copyright (c) 2020 The FreeBSD Foundation
4.\"
5.\" This document was written by Tiger Gao under sponsorship from
6.\" the FreeBSD Foundation.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions are
10.\" met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in
15.\"    the documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\" $Id: gelf_getchdr.3 3639 2020-10-20 16:07:02Z tig $
30.\"
31.Dd October 23, 2020
32.Dt GELF_GETCHDR 3
33.Os
34.Sh NAME
35.Nm elf32_getchdr ,
36.Nm elf64_getchdr ,
37.Nm gelf_getchdr
38.Nd retrieve the compression header of a section
39.Sh LIBRARY
40.Lb libelf
41.Sh SYNOPSIS
42.In libelf.h
43.Ft "Elf32_Chdr *"
44.Fn elf32_getchdr "Elf_Scn *s"
45.Ft "Elf64_Chdr *"
46.Fn elf64_getchdr "Elf_Scn *s"
47.In gelf.h
48.Ft "GElf_Chdr *"
49.Fn gelf_getchdr "Elf_Scn *scn" "GElf_Chdr *chdr"
50.Sh DESCRIPTION
51These functions return a pointer to the ELF Compression Header data
52structure associated with section descriptor
53.Ar scn .
54.Pp
55Function
56.Fn elf32_getchdr
57retrieves a pointer to an
58.Vt Elf32_Chdr
59structure.
60Section descriptor
61.Ar scn
62must be associated with an ELF descriptor of class
63.Dv ELFCLASS32 .
64.Pp
65Function
66.Fn elf64_getchdr
67retrieves a pointer to an
68.Vt Elf64_Chdr
69structure.
70Section descriptor
71.Ar scn
72must be associated with an ELF descriptor of class
73.Dv ELFCLASS64 .
74.Pp
75Function
76.Fn gelf_getchdr
77copies the values in the compression header associated with argument
78.Ar scn
79to the structure pointed to be argument
80.Ar dst .
81The
82.Vt GElf_Chdr
83data structure is described in
84.Xr gelf 3 .
85.Sh RETURN VALUES
86Functions
87.Fn elf32_getchdr
88and
89.Fn elf64_getchdr
90return a valid pointer to the appropriate compression header on success
91or NULL if an error was encountered.
92.Pp
93Function
94.Fn gelf_getchdr
95returns argument
96.Ar dst
97if successful, or NULL if an error was encountered.
98.Sh ERRORS
99These functions may fail with the following errors:
100.Bl -tag -width "[ELF_E_RESOURCE]"
101.It Bq Er ELF_E_INVALID_SECTION_FLAGS
102Arguments
103.Ar scn
104has invalid flags.
105.It Bq Er ELF_E_INVALID_SECTION_TYPE
106Argument
107.Ar scn
108has invalid type.
109.It Bq Er ELF_E_NOT_COMPRESSED
110Argument
111.Ar scn
112is not compressed.
113.El
114.Sh SEE ALSO
115.Xr elf 3 ,
116.Xr elf_getscn 3 ,
117.Xr gelf 3 ,
118