ELF_FLAGELF(3)
π ELF_FLAGELF π β from the Libelf Programmer's Manual
okay bestie, sit down, we're doing libelf flag manipulation and honestly? it's giving main character energy β¨
πΈ NAME πΈ
elf_flagelf, elf_flagdata, elf_flagehdr, elf_flagphdr, elf_flagscn, elf_flagshdr β set or clear flags on ELF descriptors and components. six little functions, one big vibe. π«Ά
β¨ SYNOPSIS β¨
#include <libelf.h>
unsigned int elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned int flags);
like, look at them. all lined up. so tidy. π
π DESCRIPTION π
So these functions let you, the caller, set or clear flags on the various ELF components that libelf is managing. They're the "hey bestie, I changed something" API. Typically you use them to mark a component as modified (aka dirty π«§), or to control layout behavior when stuff gets written out.
elf_flagelf()β modifies flags on the top-levelElfdescriptor. the big boss. the CEO. πelf_flagdata()β modifies flags on anElf_Datadescriptor, usually one you got fromelf_getdata(3)or made withelf_newdata(3).elf_flagehdr()β modifies flags on the ELF header for an ELF descriptor (like, the thinggelf_getehdr(3)hands you).elf_flagphdr()β modifies flags on the program header table of an ELF descriptor.elf_flagscn()β modifies flags on anElf_Scn(section) descriptor.elf_flagshdr()β modifies flags on the section header of a givenElf_Scn.
The cmd argument is literally just deciding: are we setting these flags (ELF_C_SET) or clearing them (ELF_C_CLR)? that's it. that's the whole job. π
The following flag values may be passed via the flags parameter:
ELF_F_DIRTYβ marks the object as modified. This makes sure changes to the component get written out duringelf_update(3). if you changed it and you want it on disk, this is the one, no cap. βοΈELF_F_LAYOUTβ says that the layout of the ELF component is managed manually by you. Offsets and sizes will be preserved exactly as provided. This flag is only used withelf_flagelf()and is ignored when used with the other functions. If this flag is set, the user must setEhdre_phoff,e_shoff, as well asElf_Datad_offandShdrsh_offset. If it's not set, then those offsets will be recalculated whenelf_updateis called. And heads up: ifELF_F_LAYOUTis set, then changes to phdr offsets will preventelf_updatefrom automatically adjusting shdr offsets. πELF_F_PERMISSIVEβ enables relaxed validation of object structure. This flag permits nonstandard layouts without strict checks. Specifically, it removes a check inelf_update()that the sectionsh_sizeis a multiple of the sectionsh_entsize(if not zero). This flag is only used withelf_flagelf()and is ignored when used with the other functions.ELF_F_PERMISSIVEis an elfutils libelf extention and may not be available in other libelf implementations. (yes it says "extention" in the original, we don't fix, we report π)
β οΈ real talk:ELF_F_LAYOUTandELF_F_PERMISSIVEare only forelf_flagelf(). everywhere else they get ignored. don't be out here passing them toelf_flagshdrand expecting a moment. π
π¦ PARAMETERS π¦
objβ the object to be modified. Forelf_flagelf,elf_flagehdr,elf_flagphdr, this is anElf *descriptor. Forelf_flagscnandelf_flagshdr, this is anElf_Scn *descriptor. Forelf_flagdata, anElf_Data *buffer.cmdβ must be either:ELF_C_SETto set the given flags, orELF_C_CLRto clear them. pick one, bestie, there's no third option. βflagsβ bitmask of flags to modify. May include any combination ofELF_F_DIRTY,ELF_F_LAYOUT, andELF_F_PERMISSIVE.
Note that ELF_F_LAYOUT and ELF_F_PERMISSIVE are only used with elf_flagelf() and are ignored for other functions. (say it with me one more time for the people in the back π£)
π RETURN VALUE π
Returns the new value of the flags after the set/clear operation. so you always know what you're working with. slay. π
Returns 0 on error, and sets an error code retrievable via elf_errmsg(3).
If the first argument is NULL then 0 is return and no error code is set.
If the last flag is cleared, 0 will be returned as the new flag value. In this case 0 is not an error indicator and no error code is set.
π this is the classic "is 0 bad or is 0 just empty" situation. read carefully. zero can mean "everything's cleared, we're chilling" OR "something went wrong". context is everything, iykyk.
π§ SEE ALSO π§
elf_errmsg(3), elf_update(3), libelf(3), elf(5)
π ATTRIBUTES π
- Interface:
elf_flagelf(),elf_flagehdr(),elf_flagphdr(),elf_flagscn(),elf_flagshdr(),elf_flagdata() - Attribute: Thread safety
- Value: MT-Unsafe race
so like, all six of them, same energy: MT-Unsafe race. be careful out here in multithreaded land. π«§
π REPORTING BUGS π
Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.
found a bug? tell the girlies at sourceware. they'll handle it. π«Ά
and that's the whole page, bestie β brought to you by Libelf, dated 2025-06-23, living in section 3 of your friendly neighborhood manual. go forth and flag responsibly. periodt. π β¨
π¦ 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