dpkg-buildflags.1 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. .TH dpkg\-buildflags 1 "2011-09-13" "Debian Project" "dpkg suite"
  2. .SH NAME
  3. dpkg\-buildflags \- returns build flags to use during package build
  4. .
  5. .SH SYNOPSIS
  6. .B dpkg\-buildflags
  7. .RI [ option "...] [" command ]
  8. .
  9. .SH DESCRIPTION
  10. \fBdpkg\-buildflags\fP is a tool to retrieve compilation flags to use during
  11. build of Debian packages.
  12. .
  13. The default flags are defined by the vendor but they can be
  14. extended/overriden in several ways:
  15. .IP 1.
  16. system-wide with \fB/etc/dpkg/buildflags.conf\fP;
  17. .IP 2.
  18. for the current user with \fB$XDG_CONFIG_HOME/dpkg/buildflags.conf\fP
  19. where \fB$XDG_CONFIG_HOME\fP defaults to \fB$HOME/.config\fP;
  20. .IP 3.
  21. temporarily by the user with environment variables (see section
  22. \fBENVIRONMENT\fP);
  23. .IP 4.
  24. dynamically by the package maintainer with environment variables set via
  25. \fBdebian/rules\fP (see section \fBENVIRONMENT\fP).
  26. .P
  27. The configuration files can contain two types of directives:
  28. .TP
  29. .BI SET " flag value"
  30. Override the flag named \fIflag\fP to have the value \fIvalue\fP.
  31. .TP
  32. .BI STRIP " flag value"
  33. Strip from the flag named \fIflag\fP all the build flags listed in \fIvalue\fP.
  34. .TP
  35. .BI APPEND " flag value"
  36. Extend the flag named \fIflag\fP by appending the options given in \fIvalue\fP.
  37. A space is prepended to the appended value if the flag's current value is non-empty.
  38. .TP
  39. .BI PREPEND " flag value"
  40. Extend the flag named \fIflag\fP by prepending the options given in \fIvalue\fP.
  41. A space is appended to the prepended value if the flag's current value is non-empty.
  42. .P
  43. The configuration files can contain comments on lines starting with a hash
  44. (#). Empty lines are also ignored.
  45. .SH COMMANDS
  46. .TP
  47. .BI \-\-dump
  48. Print to standard output all compilation flags and their values. It prints
  49. one flag per line separated from its value by an equal sign
  50. ("\fIflag\fP=\fIvalue\fP"). This is the default action.
  51. .TP
  52. .BI \-\-list
  53. Print the list of flags supported by the current vendor
  54. (one per line). See the \fBSUPPORTED FLAGS\fP section for more
  55. information about them.
  56. .TP
  57. .BI \-\-export= format
  58. Print to standard output shell (if \fIformat\fP is \fBsh\fP) or make
  59. (if \fIformat\fP is \fBmake\fP) commands that can be used to export
  60. all the compilation flags in the environment. If \fIformat\fP is
  61. \fBconfigure\fP then the output can be used on a \fB./configure\fP
  62. command-line. If the \fIformat\fP value is not
  63. given, \fBsh\fP is assumed. Only compilation flags starting with an
  64. upper case character are included, others are assumed to not be suitable
  65. for the environment.
  66. .TP
  67. .BI \-\-get " flag"
  68. Print the value of the flag on standard output. Exits with 0
  69. if the flag is known otherwise exits with 1.
  70. .TP
  71. .BI \-\-origin " flag"
  72. Print the origin of the value that is returned by \fB\-\-get\fP. Exits
  73. with 0 if the flag is known otherwise exits with 1. The origin can be one
  74. of the following values:
  75. .RS
  76. .TP
  77. .B vendor
  78. the original flag set by the vendor is returned;
  79. .TP
  80. .B system
  81. the flag is set/modified by a system-wide configuration;
  82. .TP
  83. .B user
  84. the flag is set/modified by a user-specific configuration;
  85. .TP
  86. .B env
  87. the flag is set/modified by an environment-specific configuration.
  88. .RE
  89. .TP
  90. .B \-\-help
  91. Show the usage message and exit.
  92. .TP
  93. .B \-\-version
  94. Show the version and exit.
  95. .
  96. .SH SUPPORTED FLAGS
  97. .TP
  98. .B CFLAGS
  99. Options for the C compiler. The default value set by the vendor
  100. includes \fI\-g\fP and the default optimization level (\fI\-O2\fP usually,
  101. or \fI\-O0\fP if the \fBDEB_BUILD_OPTIONS\fP environment variable defines
  102. \fInoopt\fP).
  103. .TP
  104. .B CPPFLAGS
  105. Options for the C preprocessor. Default value: empty.
  106. .TP
  107. .B CXXFLAGS
  108. Options for the C++ compiler. Same as \fBCFLAGS\fP.
  109. .TP
  110. .B FFLAGS
  111. Options for the Fortran compiler. Same as \fBCFLAGS\fP.
  112. .TP
  113. .B LDFLAGS
  114. Options passed to the compiler when linking executables or shared
  115. objects (if the linker is called directly, then
  116. .B \-Wl
  117. and
  118. .B ,
  119. have to be stripped from these options). Default value: empty.
  120. .
  121. .SH FILES
  122. .TP
  123. .B /etc/dpkg/buildflags.conf
  124. System wide configuration file.
  125. .TP
  126. .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " $HOME/.config/dpkg/buildflags.conf
  127. User configuration file.
  128. .SH ENVIRONMENT
  129. There are 2 sets of environment variables doing the same operations, the
  130. first one (DEB_\fIflag\fP_\fIop\fP) should never be used within
  131. \fBdebian/rules\fP. It's meant for any user that wants to rebuild the
  132. source package with different build flags. The second set
  133. (DEB_\fIflag\fP_MAINT_\fIop\fP) should only be used in \fBdebian/rules\fP
  134. by package maintainers to change the resulting build flags.
  135. .TP
  136. .BI DEB_ flag _SET
  137. .TQ
  138. .BI DEB_ flag _MAINT_SET
  139. This variable can be used to force the value returned for the given
  140. \fIflag\fP.
  141. .TP
  142. .BI DEB_ flag _STRIP
  143. .TQ
  144. .BI DEB_ flag _MAINT_STRIP
  145. This variable can be used to provide a space separated list of options
  146. that will be stripped from the set of flags returned for the given
  147. \fIflag\fP.
  148. .TP
  149. .BI DEB_ flag _APPEND
  150. .TQ
  151. .BI DEB_ flag _MAINT_APPEND
  152. This variable can be used to append supplementary options to the value
  153. returned for the given \fIflag\fP.
  154. .TP
  155. .BI DEB_ flag _PREPEND
  156. .TQ
  157. .BI DEB_ flag _MAINT_PREPEND
  158. This variable can be used to prepend supplementary options to the value
  159. returned for the given \fIflag\fP.
  160. .TP
  161. .B DEB_BUILD_MAINT_OPTIONS
  162. This variable can be used to disable/enable various hardening build
  163. flags through the \fBhardening\fP option. See the \fBHARDENING\fP section
  164. for details.
  165. .
  166. .SH HARDENING
  167. Several compile-time options (detailed below) can be used to help harden
  168. a resulting binary against memory corruption attacks, or provide
  169. additional warning messages during compilation. Except as noted below,
  170. these are enabled by default for architectures that support them.
  171. .P
  172. Each hardening feature can be enabled and disabled in the
  173. \fBDEB_BUILD_MAINT_OPTIONS\fP environment variable's \fBhardening\fP
  174. value with the "+" and "\-" modifier. For example, to enable the
  175. "pie" feature and disable the "fortify" feature you can do this
  176. in \fBdebian/rules\fP:
  177. .P
  178. export DEB_BUILD_MAINT_OPTIONS=hardening=+pie,\-fortify
  179. .P
  180. The special feature \fBall\fP can be used to enable or disable all
  181. hardening features at the same time. Thus disabling everything and
  182. enabling only "format" and "fortify" can be achieved with:
  183. .P
  184. export DEB_BUILD_MAINT_OPTIONS=hardening=\-all,+format,+fortify
  185. .
  186. .TP
  187. .B format
  188. This setting (enabled by default) adds
  189. .B \-Wformat \-Wformat\-security \-Werror=format\-security
  190. to \fBCFLAGS\fP and \fBCXXFLAGS\fP. This will warn about improper format
  191. string uses, and will fail when format functions are used in a way that
  192. that represent possible security problems. At present, this warns about
  193. calls to \fBprintf\fP and \fBscanf\fP functions where the format string is
  194. not a string literal and there are no format arguments, as in
  195. \fBprintf(foo);\fP instead of \fPprintf("%s", foo);\fP
  196. This may be a security hole if the format string came from untrusted
  197. input and contains "%n".
  198. .
  199. .TP
  200. .B fortify
  201. This setting (enabled by default) adds
  202. .B \-D_FORTIFY_SOURCE=2
  203. to \fBCFLAGS\fP and \fBCXXFLAGS\fP. During code generation the compiler
  204. knows a great deal of information about buffer sizes (where possible), and
  205. attempts to replace insecure unlimited length buffer function calls with
  206. length-limited ones. This is especially useful for old, crufty code.
  207. Additionally, format strings in writable memory that contain '%n' are
  208. blocked. If an application depends on such a format string, it will need
  209. to be worked around.
  210. Note that for this option to have any effect, the source must also
  211. be compiled with \fB\-O1\fP or higher.
  212. .TP
  213. .B stackprotector
  214. This setting (enabled by default) adds
  215. .B \-fstack-protector \-\-param=ssp\-buffer\-size=4
  216. to \fBCFLAGS\fP and \fBCXXFLAGS\fP. This adds safety checks against stack
  217. overwrites. This renders many potential code injection attacks into
  218. aborting situations. In the best case this turns code injection
  219. vulnerabilities into denial of service or into non-issues (depending on
  220. the application).
  221. This feature requires linking against glibc (or another provider of
  222. \fB__stack_chk_fail\fP), so needs to be disabled when building with
  223. \fB\-nostdlib\fP or \fB\-ffreestanding\fP or similar.
  224. .
  225. .TP
  226. .B relro
  227. This setting (enabled by default) adds
  228. .B \-Wl,\-z,relro
  229. to \fBLDFLAGS\fP. During program load, several ELF memory sections need
  230. to be written to by the linker. This flags the loader to turn these
  231. sections read-only before turning over control to the program. Most
  232. notably this prevents GOT overwrite attacks.
  233. .
  234. .TP
  235. .B bindnow
  236. This setting (disabled by default) adds
  237. .B \-Wl,\-z,now
  238. to \fBLDFLAGS\fP. During program load, all dynamic symbols are resolved,
  239. allowing for the entire PLT to be marked read-only (due to \fBrelro\fP
  240. above).
  241. .
  242. .TP
  243. .B pie
  244. This setting (disabled by default) adds \fB\-fPIE\fP to \fBCFLAGS\fP and
  245. \fBCXXFLAGS\fP, and \fB\-fPIE \-pie\fP to \fBLDFLAGS\fP. Position Independent
  246. Executable are needed to take advantage of Address Space Layout
  247. Randomization, supported by some kernel versions. While ASLR can already
  248. be enforced for data areas in the stack and heap (brk and mmap), the code
  249. areas must be compiled as position-independent. Shared libraries already
  250. do this (\-fPIC), so they gain ASLR automatically, but binary .text
  251. regions need to be build PIE to gain ASLR. When this happens, ROP (Return
  252. Oriented Programming) attacks are much harder since there are no static
  253. locations to bounce off of during a memory corruption attack.
  254. This is not compatible with \fB\-fPIC\fP so care must be taken when
  255. building shared objects.
  256. Additionally, since PIE is implemented via a general register, some
  257. architectures (most notably i386) can see performance losses of up to
  258. 15% in very text-segment-heavy application workloads; most workloads
  259. see less than 1%. Architectures with more general registers (e.g. amd64)
  260. do not see as high a worst-case penalty.
  261. .
  262. .SH AUTHOR
  263. Copyright \(co 2010-2011 Rapha\[:e]l Hertzog
  264. .sp
  265. Copyright \(co 2011 Kees Cook
  266. .sp
  267. This is free software; see the GNU General Public Licence version 2 or
  268. later for copying conditions. There is NO WARRANTY.