missing_syscall: when adding syscall replacements, use different names (#8229)

In meson.build we check that functions are available using:
    meson.get_compiler('c').has_function('foo')
which checks the following:
- if __stub_foo or __stub___foo are defined, return false
- if foo is declared (a pointer to the function can be taken), return true
- otherwise check for __builtin_memfd_create

_stub is documented by glibc as
   It defines a symbol '__stub_FUNCTION' for each function
   in the C library which is a stub, meaning it will fail
   every time called, usually setting errno to ENOSYS.

So if __stub is defined, we know we don't want to use the glibc version, but
this doesn't tell us if the name itself is defined or not. If it _is_ defined,
and we define our replacement as an inline static function, we get an error:

In file included from ../src/basic/missing.h:1358:0,
                 from ../src/basic/util.h:47,
                 from ../src/basic/calendarspec.h:29,
                 from ../src/basic/calendarspec.c:34:
../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration
 static inline int memfd_create(const char *name, unsigned int flags) {
                   ^~~~~~~~~~~~
.../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here
 int memfd_create (const char *__name, unsigned int __flags) __THROW;
     ^~~~~~~~~~~~

To avoid this problem, call our inline functions different than glibc,
and use a #define to map the official name to our replacement.

Fixes #8099.

v2:
- use "missing_" as the prefix instead of "_"

v3:
- rebase and update for statx()

  Unfortunately "statx" is also present in "struct statx", so the define
  causes issues. Work around this by using a typedef.

I checked that systemd compiles with current glibc
(glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID,
HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL,
HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0.

Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of
the define, but because of struct file_handle.

(cherry picked from commit 5187dd2c403caf92d09f3491e41f1ceb3f10491f)
1 file changed
tree: 341b36a34f5feb5b2892190e89195645379f9e25
  1. .dir-locals.el
  2. .editorconfig
  3. .gitattributes
  4. .gitignore
  5. .mailmap
  6. .travis.yml
  7. .vimrc
  8. .ycm_extra_conf.py
  9. CODING_STYLE
  10. CONTRIBUTING.md
  11. DISTRO_PORTING
  12. LICENSE.GPL2
  13. LICENSE.LGPL2.1
  14. Makefile-man.am
  15. Makefile.am
  16. NEWS
  17. README
  18. README.md
  19. TODO
  20. autogen.sh
  21. catalog/
  22. coccinelle/
  23. configure.ac
  24. docs/
  25. factory/etc/
  26. hwdb/
  27. m4/
  28. man/
  29. network/
  30. po/
  31. rules/
  32. shell-completion/
  33. src/
  34. sysctl.d/
  35. system-preset/
  36. sysusers.d/
  37. test/
  38. tmpfiles.d/
  39. tools/
  40. units/
  41. xorg/
README.md

systemd - System and Service Manager

Build Status
Coverity Scan Status

Details

General information about systemd can be found in the systemd Wiki.

Information about build requirements are provided in the README file.

Consult our NEWS file for information about what's new in the most recent systemd versions.

Please see our Contribution Guidelines for more information about filing GitHub Issues and posting GitHub Pull Requests.

When preparing patches for systemd, please follow our Coding Style Guidelines.

If you are looking for support, please contact our mailing list or join our IRC channel.