BUILD.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. Building Dinit
  2. =-=-=-=-=-=-=-
  3. Building Dinit should be a straight-forward process. It requires GNU make and a C++11 compiler
  4. (GCC version 4.9 and later, or Clang ~5.0 and later, should be fine)
  5. On the directly supported operating systems - Linux, OpenBSD, FreeBSD and Darwin (macOS) - a
  6. suitable build configuration is provided and should be used automatically. For other systems,
  7. or to fine tune or correct the configuration, create and edit the "mconfig" file (start by
  8. copying one for a particular OS from the "configs" directory) to choose appropriate values for
  9. the configuration variables defined within. In particular:
  10. CXX : should be set to the name of the C++ compiler (and link driver)
  11. CXXOPTS : are options passed to the compiler during compilation (see note for GCC below)
  12. LDFLAGS : are any extra flags required for linking; should not normally be needed
  13. (FreeBSD requires -lrt).
  14. Note that the "eg++" or "clang++" package must be installed on OpenBSD as the default "g++"
  15. compiler is too old. Clang is part of the base system in recent releases.
  16. Then, change into the "src" directory, and run "make" (or "gmake" if the system make is not
  17. GNU make, such as on most BSD systems):
  18. cd src
  19. make
  20. If everything goes smoothly this will build dinit, dinitctl, and optionally the shutdown
  21. utility. Use "make install" to install; you can specify an alternate installation by
  22. setting the "DESTDIR" variable, eg "make DESTDIR=/tmp/temporary-install-path install".
  23. Other configuration variables
  24. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  25. There are a number of other variables you can set in the mconfig file which affect the build:
  26. SBINDIR=...
  27. Where the "/sbin" directory is. Executables will be installed here.
  28. MANDIR=...
  29. Where the "man" directory is. Man pages will be installed here.
  30. SYSCONTROLSOCKET=...
  31. Default full path to the control socket, for when Dinit runs as system service manager.
  32. BUILD_SHUTDOWN=yes|no
  33. Whether to build the "shutdown" (and "halt" etc) utilities. These are only useful
  34. if dinit is the system init (i.e. the PID 1 process). You probably don't want this
  35. unless building for Linux.
  36. USE_UTMPX=1|0
  37. Whether to build support for manipulating the utmp/utmpx database via the related POSIX
  38. functions. If not set to any value, support is enabled for certain systems automatically
  39. and disabled for all others.
  40. SANITIZE_OPTS=...
  41. Any options to enable run-time sanitizers or additional safety checks. This will be used
  42. only when building tests. It can safely be left blank.
  43. Running test suite
  44. =-=-=-=-=-=-=-=-=-
  45. Build the "check" target in order to run the test suite:
  46. make check
  47. The standard mconfig options enable various sanitizers during build of the tests. On Linux you may
  48. see an error such as the following:
  49. make[3]: Leaving directory '/home/davmac/workspace/dinit/src/tests/cptests'
  50. ./tests
  51. ==25332==ERROR: AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes at
  52. address 2008fff7000 (errno: 12)
  53. ==25332==ReserveShadowMemoryRange failed while trying to map 0xdfff0001000 bytes. Perhaps
  54. you're using ulimit -v
  55. make[2]: *** [Makefile:12: run-tests] Aborted
  56. If you get this, either disable the address sanitizer or make sure you have overcommit enabled:
  57. echo 1 > /proc/sys/vm/overcommit_memory
  58. Any test failures will abort the test suite run immediately.
  59. In addition to the standard test suite, there is experimental support for fuzzing the control
  60. protocol handling using LLVM/clang's fuzzer (libFuzzer). Change to the `src/tests/cptests`
  61. directory and build the "fuzz" target:
  62. make fuzz
  63. Then create a "corpus" directory and run the fuzzer:
  64. mkdir corpus
  65. ./fuzz corpus
  66. This will auto-generate test data as it finds input which triggers new execution paths. Check
  67. libFuzzer documentation for further details.
  68. Special note for GCC/Libstdc++
  69. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  70. (Note: the issue discussed here has apparently been resolved in recent GCC versions).
  71. GCC 5.x onwards includes a "dual ABI" in its standard library implementation, aka Libstdc++.
  72. Compiling against the newer (C++11 and later) ABI can be achieved by adding
  73. -D_GLIBCXX_USE_CXX11_ABI=1 to the compiler command line; this uses a non-standard language
  74. extension to differently mangle symbol names in order to link against the new ABI versions.
  75. (Some systems may be configured to build with the new ABI by default, and in that case you
  76. build against the old ABI using D_GLIBCXX_USE_CXX11_ABI=1).
  77. This is problematic for several reasons. First, it prevents linking against the new ABI with
  78. other compilers that do not understand the language extension (LLVM i.e. clang++ does so
  79. in recent versions, so this is perhaps no longer much of a problem in practice). Secondly,
  80. some aspects of library behavior are ABI-dependent but cannot be changed using the ABI
  81. macro; in particular, exceptions thrown as a result of failed I/O operations are, in GCC
  82. versions 5.x and 6.x, always "old ABI" exceptions which cannot be caught by code compiled
  83. against the new ABI, and in GCC version 7.x they are always "new ABI" exceptions which cannot
  84. be caught by code compiled against the old ABI. Since the one library object now supposedly
  85. houses both ABIs, this means that at least one of the two ABIs is always broken.
  86. A blog post describing the dual ABI mechanism can be found here:
  87. https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/
  88. The bug regarding the issue with catching other-ABI exceptions is here:
  89. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145
  90. Since Dinit is affected by this bug, the unfortunate possibility exists to break Dinit by
  91. upgrading GCC. If you have libstdc++ corresponding to GCC 5.x or 6.x, you *must* build with
  92. the old ABI, but Dinit will be broken if you upgrade to GCC 7. If you have libstdc++ from
  93. GCC 7, you *must* build with the new ABI. If the wrong ABI is used, Dinit may still run
  94. successfully but any attempt to load a non-existing service, for example, will cause Dinit
  95. to crash.