[1/9] doc: Add elf32_checksum.3 and elf64_checksum.3

Message ID 20240814213321.244089-1-amerey@redhat.com
State Superseded
Delegated to: Mark Wielaard
Headers
Series [1/9] doc: Add elf32_checksum.3 and elf64_checksum.3 |

Commit Message

Aaron Merey Aug. 14, 2024, 9:33 p.m. UTC
  Signed-off-by: Aaron Merey <amerey@redhat.com>
---
 doc/elf32_checksum.3 | 47 ++++++++++++++++++++++++++++++++++++++++++++
 doc/elf64_checksum.3 | 47 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 doc/elf32_checksum.3
 create mode 100644 doc/elf64_checksum.3
  

Comments

Mark Wielaard Aug. 27, 2024, 2:41 p.m. UTC | #1
Hi Aaron,

On Wed, 2024-08-14 at 17:33 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey <amerey@redhat.com>
> ---
>  doc/elf32_checksum.3 | 47 ++++++++++++++++++++++++++++++++++++++++++++
>  doc/elf64_checksum.3 | 47 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 94 insertions(+)
>  create mode 100644 doc/elf32_checksum.3
>  create mode 100644 doc/elf64_checksum.3
> 
> diff --git a/doc/elf32_checksum.3 b/doc/elf32_checksum.3
> new file mode 100644
> index 00000000..617b955c
> --- /dev/null
> +++ b/doc/elf32_checksum.3
> @@ -0,0 +1,47 @@
> +.TH ELF32_CHECKSUM 3 2024-08-14 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf32_checksum \- compute the checksum for an ELF32 object file
> +
> +.SH SYNOPSIS
> +.B #include <libelf.h>
> +
> +.BI "long int elf32_checksum(Elf *" elf ");"
> +
> +.SH DESCRIPTION
> +Compute a checksum for the ELF32 object file referred to by
> +.I elf.
> +The checksum is computed from permanent parts of the ELF file and
> +the result is repeatable.

So this one (and the elf64 variant) are a little funny in that I don't
believe anybody really uses it. Because it is defined so fuzzy.

But I think you should explain what "permanent parts" are. The intent
is that you get a checksum that stays the same whether or not the file
is stripped. So this implementation only computes a checksum over
sections that aren't SECTION_STRIP_P (see libelf/elf-knowledge.h) and
it (obviously) ignores SHT_NOBITS sections.

Another issue is that the result is defined as long int, so depending
on platform/arch long int might be 4 to 8 bytes... But we use the crc32
from lib/crc32.c so the result is always capped to an uint32_t. I am
not sure whether that is sign-extended or not. Might want to double
check.

Finally the checksum would be set as DT_CHECKSUM in the dynamic section
(presumable as a kind of pre-build-id like value). But only prelink
ever did that (to preserve/check the original content before
prelinking). I don't believe any current utility does use DT_CHECKSUM
these days (adding it the the dynamic section would of course break the
checksum, and I don't know how one would handle that...)

> +.SH PARAMETERS
> +.TP
> +.I elf
> +The ELF32 object file for which the checksum is to be computed.
> +
> +.SH RETURN VALUE
> +On success, return the computed checksum. If an error occurs, return -1 and set a libelf error code.
> +
> +.SH SEE ALSO
> +.BR elf_errno (3),
> +.BR elf64_checksum (3),
> +.BR libelf (3),
> +.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_checksum ()
> +T}	Thread safety	MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.

Cheers,

Mark
  

Patch

diff --git a/doc/elf32_checksum.3 b/doc/elf32_checksum.3
new file mode 100644
index 00000000..617b955c
--- /dev/null
+++ b/doc/elf32_checksum.3
@@ -0,0 +1,47 @@ 
+.TH ELF32_CHECKSUM 3 2024-08-14 "Libelf" "Libelf Programmer's Manual"
+
+.SH NAME
+elf32_checksum \- compute the checksum for an ELF32 object file
+
+.SH SYNOPSIS
+.B #include <libelf.h>
+
+.BI "long int elf32_checksum(Elf *" elf ");"
+
+.SH DESCRIPTION
+Compute a checksum for the ELF32 object file referred to by
+.I elf.
+The checksum is computed from permanent parts of the ELF file and
+the result is repeatable.
+
+.SH PARAMETERS
+.TP
+.I elf
+The ELF32 object file for which the checksum is to be computed.
+
+.SH RETURN VALUE
+On success, return the computed checksum. If an error occurs, return -1 and set a libelf error code.
+
+.SH SEE ALSO
+.BR elf_errno (3),
+.BR elf64_checksum (3),
+.BR libelf (3),
+.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_checksum ()
+T}	Thread safety	MT-Safe
+.TE
+
+.SH REPORTING BUGS
+Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.
diff --git a/doc/elf64_checksum.3 b/doc/elf64_checksum.3
new file mode 100644
index 00000000..916cedaa
--- /dev/null
+++ b/doc/elf64_checksum.3
@@ -0,0 +1,47 @@ 
+.TH ELF64_CHECKSUM 3 2024-08-14 "Libelf" "Libelf Programmer's Manual"
+
+.SH NAME
+elf64_checksum \- compute the checksum for an ELF64 object file
+
+.SH SYNOPSIS
+.B #include <libelf.h>
+
+.BI "long int elf64_checksum(Elf *" elf ");"
+
+.SH DESCRIPTION
+Compute a checksum for the ELF64 object file referred to by
+.I elf.
+The checksum is computed from permanent parts of the ELF file and
+the result is repeatable.
+
+.SH PARAMETERS
+.TP
+.I elf
+The ELF64 object file for which the checksum is to be computed.
+
+.SH RETURN VALUE
+On success, return the computed checksum. If an error occurs, return -1 and set a libelf error code.
+
+.SH SEE ALSO
+.BR elf_errno (3),
+.BR elf32_checksum (3),
+.BR libelf (3),
+.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 elf64_checksum ()
+T}	Thread safety	MT-Safe
+.TE
+
+.SH REPORTING BUGS
+Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.