Re: [PATCH 15/16] doc: Add elf_scnshndx.3

2025-07-10 Thread Mark Wielaard
Hi Aaron,

On Mon, 2025-06-30 at 23:12 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey 
> ---
>  doc/Makefile.am|  1 +
>  doc/elf_scnshndx.3 | 68 ++
>  2 files changed, 69 insertions(+)
>  create mode 100644 doc/elf_scnshndx.3
> 
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index 50ab63ec..dc4a8b18 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -85,6 +85,7 @@ notrans_dist_man3_MANS= elf32_checksum.3 \
>   elf_rand.3 \
>   elf_rawdata.3 \
>   elf_rawfile.3 \
> + elf_scnshndx.3 \
>   elf_update.3 \
>   elf_version.3 \
>   libelf.3
> diff --git a/doc/elf_scnshndx.3 b/doc/elf_scnshndx.3
> new file mode 100644
> index ..8344df89
> --- /dev/null
> +++ b/doc/elf_scnshndx.3
> @@ -0,0 +1,68 @@
> +.TH ELF_SCNSHNDX 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf_scnshndx \- Find the index of the SHT_SYMTAB_SHNDX section associated 
> with a symbol table

Maybe say extended symbol table, or use associated with a SHT_SYMTAB
section?

> +.SH SYNOPSIS
> +.nf
> +#include 
> +
> +.BI "int elf_scnshndx(Elf_Scn *" scn ");"
> +.fi

OK.

> +.SH DESCRIPTION
> +The
> +.BR elf_scnshndx ()
> +function searches for the
> +.BR SHT_SYMTAB_SHNDX
> +section associated with a given symbol table section. It returns the section
> +index of the corresponding
> +.BR SHT_SYMTAB_SHNDX
> +section, or zero if none is found.

OK.

> +
> +This function is used for retrieving extended section indices in ELF files
> +with many sections, where standard symbol table entries cannot store all
> +possible section references directly.

OK.

> +The function only returns a valid result if
> +.IR scn
> +refers to a section of type
> +.BR SHT_SYMTAB .
> +Otherwise, the function returns 0.

Returns -1 on error?

> +.SH PARAMETERS
> +.TP
> +.I scn
> +An
> +.B Elf_Scn
> +pointer referencing a symbol table section.

OK.

> +.SH RETURN VALUE
> +Returns the section index of the
> +.BR SHT_SYMTAB_SHNDX
> +section if found. If no such section is found, returns 0. On error, returns 
> \-1.

OK.

> +.SH SEE ALSO
> +.BR libelf (3),
> +.BR elf (5)
> +
> +.SH ATTRIBUTES
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +InterfaceAttribute   Value
> +T{
> +.na
> +.nh
> +.BR elf_scnshndx ()
> +T}   Thread safety   MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to  or 
> https://sourceware.org/bugzilla/.
> +
> +.SH HISTORY
> +.B elf_scnshndx
> +first appeared in elfutils 0.132.  This function is a elfutils libelf 
> extension and
> +may not be available in other libelf implementations.

OK.

Thanks,

Mark


Re: [PATCH 14/16] doc: Add elf_rawfile.3

2025-07-10 Thread Mark Wielaard
Hi Aaron,

Funny, I had no idea this existed. But it is actually used by readelf
(for showing the program interpreter) and there is one test case (that
does the same).

On Mon, 2025-06-30 at 23:12 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey 
> ---
>  doc/Makefile.am   |  1 +
>  doc/elf_rawfile.3 | 71 +++
>  2 files changed, 72 insertions(+)
>  create mode 100644 doc/elf_rawfile.3
> 
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index 7d5a3eef..50ab63ec 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -84,6 +84,7 @@ notrans_dist_man3_MANS= elf32_checksum.3 \
>   elf_nextscn.3 \
>   elf_rand.3 \
>   elf_rawdata.3 \
> + elf_rawfile.3 \
>   elf_update.3 \
>   elf_version.3 \
>   libelf.3

OK.

> diff --git a/doc/elf_rawfile.3 b/doc/elf_rawfile.3
> new file mode 100644
> index ..d7a3e3fb
> --- /dev/null
> +++ b/doc/elf_rawfile.3
> @@ -0,0 +1,71 @@
> +.TH ELF_RAWFILE 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf_rawfile \- Retrieve a pointer to the entire raw ELF file image
> +
> +.SH SYNOPSIS
> +.nf
> +#include 
> +
> +.BI "char *elf_rawfile(Elf *" elf ", size_t *" ptr ");"
> +.fi

OK.

> +.SH DESCRIPTION
> +The
> +.BR elf_rawfile ()
> +function returns a pointer to the entire contents of the ELF file 
> represented by
> +.IR elf .
> +This data is unprocessed and includes everything from the ELF header to the
> +final byte.
> +
> +If the ELF descriptor was opened from memory or the file has already been
> +memory-mapped or fully read, this function returns a pointer to the internal 
> buffer.
> +
> +If the ELF data has not yet been read or mapped, it is loaded on demand.

OK.

> +If
> +.I ptr
> +is non-NULL, the total size in bytes of the raw file is stored in
> +.IR *ptr .
> +
> +The returned buffer is read-only and managed internally by libelf.
> +The application must not modify or free it.

OK.

> +.SH PARAMETERS
> +.TP
> +.I elf
> +A handle previously returned by
> +.BR elf_begin (3) .

Or elf_memory?

> +.TP
> +.I ptr
> +If not
> +.BR NULL ,
> +receives the size in bytes of the ELF file.

receives? maybe "is set to"?

> +.SH RETURN VALUE
> +Returns a pointer to the start of the ELF file data. On failure,
> +.B NULL
> +is returned and
> +.I *ptr
> +(if non-NULL) is set to 0.

OK.

> +.SH SEE ALSO
> +.BR libelf (3),
> +.BR elf (5)
> +
> +.SH ATTRIBUTES
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +InterfaceAttribute   Value
> +T{
> +.na
> +.nh
> +.BR elf_rawfile ()
> +T}   Thread safety   MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to  or 
> https://sourceware.org/bugzilla/.

OK.

Thanks,

Mark


Re: [PATCH 16/16] doc: Add elf_strptr.3

2025-07-10 Thread Mark Wielaard
Hi Aaron,

On Mon, 2025-06-30 at 23:12 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey 
> ---
>  doc/Makefile.am  |  1 +
>  doc/elf_strptr.3 | 72 
>  2 files changed, 73 insertions(+)
>  create mode 100644 doc/elf_strptr.3
> 
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index dc4a8b18..f7446872 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -86,6 +86,7 @@ notrans_dist_man3_MANS= elf32_checksum.3 \
>   elf_rawdata.3 \
>   elf_rawfile.3 \
>   elf_scnshndx.3 \
> + elf_strptr.3 \
>   elf_update.3 \
>   elf_version.3 \
>   libelf.3

OK.

> diff --git a/doc/elf_strptr.3 b/doc/elf_strptr.3
> new file mode 100644
> index ..1cfdf401
> --- /dev/null
> +++ b/doc/elf_strptr.3
> @@ -0,0 +1,72 @@
> +.TH ELF_STRPTR 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf_strptr \- Return a pointer to a string in a string table section
> +
> +.SH SYNOPSIS
> +.nf
> +#include 
> +
> +.BI "char *elf_strptr(Elf *" elf ", size_t " section_index ", size_t " 
> offset ");"
> +.fi

OK.

> +.SH DESCRIPTION
> +The
> +.BR elf_strptr ()
> +function returns a pointer to a null-terminated string located at
> +.I offset
> +bytes from the beginning of the string table section identified by
> +.IR section_index .
> +The section must be of type
> +.BR SHT_STRTAB .

OK.

> +This function validates the provided offset against the size of the string
> +table and ensures the string is null-terminated. It transparently handles
> +both uncompressed and compressed sections.

Maybe explicitly say that the offset is interpreted as if from the
uncompressed data? And that the string returned is a valid pointer into
the uncompressed data?

> +
> +If the ELF descriptor is not backed by memory mapping, or the section has
> +not been loaded yet, the function will read and initialize the necessary
> +data from the file.

OK.

> +.SH PARAMETERS
> +.TP
> +.I elf
> +Pointer to an ELF descriptor.
> +
> +.TP
> +.I section_index
> +The index of the string table section (of type
> +.BR SHT_STRTAB ).
> +
> +.TP
> +.I offset
> +The byte offset from the beginning of the string table section where
> +the desired string is located.

OK.

> +
> +.SH RETURN VALUE
> +Returns a pointer to the string within the string table if successful.
> +Returns
> +.B NULL
> +on error.
> +
> +.SH SEE ALSO
> +.BR elf (3),
> +.BR elf_getscn (3),
> +.BR libelf (3),
> +.BR elf (5)

Maybe add elf32/64_getshdr and gelf_getsym as examples of sh_name
(.shstrtab) or st_name (.strtab) getting name strings?

> +
> +.SH ATTRIBUTES
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +InterfaceAttribute   Value
> +T{
> +.na
> +.nh
> +.BR elf_strptr ()
> +T}   Thread safety   MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to  or 
> https://sourceware.org/bugzilla/.

OK.

Thanks,

Mark