Search code examples
androidclibcandroid-debugbionic

What is __LIBC_HIDDEN__ in C header?


Introduction

In a log output of a crash, there is an error with backtrace output as:

#00 pc 00038cf0  /apex/com.android.runtime/lib/bionic/libc.so (__futex_wait_ex(void volatile*, bool, int, bool, timespec const*)+100)

I went to search for this file and is available in the link below: https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/private/bionic_futex.h


Code

In this file there is the declaration of function **__futex_wait_ex **as:

static inline int __futex_wait_ex(volatile void* ftx, bool shared, int value) {
  return __futex(ftx, (shared ? FUTEX_WAIT_BITSET : FUTEX_WAIT_BITSET_PRIVATE), value, nullptr,
                 FUTEX_BITSET_MATCH_ANY);
}
__LIBC_HIDDEN__ int __futex_wait_ex(volatile void* ftx, bool shared, int value,
                                    bool use_realtime_clock, const timespec* abs_timeout);

Question

What LIBC_HIDDEN does?

I seached in the internet some explanations but could not find an straight answer. I was hopping that was a pattern used in my places so it would be easy to find.


Solution

  • It's a macro which is defined in https://android.googlesource.com/platform/bionic/+/a818445/libc/include/sys/cdefs.h

    as

    /* Used to tag non-static symbols that are private and never exposed by the shared library. */
    #define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
    

    Basically it means that you can not use functions marked as LIBC_HIDDEN outside of the shared library they are implemented in.