DWARF_GET_WEAKS(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

✨ DWARF_GET_WEAKS πŸ’…

okay bestie, so this is a page from the Library Functions Manual β€” it's DWARF_GET_WEAKS(3), and yes the title is in all caps because it's that girl. We're talking libdwarf, we're talking weak symbols, we're talking the SGI-specific ".debug_weaknames" section. Buckle up πŸŽ€


🌸 NAME 🌸

dwarf_get_weaks, dwarf_weak_cu_offset, dwarf_weak_die_offset, dwarf_weak_name_offsets, dwarf_weakname β€” the whole squad that retrieves information about weak symbols 🫢


πŸ¦‹ LIBRARY πŸ¦‹

DWARF Access Library (libdwarf, -ldwarf) β€” like, that's the house these functions live in, no cap.


⭐ SYNOPSIS ⭐

#include <libdwarf.h>

int
dwarf_get_weaks(Dwarf_Debug dbg, Dwarf_Weak **weaks,
    Dwarf_Signed *nweaks, Dwarf_Error *err);

int
dwarf_weak_cu_offset(Dwarf_Weak weak, Dwarf_Off *cu_offset,
    Dwarf_Error *err);

int
dwarf_weak_die_offset(Dwarf_Weak weak, Dwarf_Off *die_offset,
    Dwarf_Error *err);

int
dwarf_weak_name_offsets(Dwarf_Weak weak, char **name,
    Dwarf_Off *die_offset, Dwarf_Off *cu_die_offset, Dwarf_Error *err);

int
dwarf_weakname(Dwarf_Weak weak, char **name, Dwarf_Error *err);

πŸ’– DESCRIPTION πŸ’–

So these functions pull info about weak symbols out of the lookup tables in the (SGI-specific) ".debug_weaknames" section. And the way they hand you that info? Through opaque descriptors of type Dwarf_Weak β€” very mysterious, very main character energy πŸ’…. You can't just peek inside them, bestie; applications need to use the functions described below to retrieve the name and offset information contained in these descriptors.

dwarf_get_weaks() retrieves descriptors for all the weak symbols associated with the DWARF debug context specified by argument dbg. The argument weaks should point to a location that will be set to a pointer to an array of Dwarf_Weak descriptors. And the argument nweaks? That should point to a location that will be set to the number of descriptors returned. Two outputs, one call, we love efficiency ✨

dwarf_weak_cu_offset() returns the offset, relative to the ".debug_info" section, of the compilation unit that contains the debugging information entry associated with the argument weak. Argument cu_offset should point to a location that will hold the returned offset. Slay.

dwarf_weak_die_offset() retrieves the offset, relative to the ".debug_info" section, of the debugging information entry associated with the argument weak, and stores it into the location pointed to by the argument die_offset. Same vibe, different offset πŸ’€

dwarf_weak_name_offsets() is the overachiever β€” it retrieves both the name and offsets for the debugging information entry for argument weak. Let's break it down, because there's a lot going on:

  • Argument name should point to a location which will be set to a pointer to a NUL-terminated string containing the name of the associated debugging information entry.
  • Argument die_offset should point to a location which will be set to the offset, relative to the ".debug_info" section, of the associated debugging information entry.
  • Argument cu_die_offset should point to a location which will be set to the offset, relative to the ".debug_info" section, of the first debugging information entry in the compilation unit associated with argument weak.

dwarf_weakname() sets the location pointed to by argument name to a pointer to a NUL-terminated string holding the name of the debugging information entry associated with the argument weak. Simple, cute, does exactly one thing πŸŽ€

🧚 Memory Management 🧚

okay this part is important so listen up πŸ™ˆ

The memory area used for the array of Dwarf_Weak descriptors returned in argument weaks by function dwarf_get_weaks() is owned by the DWARF Access Library (libdwarf, -ldwarf). Application code should not attempt to directly free this pointer. Portable code should instead use the function dwarf_weaks_dealloc(3) to indicate that the memory area may be freed. Like, it's not yours, don't touch it, ask nicely through the proper API 😭

The memory area used for the string returned in the name argument to functions dwarf_weak_name_offsets() and dwarf_weakname() is owned by the DWARF Access Library (libdwarf, -ldwarf). Portable code should indicate that the memory area can be freed using the dwarf_dealloc(3) function. Different string, different dealloc function β€” iykyk.

πŸ’œ Error Returns πŸ’œ

If argument err is not NULL, these functions will use it to store error information, in case of an error. So if you pass NULL, you're on your own, bestie β€” no error tea for you πŸ“


🌈 RETURN VALUES 🌈

On success, these functions returns DW_DLV_OK. (Yeah, the original says "functions returns" β€” we're keeping the lore.) In case of an error, they return DW_DLV_ERROR and set the argument err. Periodt.


πŸ”₯ ERRORS πŸ”₯

These functions may fail with the following errors β€” vibe check failed, basically:

  • [DW_DLE_ARGUMENT] β€” One of the arguments cu_die_offset, cu_offset, dbg, die_offset, weak, weaks, name, or nweaks was NULL. You handed it a nothing-burger, it's not gonna work πŸ’€
  • [DW_DLE_NO_ENTRY] β€” The DWARF debugging context referenced by argument dbg did not contain information about weak symbols. The tea was simply not there 😭

πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’€ real talk though: don't free the library's memory yourself. Use dwarf_weaks_dealloc(3) for the descriptor array and dwarf_dealloc(3) for the name strings. That's the whole warning, and it's giving "respect the ownership boundaries."

okay that's the whole page, bestie, you ate it up 🫢 this little icon came from Debian, dated April 10, 2011 β€” like, vintage but still iconic βœ¨πŸŽ€

πŸ“¦ where this page comes from