ELF_FLAGDATA(3)
π ELF_FLAGDATA β the libelf flag-shuffling girlies π
okay so this is a page from the Library Functions Manual and it's literally about the elf_flag* girlies in the ELF Access Library (libelf, link with -lelf). bestie, these functions are your little flag remote controls π
β¨ SYNOPSIS β¨
#include <libelf.h>
unsigned int
elf_flagarhdr(Elf_Arhdr *arhdr, Elf_Cmd cmd, unsigned int flags);
unsigned int
elf_flagdata(Elf_Data *data, Elf_Cmd cmd, unsigned int flags);
unsigned int
elf_flagehdr(Elf *elf, Elf_Cmd cmd, unsigned int flags);
unsigned int
elf_flagelf(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);
like, seven little functions, all matching, all iconic π
πΈ DESCRIPTION πΈ
So here's the vibe: these functions let you query, set, or reset flags on the data structures that hang out with an ELF file. flag goblin behaviour only π
The arguments arhdr, data, elf and scn are the data structures whose flags you're changing. Important though β these are not just any rando values, they should have come back from earlier calls to functions in the elf(3) API set:
arhdrshould have been returned by a prior call toelf_getarhdr(3).datashould have been returned by a prior call to one ofelf_newdata(3),elf_getdata(3)orelf_rawdata(3).elfshould have been allocated by a prior call to one ofelf_begin(3)orelf_memory(3).scnshould have been returned by a prior call to one ofelf_getscn(3),elf_newscn(3)orelf_nextscn(3).
and the best part? these values are allowed to be NULL to simplify error handling in your application code π«Ά so you can be a little lazy and it's legal.
The argument cmd may have the following values:
ELF_C_CLRβ the argumentflagsspecifies the flags to be cleared. bye bye flags π¨ELF_C_SETβ the argumentflagsspecifies the flags to be set. hello flags β¨
And the argument flags is allowed to have the following flags set:
ELF_F_ARCHIVEβ this flag is only valid with theelf_flagelf()API. it informs the library that the application desires to create anar(1)archive. the argumentelfshould have been opened for writing using theELF_C_WRITEcommand to functionelf_begin().ELF_F_ARCHIVE_SYSVβ this flag is used in conjunction with theELF_F_ARCHIVEflag to indicate that the library should create archives that conform to System V layout rules. the default is to create BSD style archives. (default behaviour is always the plot twist π)ELF_F_DIRTYβ mark the associated data structure as needing to be written back to the underlying file. a subsequent call toelf_update(3)will resynchronize the library's internal data structures.ELF_F_LAYOUTβ this flag is only valid with theelf_flagelf()API. it informs the library that the application will take responsibility for the layout of the file and that the library is not to insert any padding in between sections. you're the main character now, you handle the layout π
ngl this part matters: marking a given data structure as "dirty" affects all of its contained elements. so marking an ELF descriptorelfwithelf_flagelf(elf, ELF_C_SET, ELF_F_DIRTY)means that the entire contents of the descriptor are "dirty". it's giving contagious β¨
And last but not least: using a value of zero for argument flags will return the current set of flags for the data structure being queried. zero equals "just show me what's there" π
π¦ RETURN VALUES π¦
These functions return the updated flags if successful, or zero if an error is detected. zero is the "something went wrong" number, not a mood π
π§ COMPATIBILITY π§
Heads up bestie: the elf_flagarhdr() function and the ELF_F_ARCHIVE and ELF_F_ARCHIVE_SYSV flags are an extension to the elf(3) API. not standard, but iconic π
π ERRORS π
These functions may fail with the following errors:
[ELF_E_ARGUMENT]β an unsupported value was used for thecmdargument.[ELF_E_ARGUMENT]β argumentflagshad unsupported flags set.[ELF_E_ARGUMENT]β the argumentelfwas not a descriptor for an ELF object.[ELF_E_MODE]β theELF_F_ARCHIVEflag was used with an ELF descriptor that had not been opened for writing.[ELF_E_SEQUENCE]β functionelf_flagehdr()was called without an executable header being allocated.[ELF_E_SEQUENCE]β functionelf_flagphdr()was called without a program header being allocated.
fr fr read those [ELF_E_SEQUENCE] ones β order of operations matters, don't be out here flagging headers that don't exist yet ππ
π SEE ALSO π
elf(3), elf32_newehdr(3), elf32_newphdr(3), elf64_newehdr(3), elf64_newphdr(3), elf_newdata(3), elf_update(3), gelf(3), gelf_newehdr(3), gelf_newphdr(3), gelf_update_dyn(3), gelf_update_move(3), gelf_update_rel(3), gelf_update_rela(3), gelf_update_sym(3), gelf_update_syminfo(3)
the whole friend group, go say hi π«Άβ¨
mwah π this page came from Debian, dated June 12, 2019 β shoutout to the Debian girlies for keeping the docs cute. go forth and flag responsibly, bestie ππ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: libelf 15.0.0
- Copyright (c) 2006-2008,2011 Joseph Koshy. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms