GELF_NEWEHDR(3)
GELF_NEWEHDR(3) π
okay bestie, welcome to the Libelf Programmer's Manual β¨ today we're talking about gelf_newehdr and honestly? she's a builder. a little maker of beginnings. let's get into it π
β¨ NAME β¨
gelf_newehdr β allocate and initialize a new ELF file header π¦
β¨ SYNOPSIS β¨
#include <gelf.h>
void *gelf_newehdr(Elf *elf, int class);
β¨ DESCRIPTION β¨
so like, gelf_newehdr() allocates and initializes a brand new ELF header for elf, but only if a header doesn't already exist. like, she's not gonna overwrite anything, she's just here to set you up. and when that new ELF header gets created, every single one of its fields is zero-initialized. blank slate energy. main character debut. π
you, the caller, have to tell her which ELF class you want via class, and it must be one of these two:
ELFCLASS32β request a 32-bit ELF file header πELFCLASS64β request a 64-bit ELF file header π
not me being picky but fr, those are the only two options. pick one.
β¨ PARAMETERS β¨
elfβ pointer to an ELF descriptor of kindELF_K_ELF. that's the vibe check she needs to pass.classβ the requested ELF class for the new header. must beELFCLASS32orELFCLASS64. no in-between, no "other", periodt.
β¨ RETURN VALUE β¨
on success, gelf_newehdr() returns a non-zero value β¨ (slay). you can then grab the ELF header of elf using gelf_getehdr(). you could also use elf32_getehdr() or elf64_getehdr(), depending on which ELF class you specified with class. iykyk π«Ά
on failure, NULL is returned and elf_errno is set. π BUT β and this is important, bestie β if elf is NULL, then NULL is returned without setting elf_errno. like, no error code for you. nothing. silence. π
heads up: in other libelf implementations, the gelf_newehdr() return value may be a different type. so don't go assuming, okay? πΈ
β¨ SEE ALSO β¨
elf32_getehdr()elf64_getehdr()gelf_getehdr(3)gelf_update_ehdr(3)libelf(3)elf(5)
β¨ ATTRIBUTES β¨
- Interface:
gelf_newehdr() - Attribute: Thread safety
- Value:
MT-Safe
so yeah, she's thread safe. go off, queen π
β¨ REPORTING BUGS β¨
found a bug? don't suffer in silence, bestie π report it to <elfutils-devel@sourceware.org> or hit up <https://sourceware.org/bugzilla/>. they wanna know fr fr π
and that's the whole page!! ty for reading, ily, go write some ELF headers ππ
this cutie was brought to you by Libelf, dated 2025-09-17 β catch you on the next manpage, bestie πβ¨π¦
π¦ where this page comes from
- 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.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
- nixpkgs unstable: elfutils 0.195
- 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