Bug #8569


problem with inline functions in abd.h

Added by Andriy Gapon almost 5 years ago. Updated almost 5 years ago.

zfs - Zettabyte File System
Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


C [C99] has peculiar rules for inline functions that are different from the C++ rules.
Unlike C++ where inline is "fire and forget", in C a programmer must pay attention to the function's storage class / visibility.
The main problem is with the case where a compiler decides to not inline a call to the function declared as inline.
Some relevant links:
The summary is that either the inline functions should be declared 'static inline' or one of the compilation units (.c files) must provide a callable externally visible function definition.
In the former case, the compiler would automatically create a local non-inlined function instance in every compilation unit where it's needed.
In the latter case the single external definition is used to satisfy any non-inlined calls in all compilation units.

As things stand right now, we can get an undefined reference error under certain combinations of compilers and compiler options.
For example, this is what I get on FreeBSD when compiling with clang 4.0.0 and -O1:

In function `abd_free':
/usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/abd.c:385: undefined reference to `abd_is_linear'

So, there are two alternatives. Either to qualify each inline function in abd.h with static storage class.
Or to add declarations like the following to abd.c:

extern inline boolean_t abd_is_linear(abd_t *abd);

Both work. I am not sure which one would be more consistent with the illumos development rules.

Actions #1

Updated by Andriy Gapon almost 5 years ago

I see that the illumos code in general has a great deal of static inline functions in header files.
The ZFS code has a few instances of the naked inline in a header file and a matching extern inline in a C file (e.g. zap_f_phys, zap_m_phys, dmu_buf_init_user).

Actions #2

Updated by Gordon Ross almost 5 years ago

Your 2nd way (put "extern inline ..." in abd.c) has the advantage of predictability about where the externally visible symbol will be instantiated. I find that preferable.

Actions #3

Updated by Andriy Gapon almost 5 years ago

Submitted a pull request with the change:

Actions #4

Updated by Electric Monk almost 5 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit 37e84ab74e939caf52150fc3352081786ecc0c29

commit  37e84ab74e939caf52150fc3352081786ecc0c29
Author: Andriy Gapon <>
Date:   2017-08-31T05:29:47.000Z

    8569 problem with inline functions in abd.h
    Reviewed by: Matt Ahrens <>
    Approved by: Robert Mustacchi <>


Also available in: Atom PDF