ELF / Dynamic section types / Possible bug in the header

0

Pytanie do tych co ostro grzebią w Linuxie: Mamy sobie elf.h a w nim taką oto deklarację:
https://github.com/lattera/glibc/blob/master/elf/elf.h#L873 (i tutaj: https://code.woboq.org/userspace/glibc/elf/elf.h.html)

#define	DT_INIT_ARRAY	25		/* Array with addresses of init fct */
#define	DT_FINI_ARRAY	26		/* Array with addresses of fini fct */
#define	DT_INIT_ARRAYSZ	27		/* Size in bytes of DT_INIT_ARRAY */
#define	DT_FINI_ARRAYSZ	28		/* Size in bytes of DT_FINI_ARRAY */
#define DT_RUNPATH	29		/* Library search path */
#define DT_FLAGS	30		/* Flags for the object being loaded */
#define DT_ENCODING	32		/* Start of encoded range */
#define DT_PREINIT_ARRAY 32		/* Array with addresses of preinit fct*/
#define DT_PREINIT_ARRAYSZ 33		/* size in bytes of DT_PREINIT_ARRAY */
#define DT_SYMTAB_SHNDX	34		/* Address of SYMTAB_SHNDX section */

Widać że DT_ENCODING i DT_PREINIT_ARRAY dzielą tą samą wartość. Wygląda jakby był błąd i zamiast 32 powinno być 31.
Tyle że ludzie od libc żyją w jaskini i nie ma nawet gdzie zapytać (nie mam ochoty na pałowanie na SO dzisiaj), ani Slacka ani Discord'a tylko lista mailingowa...

Może ktoś bawił się w parsowanie ELFów i wie czy ta deklaracja jest poprawna czy to faktycznie błąd i powinno być 31?

1

Źle do tego podchodzisz.
Ważniejszy jest kontekst w jakim użyte są te stałe, a nie jaką wartość mają sąsiedzi.
Np DT_ENCODING może występować tylko po jakiejś konkretnej wartości, a DT_PREINIT_ARRAY jeszcze po innej.
Albo obie wartości są w innej części elf.
Przedukaj repo by zobaczyć kiedy te wartości są używane.
Albo jeszcze lepiej poszukaj specyfikacji ELF.

0

Masz rację, zgodnie z tym co tutaj pisze: https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-42444/index.html

To make interpreting the contents of dynamic section entries simpler for tools, the value of each tag, except for those in two special compatibility ranges, will
determine the interpretation of the d_un union. A tag whose value is an even number indicates a dynamic section entry that uses d_ptr. A tag whose value is an odd
number indicates a dynamic section entry that uses d_val or that uses neither d_ptr nor d_val. Tags whose values are less than the special value DT_ENCODING
and tags whose values fall between DT_HIOS and DT_LOPROC do not follow these rules.

To jest to wartość znacznikowa.

1 użytkowników online, w tym zalogowanych: 0, gości: 1