ELF_RAWDATA(3)
β¨ ELF_RAWDATA π
okay bestie, welcome to elf_rawdata β it lives in the Libelf Programmer's Manual and it is literally the "give me the section exactly as it sat on disk, no glow-up, no filter" function π
πΈ SYNOPSIS πΈ
#include <libelf.h>
Elf_Data *elf_rawdata(Elf_Scn *scn, Elf_Data *data);
π DESCRIPTION π
so. elf_rawdata() hands you back a pointer to an Elf_Data structure, and inside that structure is the unprocessed (raw) contents of the section that scn is pointing at. no cap.
and when we say raw, we mean raw raw β this view is the exact on-disk binary layout of the ELF file, with zero modifications made for endianness or memory alignment. it's the section in its natural habitat, before anyone touched it π¦
if you actually want the data translated into the in-memory format, that's a different function, babe β go use elf_getdata(3). that's the one that does the translation. this one does not. periodt.
now, the data parameter, and this matters:
- if
dataisNULL, the raw data of the section is returned. - if
datais notNULLand raw data has not been initialized, the call fails. π
compressed sections? bestie, listen. for compressed sections (i.e., ones with the SHF_COMPRESSED flag), the returned Elf_Data contains the compressed form, and its d_type is ELF_T_CHDR. it does not unzip anything for you, it's just handing you the compressed vibe as-is.
for sections of type SHT_NOBITS, the d_buf pointer is NULL. no buffer, no drama.
β οΈ important, and I need you to hear me on this one: theElf_Data *returned by this function and itsd_bufare owned by libelf and should not be freed. they're only valid untilelf_end(3)is called on theElfdescriptor associated withscn. so don't free them, don't hoard them, don't keep them pastelf_end. that's it, that's the rule π
π«Ά PARAMETERS π«Ά
scnβ a section descriptor returned fromelf_getscn(3)orelf_nextscn(3). and if it'sNULL? then this function returnsNULL. it's giving "you get nothing, respectfully" πdataβ must beNULLon the initial invocation. any other use is not supported. that's not me being mean, that's just the facts π
π RETURN VALUE π
it returns a pointer to an Elf_Data descriptor describing the raw contents of the section. if something goes wrong, NULL is returned and elf_errno is set. so like, always check your elf_errno, bestie, that's the whole plot twist π
π₯ SEE ALSO π₯
elf_getdata(3)elf_getscn(3)elf_compress(3)libelf(3)elf(5)
β ATTRIBUTES β
- Interface:
elf_rawdata() - Attribute: Thread safety
- Value:
MT-Safe
(yes bestie, it's MT-Safe. multi-threaded and unbothered. main character energy fr fr β¨)
π REPORTING BUGS π
found a bug? don't gatekeep it, report it to <elfutils-devel@sourceware.org> or over at https://sourceware.org/bugzilla/. the maintainers will literally be obsessed with you for it π
and that's the whole page, bestie!! this was Libelf, dated 2025-06-30 β go forth, read your raw section bytes, and do not free that pointer. iykyk ππ§
π¦ where this page comes from
- alpine 3.23: elfutils-doc 0.194-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- alpine 3.24: elfutils-doc 0.195-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- arch rolling: libelf 0.196-1
- arch rolling: libelf 0.197-1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 10: elfutils-libelf-devel 0.197-1.el10 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.194-5.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.194-5.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- nixos 26.05: elfutils 0.194
- nixpkgs unstable: elfutils 0.195
- ubuntu resolute: libelf-dev 0.194-4 Β· GPL-3.0-or-later
- ubuntu stonking: libelf-dev 0.196-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms