Hi Aaron, On Tue, 2025-04-01 at 00:05 -0400, Aaron Merey wrote: > diff --git a/doc/elf_getbase.3 b/doc/elf_getbase.3 > new file mode 100644 > index 00000000..1934e1ac > --- /dev/null > +++ b/doc/elf_getbase.3 > @@ -0,0 +1,55 @@ > +.TH ELF_GETBASE 3 2025-03-31 "Libelf" "Libelf Programmer's Manual" > + > +.SH NAME > +elf_getbase \- Retrieve the base offset for an ELF object file. > + > +.SH SYNOPSIS > +.B #include <libelf.h> > + > +.BI "int64_t elf_getbase(Elf *" elf ");" > + > +.SH DESCRIPTION > +.B elf_getbase > +returns the file offset of the first byte of the ELF descriptor > +.IR elf .
Interesting, I didn't actually knew what this did. I had to look at the one single use we have of this in tests/arextract.c. So it can be used for a naive ar extraction utility. Our eu-ar uses elf_rawfile for that though. > +If > +.I elf > +is a member of an archive and has ELF kind > +.BR ELF_K_AR , > +the base offset is the offset of the ELF object within the archive. > +For other ELF object types the base offset is 0. So this is only really interesting for AR entries? And then it gives the file offset right after the AR header? Otherwise it returns zero? > +.SH PARAMETERS > +.TP > +.I elf > +The ELF descriptor. > + > +.SH RETURN VALUE > +Return the base offset of > +.IR elf . > +If > +.I elf > +is NULL, return -1. So should this say if the ELF kind is not ELF_K_AR it returns, unless the elf is NULL, then it returns -1? > +.SH SEE ALSO > +.BR libelf (3), > +.BR elf (5) Maybe reference elf_getaroff? Which seems to do the same, but gives the offset to the AR header inside the file? And elf_rawelf which gives you a pointer to the same offset to read from. > +.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 elf_getbase () > +T} Thread safety MT-Safe > +.TE > + > +.SH REPORTING BUGS > +Report bugs to <elfutils-devel@sourceware.org> or > https://sourceware.org/bugzilla/. Cheers, Mark