Bug #4555

macro side-effects with /usr/include/libelf.h

Added by Richard PALO almost 7 years ago. Updated over 6 years ago.

lib - userland libraries
Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


libelf.h contains the following snippet:

#undef _
#ifdef __STDC__
typedef void        Elf_Void;
#define _(a)        a
typedef char        Elf_Void;
#define _(a)        ()
#undef const
#define const

(at the end, '_' is #undef'd)

This causes interference with other programs defining the macro '_', for example for NLS purposes. 'const' is may also be redefined...

A possible solution is to use #pragma push_macro/pop_macro but that would seemingly restrict builds to gcc>=4.4 and recent clang.

BTW, a current workaround is to put #pragma push_macro("_") and pop_macro("_")
around #include <gelf.h> or #include <libelf.h> statements.

Other ELF distros defining libelf.h don't have this problem.



Updated by Richard PALO almost 7 years ago


Updated by Richard PALO almost 7 years ago

After reviewing the manner other illumos components avoided the above side-effects,
the attached patch seems appropriate.


Updated by Andrew Stormont almost 7 years ago

Patch looks good to me. Feel free to count me as a reviewer.


Updated by Igor Pashev almost 7 years ago

Why not just remove support for pre-ANSI C with those macros ?


Updated by Richard PALO almost 7 years ago

As the prevalent opinion was to drop the non STDC stuff, attached is a reworked patch.

I've so far done a successful incremental, and am proceeding to pull and rebase illumos-gate for a full build.


Updated by Richard PALO almost 7 years ago

no time like the present to relook, making libelf.h cstyle clean.
Another go...


Updated by Dan McDonald over 6 years ago

  • Status changed from New to Resolved

See update from the git robot.


Updated by Electric Monk over 6 years ago

git commit 7a3fc0ccaf807a654980fdce2d9187503628b99d

Author: Richard PALO <>

4555 macro side-effects with /usr/include/libelf.h
Reviewed by: Richard Lowe <>
Reviewed by: Andy Stormont <>
Reviewed by: Igor Pashev <>
Approved by: Dan McDonald <>


Updated by Yuri Pankov over 6 years ago

  • Category set to lib - userland libraries
  • Assignee set to Richard PALO
  • % Done changed from 0 to 100
  • Tags deleted (needs-triage)

Also available in: Atom PDF