Hi Aaron,

On Wed, 2024-08-14 at 17:33 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey <ame...@redhat.com>
> ---
>  doc/elf32_fsize.3 | 59 +++++++++++++++++++++++++++++++++++++++++++++++
>  doc/elf64_fsize.3 | 59 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 118 insertions(+)
>  create mode 100644 doc/elf32_fsize.3
>  create mode 100644 doc/elf64_fsize.3
> 
> diff --git a/doc/elf32_fsize.3 b/doc/elf32_fsize.3
> new file mode 100644
> index 00000000..ea86157f
> --- /dev/null
> +++ b/doc/elf32_fsize.3
> @@ -0,0 +1,59 @@
> +.TH ELF32_FSIZE 3 2024-08-14 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf32_fsize \- calculate the file size of various ELF32 data structures
> +
> +.SH SYNOPSIS
> +.B #include <libelf.h>
> +
> +.BI "size_t elf32_fsize(Elf_Type " type ", size_t " count ", unsigned int " 
> version ");"
> +
> +.SH DESCRIPTION
> +Calculate the file size in bytes of various ELF32 data structures,
> +given their type and count.

Maybe try rewording not using the exact names in the function
declaration?

"Given an Elf_Type representation of core Elf structures and the number
of items (and the ELF version) returns the number of bytes needed for
the on-disk representation in a 32-bit ELF file."?

Also you should probably note that this libelf implementation relies on
the in-memory representation being the same size as the on-disk
representation.

Maybe give at least some examples of Elf_Type and which data structure
they represent? ELF_T_ADDR (32 bit address), ELF_T_EHDR (Elf32_Ehdr),
etc.

And mention that elf_getdata will set the Elf_Data d_type to the
Elf_Type of the section?

> +.SH PARAMETERS
> +.TP
> +.I type
> +The ELF32 data structure type for which the file size is to be calculated. 
> See
> +.BR libelf.h
> +for a list of valid
> +.BR Elf_Type

Should we have a libelf man page instead that describes these data
structures?

> +values.
> +
> +.TP
> +.I count
> +The number of elements of the specified type.
> +
> +.TP
> +.I version
> +The ELF version. This should be set to
> +.B EV_CURRENT.

Yeah, maybe explicitly say that this is the only valid value.

> +.SH RETURN VALUE
> +The size in bytes of the specified count and type of data structure.  If an 
> error occurs,
> +return 0 and set a libelf error code.

Maybe explicitly say what an error is?
version != EV_CURRENT or type isn't a valid Elf_Type.

I also note that the result will overflow if
count > SIZE_MAX / elf32_fsize(type, 1, 1)
But doesn't produce an error (should it?)

> +.SH SEE ALSO
> +.BR elf_errno (3),
> +.BR elf64_fsize (3),
> +.BR libelf (3),

Aha, you are already referencing it. But it doesn't exist yet?

> +.BR elf (5)
> +
> +.SH ATTRIBUTES
> +For an explanation of the terms used in this section, see
> +.BR attributes (7).
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +Interface    Attribute       Value
> +T{
> +.na
> +.nh
> +.BR elf32_fsize ()
> +T}   Thread safety   MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to <elfutils-devel@sourceware.org> or 
> https://sourceware.org/bugzilla/.

Cheers,

Mark

Reply via email to