GELF_NEWEHDR(3)

πŸ“¦
version 0.197 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu stonking

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 kind ELF_K_ELF. that's the vibe check she needs to pass.
  • class β€” the requested ELF class for the new header. must be ELFCLASS32 or ELFCLASS64. 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 ✨


✨ 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