[07/16] doc: Add elf_getshdrstrndx.3 and elf_getshstrndx.3

Message ID 20250701031248.1106390-7-amerey@redhat.com
State Superseded
Delegated to: Mark Wielaard
Headers
Series [01/16] doc: Add elf_memory.3 |

Commit Message

Aaron Merey July 1, 2025, 3:12 a.m. UTC
  Signed-off-by: Aaron Merey <amerey@redhat.com>
---
 doc/Makefile.am         |  2 ++
 doc/elf_getshdrstrndx.3 | 80 +++++++++++++++++++++++++++++++++++++++++
 doc/elf_getshstrndx.3   |  1 +
 3 files changed, 83 insertions(+)
 create mode 100644 doc/elf_getshdrstrndx.3
 create mode 100644 doc/elf_getshstrndx.3
  

Comments

Mark Wielaard July 8, 2025, 4:53 p.m. UTC | #1
Hi Aaron,

On Mon, 2025-06-30 at 23:12 -0400, Aaron Merey wrote:
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index cf60a271..129c612d 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -71,7 +71,9 @@ notrans_dist_man3_MANS= elf32_checksum.3 \
>  			elf_getphdrnum.3 \
>  			elf_getscn.3 \
>  			elf_getshdrnum.3 \
> +			elf_getshdrstrndx.3 \
>  			elf_getshnum.3 \
> +			elf_getshstrndx.3 \
>  			elf_hash.3 \
>  			elf_kind.3 \
>  			elf_memory.3 \

OK.

> diff --git a/doc/elf_getshdrstrndx.3 b/doc/elf_getshdrstrndx.3
> new file mode 100644
> index 00000000..b3bdca0f
> --- /dev/null
> +++ b/doc/elf_getshdrstrndx.3
> @@ -0,0 +1,80 @@
> +.TH ELF_GETSHDRSTRNDX 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf_getshdrstrndx, elf_getshstrndx \- retrieve the section header string table index
> +.SH SYNOPSIS
> +.nf
> +#include <libelf.h>
> +
> +.B int elf_getshdrstrndx("Elf *elf", "size_t *dst");
> +.B int elf_getshstrndx("Elf *elf", "size_t *dst");
> +.fi

OK, but maybe mark elf_getshstrndx deprecated/obsolete?

> +.SH DESCRIPTION
> +The
> +.BR elf_getshdrstrndx ()
> +function retrieves the section header string table index from the ELF descriptor
> +.IR elf ,
> +and stores it in the location pointed to by
> +.IR dst .
> +
> +This function handles both standard ELF values and extended section indexing.
> +In the latter case, if the section header string table index field of the ELF
> +header contains
> +.B SHN_XINDEX,
> +then the true index is stored in the
> +.B sh_link
> +field of section 0, which this function reads either from memory or directly
> +from the file.

OK, but the last subsentence (from memory or file) seems an
implementation detail.

Maybe add a bit more explanation about how/when to use this (SEE ALSO)?

> +
> +The function
> +.BR elf_getshstrndx ()
> +is a deprecated alias for
> +.BR elf_getshdrstrndx ()
> +and should not be used in new code.

OK. Maybe add see history, below?

> +.SH PARAMETERS
> +.TP
> +.I elf
> +A pointer to an
> +.B Elf
> +descriptor opened with
> +.BR elf_begin (3).
> +The descriptor must be of kind
> +.B ELF_K_ELF .

Can also be created with elf_memory.
Elf may be NULL, but then an error is returned.

> +.TP
> +.I dst
> +A pointer to a
> +.B size_t
> +location where the index of the section header string table will be stored.
> +Must not be NULL.

OK.

> +
> +.SH RETURN VALUE
> +Returns 0 on success and stores the section header string table index in
> +.IR dst .
> +Returns \-1 on failure.

And sets elf_errno, except when elf is NULL.

> +
> +.SH SEE ALSO
> +.BR libelf (3),
> +.BR elf (5)

Maybe add elf32_getshdr/elf64_getshdr and/or elf_strptr since you get
section names using elf_strptr (elf, shdrstrndx, sh_name)
But maybe that should be in the description?

> +
> +.SH ATTRIBUTES
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +Interface	Attribute	Value
> +T{
> +.na
> +.nh
> +.BR elf_getshdrstrndx (),\~elf_getshstrndx ()
> +T}	Thread safety	MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.

OK.

> +.SH HISTORY
> +.B elf_getshdrstrndx
> +first appeared in elfutils 0.142.  This function is a elfutils libelf extension and
> +may not be available in other libelf implementations.

Same story as for elf_getshnum/elf_getshdrnum. Some other libelf
implementations got the return value of elf_getshstrndx wrong. So to
get things consistent elf_getshdrstrndx was introduced.

[There also was a get_elfphnum function with the same issue, but
elfutils libelf never had an implementation of that.]

> diff --git a/doc/elf_getshstrndx.3 b/doc/elf_getshstrndx.3
> new file mode 100644
> index 00000000..22a2251f
> --- /dev/null
> +++ b/doc/elf_getshstrndx.3
> @@ -0,0 +1 @@
> +.so man3/elf_getshdrstrndx.3

OK.

Thanks,

Mark
  

Patch

diff --git a/doc/Makefile.am b/doc/Makefile.am
index cf60a271..129c612d 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -71,7 +71,9 @@  notrans_dist_man3_MANS= elf32_checksum.3 \
 			elf_getphdrnum.3 \
 			elf_getscn.3 \
 			elf_getshdrnum.3 \
+			elf_getshdrstrndx.3 \
 			elf_getshnum.3 \
+			elf_getshstrndx.3 \
 			elf_hash.3 \
 			elf_kind.3 \
 			elf_memory.3 \
diff --git a/doc/elf_getshdrstrndx.3 b/doc/elf_getshdrstrndx.3
new file mode 100644
index 00000000..b3bdca0f
--- /dev/null
+++ b/doc/elf_getshdrstrndx.3
@@ -0,0 +1,80 @@ 
+.TH ELF_GETSHDRSTRNDX 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
+
+.SH NAME
+elf_getshdrstrndx, elf_getshstrndx \- retrieve the section header string table index
+.SH SYNOPSIS
+.nf
+#include <libelf.h>
+
+.B int elf_getshdrstrndx("Elf *elf", "size_t *dst");
+.B int elf_getshstrndx("Elf *elf", "size_t *dst");
+.fi
+.SH DESCRIPTION
+The
+.BR elf_getshdrstrndx ()
+function retrieves the section header string table index from the ELF descriptor
+.IR elf ,
+and stores it in the location pointed to by
+.IR dst .
+
+This function handles both standard ELF values and extended section indexing.
+In the latter case, if the section header string table index field of the ELF
+header contains
+.B SHN_XINDEX,
+then the true index is stored in the
+.B sh_link
+field of section 0, which this function reads either from memory or directly
+from the file.
+
+The function
+.BR elf_getshstrndx ()
+is a deprecated alias for
+.BR elf_getshdrstrndx ()
+and should not be used in new code.
+
+.SH PARAMETERS
+.TP
+.I elf
+A pointer to an
+.B Elf
+descriptor opened with
+.BR elf_begin (3).
+The descriptor must be of kind
+.B ELF_K_ELF .
+
+.TP
+.I dst
+A pointer to a
+.B size_t
+location where the index of the section header string table will be stored.
+Must not be NULL.
+
+.SH RETURN VALUE
+Returns 0 on success and stores the section header string table index in
+.IR dst .
+Returns \-1 on failure.
+
+.SH SEE ALSO
+.BR libelf (3),
+.BR elf (5)
+
+.SH ATTRIBUTES
+.TS
+allbox;
+lbx lb lb
+l l l.
+Interface	Attribute	Value
+T{
+.na
+.nh
+.BR elf_getshdrstrndx (),\~elf_getshstrndx ()
+T}	Thread safety	MT-Safe
+.TE
+
+.SH REPORTING BUGS
+Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.
+
+.SH HISTORY
+.B elf_getshdrstrndx
+first appeared in elfutils 0.142.  This function is a elfutils libelf extension and
+may not be available in other libelf implementations.
diff --git a/doc/elf_getshstrndx.3 b/doc/elf_getshstrndx.3
new file mode 100644
index 00000000..22a2251f
--- /dev/null
+++ b/doc/elf_getshstrndx.3
@@ -0,0 +1 @@ 
+.so man3/elf_getshdrstrndx.3