.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "dpkg-buildflags 1" .TH dpkg-buildflags 1 2024-08-01 1.22.11 "dpkg suite" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME dpkg\-buildflags \- returns build flags to use during package build .SH SYNOPSIS .IX Header "SYNOPSIS" \&\fBdpkg-buildflags\fR [\fIoption\fR...] [\fIcommand\fR] .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBdpkg-buildflags\fR is a tool to retrieve compilation flags to use during build of Debian packages. .PP The default flags are defined by the vendor but they can be extended/overridden in several ways: .IP 1. 4 system-wide with \fB/etc/dpkg/buildflags.conf\fR; .IP 2. 4 for the current user with \fR\f(CB$XDG_CONFIG_HOME\fR\fB/dpkg/buildflags.conf\fR where \fB\fR\f(CB$XDG_CONFIG_HOME\fR\fB\fR defaults to \fB\fR\f(CB$HOME\fR\fB/.config\fR; .IP 3. 4 temporarily by the user with environment variables (see section "ENVIRONMENT"); .IP 4. 4 dynamically by the package maintainer with environment variables set via \&\fBdebian/rules\fR (see section "ENVIRONMENT"). .PP The configuration files can contain four types of directives: .IP "\fBSET\fR \fIflag\fR \fIvalue\fR" 4 .IX Item "SET flag value" Override the flag named \fIflag\fR to have the value \fIvalue\fR. .IP "\fBSTRIP\fR \fIflag\fR \fIvalue\fR" 4 .IX Item "STRIP flag value" Strip from the flag named \fIflag\fR all the build flags listed in \fIvalue\fR. Since dpkg 1.16.1. .IP "\fBAPPEND\fR \fIflag\fR \fIvalue\fR" 4 .IX Item "APPEND flag value" Extend the flag named \fIflag\fR by appending the options given in \fIvalue\fR. A space is prepended to the appended value if the flag's current value is non-empty. .IP "\fBPREPEND\fR \fIflag\fR \fIvalue\fR" 4 .IX Item "PREPEND flag value" Extend the flag named \fIflag\fR by prepending the options given in \fIvalue\fR. A space is appended to the prepended value if the flag's current value is non-empty. Since dpkg 1.16.1. .PP The configuration files can contain comments on lines starting with a hash (#). Empty lines are also ignored. .PP This program was introduced in dpkg 1.15.7. .SH COMMANDS .IX Header "COMMANDS" .IP \fB\-\-dump\fR 4 .IX Item "--dump" Print to standard output all compilation flags and their values. It prints one flag per line separated from its value by an equal sign (\(lq\fIflag\fR=\fIvalue\fR\(rq). This is the default action. .IP \fB\-\-list\fR 4 .IX Item "--list" Print the list of flags supported by the current vendor (one per line). See the "SUPPORTED FLAGS" section for more information about them. .IP \fB\-\-status\fR 4 .IX Item "--status" Display any information that can be useful to explain the behavior of \&\fBdpkg-buildflags\fR (since dpkg 1.16.5): relevant environment variables, current vendor, state of all feature flags. Also print the resulting compiler flags with their origin. .Sp This is intended to be run from \fBdebian/rules\fR, so that the build log keeps a clear trace of the build flags used. This can be useful to diagnose problems related to them. .IP \fB\-\-export=\fR\fIformat\fR 4 .IX Item "--export=format" Print to standard output commands that can be used to export all the compilation flags for some particular tool. If the \fIformat\fR value is not given, \fBsh\fR is assumed. Only compilation flags starting with an upper case character are included, others are assumed to not be suitable for the environment. Supported formats: .RS 4 .IP \fBsh\fR 4 .IX Item "sh" Shell commands to set and export all the compilation flags in the environment. The flag values are quoted so the output is ready for evaluation by a shell. .IP \fBcmdline\fR 4 .IX Item "cmdline" Arguments to pass to a build program's command line to use all the compilation flags (since dpkg 1.17.0). The flag values are quoted in shell syntax. .IP \fBconfigure\fR 4 .IX Item "configure" This is a legacy alias for \fBcmdline\fR. .IP \fBmake\fR 4 .IX Item "make" Make directives to set and export all the compilation flags in the environment. Output can be written to a Makefile fragment and evaluated using an \fBinclude\fR directive. .RE .RS 4 .RE .IP "\fB\-\-get\fR \fIflag\fR" 4 .IX Item "--get flag" Print the value of the flag on standard output. Exits with 0 if the flag is known otherwise exits with 1. .IP "\fB\-\-origin\fR \fIflag\fR" 4 .IX Item "--origin flag" Print the origin of the value that is returned by \fB\-\-get\fR. Exits with 0 if the flag is known otherwise exits with 1. The origin can be one of the following values: .RS 4 .IP \fBvendor\fR 4 .IX Item "vendor" the original flag set by the vendor is returned; .IP \fBsystem\fR 4 .IX Item "system" the flag is set/modified by a system-wide configuration; .IP \fBuser\fR 4 .IX Item "user" the flag is set/modified by a user-specific configuration; .IP \fBenv\fR 4 .IX Item "env" the flag is set/modified by an environment-specific configuration. .RE .RS 4 .RE .IP \fB\-\-query\fR 4 .IX Item "--query" Print any information that can be useful to explain the behavior of the program: current vendor, relevant environment variables, feature areas, state of all feature flags, whether a feature is handled as a builtin default by the compiler (since dpkg 1.21.14), and the compiler flags with their origin (since dpkg 1.19.0). .Sp For example: .Sp .Vb 3 \& Vendor: Debian \& Environment: \& DEB_CFLAGS_SET=\-O0 \-Wall \& \& Area: qa \& Features: \& bug=no \& canary=no \& Builtins: \& \& Area: hardening \& Features: \& pie=no \& Builtins: \& pie=yes \& \& Area: reproducible \& Features: \& timeless=no \& Builtins: \& \& Flag: CFLAGS \& Value: \-O0 \-Wall \& Origin: env \& \& Flag: CPPFLAGS \& Value: \-D_FORTIFY_SOURCE=2 \& Origin: vendor .Ve .IP "\fB\-\-query\-features\fR \fIarea\fR" 4 .IX Item "--query-features area" Print the features enabled for a given area (since dpkg 1.16.2). If the feature is handled (even if only on some architectures) as a builtin default by the compiler, then a \fBBuiltin\fR field is printed (since dpkg 1.21.14). See the "FEATURE AREAS" section for more details about the currently recognized areas. Exits with 0 if the area is known otherwise exits with 1. .Sp The output is in RFC822 format, with one section per feature. For example: .Sp .Vb 3 \& Feature: pie \& Enabled: yes \& Builtin: yes \& \& Feature: stackprotector \& Enabled: yes .Ve .IP \fB\-\-help\fR 4 .IX Item "--help" Show the usage message and exit. .IP \fB\-\-version\fR 4 .IX Item "--version" Show the version and exit. .SH "SUPPORTED FLAGS" .IX Header "SUPPORTED FLAGS" .IP \fBASFLAGS\fR 4 .IX Item "ASFLAGS" Options for the host assembler. Default value: empty. Since dpkg 1.21.0. .IP \fBCFLAGS\fR 4 .IX Item "CFLAGS" Options for the host C compiler. The default value set by the vendor includes \fB\-g\fR and the default optimization level (\fB\-O2\fR usually, or \fB\-O0\fR if the \fBDEB_BUILD_OPTIONS\fR environment variable defines \&\fInoopt\fR). .IP \fBCPPFLAGS\fR 4 .IX Item "CPPFLAGS" Options for the host C preprocessor. Default value: empty. .IP \fBCXXFLAGS\fR 4 .IX Item "CXXFLAGS" Options for the host C++ compiler. Same as \fBCFLAGS\fR. .IP \fBOBJCFLAGS\fR 4 .IX Item "OBJCFLAGS" Options for the host Objective C compiler. Same as \fBCFLAGS\fR. Since dpkg 1.17.7. .IP \fBOBJCXXFLAGS\fR 4 .IX Item "OBJCXXFLAGS" Options for the host Objective C++ compiler. Same as \fBCXXFLAGS\fR. Since dpkg 1.17.7. .IP \fBDFLAGS\fR 4 .IX Item "DFLAGS" Options for the host D compiler (ldc or gdc). Since dpkg 1.20.6. .IP \fBFFLAGS\fR 4 .IX Item "FFLAGS" Options for the host Fortran 77 compiler. A subset of \fBCFLAGS\fR. .IP \fBFCFLAGS\fR 4 .IX Item "FCFLAGS" Options for the host Fortran 9x compiler. Same as \fBFFLAGS\fR. Since dpkg 1.17.7. .IP \fBLDFLAGS\fR 4 .IX Item "LDFLAGS" Options passed to the host compiler when linking executables or shared objects (if the linker is called directly, then \&\fB\-Wl\fR and \&\fB,\fR have to be stripped from these options). Default value: empty. .IP \fBASFLAGS_FOR_BUILD\fR 4 .IX Item "ASFLAGS_FOR_BUILD" Options for the build assembler. Default value: empty. Since dpkg 1.22.1. .IP \fBCFLAGS_FOR_BUILD\fR 4 .IX Item "CFLAGS_FOR_BUILD" Options for the build C compiler. The default value set by the vendor includes \fB\-g\fR and the default optimization level (\fB\-O2\fR usually, or \fB\-O0\fR if the \fBDEB_BUILD_OPTIONS\fR environment variable defines \fInoopt\fR). Since dpkg 1.22.1. .IP \fBCPPFLAGS_FOR_BUILD\fR 4 .IX Item "CPPFLAGS_FOR_BUILD" Options for the build C preprocessor. Default value: empty. Since dpkg 1.22.1. .IP \fBCXXFLAGS_FOR_BUILD\fR 4 .IX Item "CXXFLAGS_FOR_BUILD" Options for the build C++ compiler. Same as \fBCFLAGS_FOR_BUILD\fR. Since dpkg 1.22.1. .IP \fBOBJCFLAGS_FOR_BUILD\fR 4 .IX Item "OBJCFLAGS_FOR_BUILD" Options for the build Objective C compiler. Same as \fBCFLAGS_FOR_BUILD\fR. Since dpkg 1.22.1. .IP \fBOBJCXXFLAGS_FOR_BUILD\fR 4 .IX Item "OBJCXXFLAGS_FOR_BUILD" Options for the build Objective C++ compiler. Same as \fBCXXFLAGS_FOR_BUILD\fR. Since dpkg 1.22.1. .IP \fBDFLAGS_FOR_BUILD\fR 4 .IX Item "DFLAGS_FOR_BUILD" Options for the build D compiler (ldc or gdc). Since dpkg 1.22.1. .IP \fBFFLAGS_FOR_BUILD\fR 4 .IX Item "FFLAGS_FOR_BUILD" Options for the build Fortran 77 compiler. A subset of \fBCFLAGS_FOR_BUILD\fR. Since dpkg 1.22.1. .IP \fBFCFLAGS_FOR_BUILD\fR 4 .IX Item "FCFLAGS_FOR_BUILD" Options for the build Fortran 9x compiler. Same as \fBFFLAGS_FOR_BUILD\fR. Since dpkg 1.22.1. .IP \fBLDFLAGS_FOR_BUILD\fR 4 .IX Item "LDFLAGS_FOR_BUILD" Options passed to the build compiler when linking executables or shared objects (if the linker is called directly, then \fB\-Wl\fR and \fB,\fR have to be stripped from these options). Default value: empty. Since dpkg 1.22.1. .PP New flags might be added in the future if the need arises (for example to support other languages). .SH "FEATURE AREAS" .IX Header "FEATURE AREAS" Feature areas are currently vendor specific, and the ones described below are only recognized on Debian and derivatives. .PP Each area feature can be enabled and disabled in the \fBDEB_BUILD_OPTIONS\fR and \fBDEB_BUILD_MAINT_OPTIONS\fR environment variable's area value with the \(oq\fB+\fR\(cq and \(oq\fB\-\fR\(cq modifier. Following the general syntax of these variables (described in \fBdpkg\-buildpackage\fR\|(1)), multiple feature areas can be specified separated by spaces, where each get feature specifiers as mandatory parameters after an equal sign (\(oq\fB=\fR\(cq). The feature specifiers are comma-separated and parsed from left to right, where the settings within the same feature specifier override previous ones, even if the feature specifiers are split across multiple space-separated feature area settings for the same area. .PP For example, to enable the \fBhardening\fR \(lqpie\(rq feature and disable the \(lqfortify\(rq feature you can do this in \fBdebian/rules\fR: .PP .Vb 1 \& export DEB_BUILD_MAINT_OPTIONS = hardening=+pie,\-fortify .Ve .PP The special feature \fBall\fR (valid in any area) can be used to enable or disable all area features at the same time. Thus disabling everything in the \fBhardening\fR area and enabling only \(lqformat\(rq and \(lqfortify\(rq can be achieved with: .PP .Vb 1 \& export DEB_BUILD_MAINT_OPTIONS = hardening=\-all,+format,+fortify .Ve .PP Multiple feature areas can be set: .PP .Vb 1 \& export DEB_BUILD_MAINT_OPTIONS = hardening=+pie abi=+lfs .Ve .PP The override behavior applies as much to the \fBall\fR special feature, as to specific features, which should allow for composition. Thus to enable \(lqlfs\(rq in the \fBabi\fR area, and only \(lqpie\(rq and \(lqfortify\(rq in the \fBhardening\fR area, but \(lqformat\(rq only when CONDITION is defined, this could be done with: .PP .Vb 6 \& export DEB_BUILD_MAINT_OPTIONS = hardening=\-all,+pie,+format abi=+lfs \& … \& DEB_BUILD_MAINT_OPTIONS += hardening=+fortify \& ifdef CONDITION \& DEB_BUILD_MAINT_OPTIONS += hardening=\-format \& endif .Ve .SS abi .IX Subsection "abi" Several compile-time options (detailed below) can be used to enable features that can change the ABI of a package, but cannot be enabled by default due to backwards compatibility reasons unless coordinated or checked individually. .IP \fBlfs\fR 4 .IX Item "lfs" This setting (since dpkg 1.22.0; disabled by default) enables Large File Support on 32\-bit architectures where their ABI does not include LFS by default, by adding \&\fB\-D_LARGEFILE_SOURCE \-D_FILE_OFFSET_BITS=64\fR to \fBCPPFLAGS\fR. .Sp When this feature is enabled it will override the value from the same feature in the \fBfuture\fR feature area. .IP \fBtime64\fR 4 .IX Item "time64" This setting (since dpkg 1.22.0; enabled by default except for i386, hurd\-i386 and kfreebsd\-i386 since dpkg 1.22.5) enables 64\-bit time_t support on 32\-bit architectures where their ABI does not include it by default, by adding \fB\-D_TIME_BITS=64\fR to \fBCPPFLAGS\fR. This setting automatically enables the \fBlfs\fR feature from the \fBabi\fR feature area. .Sp If the setting is enabled explicitly then it gets enabled on all architectures including i386 but not hurd\-i386 nor kfreebsd\-i386 (where the kernel does not have time64 interfaces), ignoring the binary backwards compatibility default. .Sp It is also enabled by default by gcc on the armel, armhf, hppa, m68k, mips, mipsel, powerpc and sh4 Debian architectures, where disabling the feature will add instead \&\fB\-U_LARGEFILE_SOURCE \-U_FILE_OFFSET_BITS \-U_TIME_BITS\fR to \fBCPPFLAGS\fR. .SS future .IX Subsection "future" Several compile-time options (detailed below) can be used to enable features that should be enabled by default, but cannot due to backwards compatibility reasons. .IP \fBlfs\fR 4 .IX Item "lfs" This setting (since dpkg 1.19.0; disabled by default) is now an alias for the \fBlfs\fR feature in the \fBabi\fR area, use that instead. The feature from the \fBabi\fR area overrides this setting. .SS qa .IX Subsection "qa" Several compile-time options (detailed below) can be used to help detect problems in the source code or build system. .IP \fBbug-implicit-func\fR 4 .IX Item "bug-implicit-func" This setting (since dpkg 1.22.3; enabled by default since dpkg 1.22.6) adds \&\fB\-Werror=implicit\-function\-declaration\fR to \fBCFLAGS\fR. .IP \fBbug\fR 4 .IX Item "bug" This setting (since dpkg 1.17.4; disabled by default) adds any warning option that reliably detects problematic source code. The warnings are fatal. The only currently supported flags are \fBCFLAGS\fR and \fBCXXFLAGS\fR with flags set to \fB\-Werror=array\-bounds\fR, \fB\-Werror=clobbered\fR, \&\fB\-Werror=implicit\-function\-declaration\fR and \&\fB\-Werror=volatile\-register\-var\fR. .Sp This feature handles \fB\-Werror=implicit\-function\-declaration\fR via the \fBbug-implicit-func\fR feature, if that has not been specified. .IP \fBcanary\fR 4 .IX Item "canary" This setting (since dpkg 1.17.14; disabled by default) adds dummy canary options to the build flags, so that the build logs can be checked for how the build flags propagate and to allow finding any omission of normal build flag settings. The only currently supported flags are \fBCPPFLAGS\fR, \fBCFLAGS\fR, \&\fBOBJCFLAGS\fR, \fBCXXFLAGS\fR and \fBOBJCXXFLAGS\fR with flags set to \fB\-D_\|_DEB_CANARY_\fR\fIflag\fR_\fIrandom-id\fR\fB_\|_\fR, and \&\fBLDFLAGS\fR set to \fB\-Wl,\-z,deb\-canary\-\fR\fIrandom-id\fR. .SS optimize .IX Subsection "optimize" Several compile-time options (detailed below) can be used to help optimize a resulting binary (since dpkg 1.21.0). \&\fBNote\fR: Enabling \fBall\fR these options can result in unreproducible binary artifacts. .IP \fBlto\fR 4 .IX Item "lto" This setting (since dpkg 1.21.0; disabled by default) enables Link Time Optimization by adding \fB\-flto=auto \-ffat\-lto\-objects\fR to \&\fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR, \fBFCFLAGS\fR and \fBLDFLAGS\fR. .SS sanitize .IX Subsection "sanitize" Several compile-time options (detailed below) can be used to help sanitize a resulting binary against memory corruptions, memory leaks, use after free, threading data races and undefined behavior bugs. \&\fBNote\fR: These options should \fBnot\fR be used for production builds as they can reduce reliability for conformant code, reduce security or even functionality. .IP \fBaddress\fR 4 .IX Item "address" This setting (since dpkg 1.18.0; disabled by default) adds \&\fB\-fsanitize=address\fR to \&\fBLDFLAGS\fR and \fB\-fsanitize=address \-fno\-omit\-frame\-pointer\fR to \&\fBCFLAGS\fR and \fBCXXFLAGS\fR. .IP \fBthread\fR 4 .IX Item "thread" This setting (since dpkg 1.18.0; disabled by default) adds \&\fB\-fsanitize=thread\fR to \&\fBCFLAGS\fR, \fBCXXFLAGS\fR and \fBLDFLAGS\fR. .IP \fBleak\fR 4 .IX Item "leak" This setting (since dpkg 1.18.0; disabled by default) adds \&\fB\-fsanitize=leak\fR to \&\fBLDFLAGS\fR. It gets automatically disabled if either the \fBaddress\fR or the \fBthread\fR features are enabled, as they imply it. .IP \fBundefined\fR 4 .IX Item "undefined" This setting (since dpkg 1.18.0; disabled by default) adds \&\fB\-fsanitize=undefined\fR to \&\fBCFLAGS\fR, \fBCXXFLAGS\fR and \fBLDFLAGS\fR. .SS hardening .IX Subsection "hardening" Several compile-time options (detailed below) can be used to help harden a resulting binary against memory corruption attacks, or provide additional warning messages during compilation. Except as noted below, these are enabled by default for architectures that support them. .IP \fBformat\fR 4 .IX Item "format" This setting (since dpkg 1.16.1; enabled by default) adds \&\fB\-Wformat \-Werror=format\-security\fR to \fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR and \fBOBJCXXFLAGS\fR. This will warn about improper format string uses, and will fail when format functions are used in a way that represent possible security problems. At present, this warns about calls to \fBprintf\fR and \fBscanf\fR functions where the format string is not a string literal and there are no format arguments, as in \&\fBprintf(foo);\fR instead of \fBprintf("%s", foo);\fR This may be a security hole if the format string came from untrusted input and contains \(oq%n\(cq. .IP \fBfortify\fR 4 .IX Item "fortify" This setting (since dpkg 1.16.1; enabled by default) adds \&\fB\-D_FORTIFY_SOURCE=2\fR to \fBCPPFLAGS\fR. During code generation the compiler knows a great deal of information about buffer sizes (where possible), and attempts to replace insecure unlimited length buffer function calls with length-limited ones. This is especially useful for old, crufty code. Additionally, format strings in writable memory that contain \(oq%n\(cq are blocked. If an application depends on such a format string, it will need to be worked around. .Sp Note that for this option to have any effect, the source must also be compiled with \fB\-O1\fR or higher. If the environment variable \&\fBDEB_BUILD_OPTIONS\fR contains \fInoopt\fR, then \fBfortify\fR support will be disabled, due to new warnings being issued by glibc 2.16 and later. .IP \fBstackprotector\fR 4 .IX Item "stackprotector" This setting (since dpkg 1.16.1; enabled by default if stackprotectorstrong is not in use) adds \fB\-fstack\-protector \-\-param=ssp\-buffer\-size=4\fR to \fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR. This adds safety checks against stack overwrites. This renders many potential code injection attacks into aborting situations. In the best case this turns code injection vulnerabilities into denial of service or into non-issues (depending on the application). .Sp This feature requires linking against glibc (or another provider of \&\fB_\|_stack_chk_fail\fR), so needs to be disabled when building with \&\fB\-nostdlib\fR or \fB\-ffreestanding\fR or similar. .IP \fBstackprotectorstrong\fR 4 .IX Item "stackprotectorstrong" This setting (since dpkg 1.17.11; enabled by default) adds \&\fB\-fstack\-protector\-strong\fR to \fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR. This is a stronger variant of \fBstackprotector\fR, but without significant performance penalties. .Sp Disabling \fBstackprotector\fR will also disable this setting. .Sp This feature has the same requirements as \fBstackprotector\fR, and in addition also requires gcc 4.9 and later. .IP \fBstackclash\fR 4 .IX Item "stackclash" This setting (since dpkg 1.22.0; enabled by default) adds \&\fB\-fstack\-clash\-protection\fR on \fBamd64\fR, \fBarm64\fR, \fBarmhf\fR and \fBarmel\fR to \&\fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR. This adds code to prevent stack clash style attacks. .IP \fBbranch\fR 4 .IX Item "branch" This setting (since dpkg 1.22.0; enabled by default) adds \fB\-fcf\-protection\fR on \fBamd64\fR and \fB\-mbranch\-protection=standard\fR on \fBarm64\fR to \&\fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR. This adds branch protection to indirect calls, jumps and returns to check whether these are valid at run-time. .IP \fBrelro\fR 4 .IX Item "relro" This setting (since dpkg 1.16.1; enabled by default) adds \&\fB\-Wl,\-z,relro\fR to \fBLDFLAGS\fR. During program load, several ELF memory sections need to be written to by the linker. This flags the loader to turn these sections read-only before turning over control to the program. Most notably this prevents GOT overwrite attacks. If this option is disabled, \&\fBbindnow\fR will become disabled as well. .IP \fBbindnow\fR 4 .IX Item "bindnow" This setting (since dpkg 1.16.1; disabled by default) adds \&\fB\-Wl,\-z,now\fR to \fBLDFLAGS\fR. During program load, all dynamic symbols are resolved, allowing for the entire PLT to be marked read-only (due to \fBrelro\fR above). The option cannot become enabled if \fBrelro\fR is not enabled. .IP \fBpie\fR 4 .IX Item "pie" This setting (since dpkg 1.16.1; with no global default since dpkg 1.18.23, as it is enabled by default now by gcc on the amd64, arm64, armel, armhf, hurd\-i386, i386, kfreebsd\-amd64, kfreebsd\-i386, mips, mipsel, mips64el, powerpc, ppc64, ppc64el, riscv64, s390x, sparc and sparc64 Debian architectures) adds the required options to enable or disable PIE via gcc specs files, if needed, depending on whether gcc injects on that architecture the flags by itself or not. When the setting is enabled and gcc injects the flags, it adds nothing. When the setting is enabled and gcc does not inject the flags, it adds \&\fB\-fPIE\fR (via \fI/usr/share/dpkg/pie\-compiler.specs\fR) to \fBCFLAGS\fR, \&\fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR, and \&\fB\-fPIE \-pie\fR (via \fI/usr/share/dpkg/pie\-link.specs\fR) to \fBLDFLAGS\fR. When the setting is disabled and gcc injects the flags, it adds \&\fB\-fno\-PIE\fR (via \fI/usr/share/dpkg/no\-pie\-compile.specs\fR) to \fBCFLAGS\fR, \&\fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR, and \&\fB\-fno\-PIE \-no\-pie\fR (via \fI/usr/share/dpkg/no\-pie\-link.specs\fR) to \&\fBLDFLAGS\fR. .Sp Position Independent Executable (PIE) is needed to take advantage of Address Space Layout Randomization (ASLR), supported by some kernel versions. While ASLR can already be enforced for data areas in the stack and heap (brk and mmap), the code areas must be compiled as position-independent. Shared libraries already do this (\fB\-fPIC\fR), so they gain ASLR automatically, but binary .text regions need to be built as PIE to gain ASLR. When this happens, ROP (Return Oriented Programming) attacks are much harder since there are no static locations to bounce off of during a memory corruption attack. .Sp PIE is not compatible with \fB\-fPIC\fR, so in general care must be taken when building shared objects. But because the PIE flags emitted get injected via gcc specs files, it should always be safe to unconditionally set them regardless of the object type being compiled or linked. .Sp Static libraries can be used by programs or other shared libraries. Depending on the flags used to compile all the objects within a static library, these libraries will be usable by different sets of objects: .RS 4 .IP none 4 .IX Item "none" Cannot be linked into a PIE program, nor a shared library. .IP \fB\-fPIE\fR 4 .IX Item "-fPIE" Can be linked into any program, but not a shared library (recommended). .IP \fB\-fPIC\fR 4 .IX Item "-fPIC" Can be linked into any program and shared library. .RE .RS 4 .Sp If there is a need to set these flags manually, bypassing the gcc specs injection, there are several things to take into account. Unconditionally and explicitly passing \fB\-fPIE\fR, \fB\-fpie\fR or \fB\-pie\fR to a build-system using libtool is safe as these flags will get stripped when building shared libraries. Otherwise on projects that build both programs and shared libraries you might need to make sure that when building the shared libraries \fB\-fPIC\fR is always passed last (so that it overrides any previous \fB\-PIE\fR) to compilation flags such as \fBCFLAGS\fR, and \fB\-shared\fR is passed last (so that it overrides any previous \fB\-pie\fR) to linking flags such as \&\fBLDFLAGS\fR. \&\fBNote\fR: This should not be needed with the default gcc specs machinery. .Sp Additionally, since PIE is implemented via a general register, some register starved architectures (but not including i386 anymore since optimizations implemented in gcc >= 5) can see performance losses of up to 15% in very text-segment-heavy application workloads; most workloads see less than 1%. Architectures with more general registers (e.g. amd64) do not see as high a worst-case penalty. .RE .SS reproducible .IX Subsection "reproducible" The compile-time options detailed below can be used to help improve build reproducibility or provide additional warning messages during compilation. Except as noted below, these are enabled by default for architectures that support them. .IP \fBtimeless\fR 4 .IX Item "timeless" This setting (since dpkg 1.17.14; enabled by default) adds \&\fB\-Wdate\-time\fR to \fBCPPFLAGS\fR. This will cause warnings when the \fB_\|_TIME_\|_\fR, \fB_\|_DATE_\|_\fR and \&\fB_\|_TIMESTAMP_\|_\fR macros are used. .IP \fBfixfilepath\fR 4 .IX Item "fixfilepath" This setting (since dpkg 1.19.1; enabled by default) adds \&\fB\-ffile\-prefix\-map=\fR\fIBUILDPATH\fR\fB=.\fR to \fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR where \fBBUILDPATH\fR is set to the top-level directory of the package being built. This has the effect of removing the build path from any generated file. .Sp If both \fBfixdebugpath\fR and \fBfixfilepath\fR are set, this option takes precedence, because it is a superset of the former. .Sp \&\fBNote\fR: If the build process captures the build flags into the resulting built objects, that will make the package unreproducible. And while disabling this option might make some of the objects reproducible again this would also require disabling \fBfixdebugpath\fR, which might make any generated debug symbols objects unreproducible. The ideal fix is to stop capturing build flags. .IP \fBfixdebugpath\fR 4 .IX Item "fixdebugpath" This setting (since dpkg 1.18.5; enabled by default) adds \&\fB\-fdebug\-prefix\-map=\fR\fIBUILDPATH\fR\fB=.\fR to \fBCFLAGS\fR, \fBCXXFLAGS\fR, \fBOBJCFLAGS\fR, \fBOBJCXXFLAGS\fR, \&\fBFFLAGS\fR and \fBFCFLAGS\fR where \fBBUILDPATH\fR is set to the top-level directory of the package being built. This has the effect of removing the build path from any generated debug symbols. .Sp \&\fBNote\fR: This feature has similar reproducible properties as \fBfixfilepath\fR. .SH ENVIRONMENT .IX Header "ENVIRONMENT" There are 2 sets of environment variables doing the same operations, the first one (DEB_\fIflag\fR_\fIop\fR) should never be used within \&\fBdebian/rules\fR. It's meant for any user that wants to rebuild the source package with different build flags. The second set (DEB_\fIflag\fR_MAINT_\fIop\fR) should only be used in \fBdebian/rules\fR by package maintainers to change the resulting build flags. .IP \fBDEB_\fR\fIflag\fR\fB_SET\fR 4 .IX Item "DEB_flag_SET" .PD 0 .IP "\fBDEB_\fR\fIflag\fR\fB_MAINT_SET\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_MAINT_SET (since dpkg 1.16.1)" .PD This variable can be used to force the value returned for the given \&\fIflag\fR. .IP "\fBDEB_\fR\fIflag\fR\fB_STRIP\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_STRIP (since dpkg 1.16.1)" .PD 0 .IP "\fBDEB_\fR\fIflag\fR\fB_MAINT_STRIP\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_MAINT_STRIP (since dpkg 1.16.1)" .PD This variable can be used to provide a space separated list of options that will be stripped from the set of flags returned for the given \&\fIflag\fR. .IP \fBDEB_\fR\fIflag\fR\fB_APPEND\fR 4 .IX Item "DEB_flag_APPEND" .PD 0 .IP "\fBDEB_\fR\fIflag\fR\fB_MAINT_APPEND\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_MAINT_APPEND (since dpkg 1.16.1)" .PD This variable can be used to append supplementary options to the value returned for the given \fIflag\fR. .IP "\fBDEB_\fR\fIflag\fR\fB_PREPEND\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_PREPEND (since dpkg 1.16.1)" .PD 0 .IP "\fBDEB_\fR\fIflag\fR\fB_MAINT_PREPEND\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_flag_MAINT_PREPEND (since dpkg 1.16.1)" .PD This variable can be used to prepend supplementary options to the value returned for the given \fIflag\fR. .IP \fBDEB_BUILD_OPTIONS\fR 4 .IX Item "DEB_BUILD_OPTIONS" .PD 0 .IP "\fBDEB_BUILD_MAINT_OPTIONS\fR (since dpkg 1.16.1)" 4 .IX Item "DEB_BUILD_MAINT_OPTIONS (since dpkg 1.16.1)" .PD These variables can be used by a user or maintainer to disable/enable various area features that affect build flags. The \fBDEB_BUILD_MAINT_OPTIONS\fR variable overrides any setting in the \&\fBDEB_BUILD_OPTIONS\fR feature areas. See the "FEATURE AREAS" section for details. .IP \fBDEB_VENDOR\fR 4 .IX Item "DEB_VENDOR" This setting defines the current vendor. If not set, it will discover the current vendor by reading \&\fB/etc/dpkg/origins/default\fR. .IP \fBDEB_BUILD_PATH\fR 4 .IX Item "DEB_BUILD_PATH" This variable sets the build path (since dpkg 1.18.8) to use in features such as \fBfixdebugpath\fR so that they can be controlled by the caller. This variable is currently Debian and derivatives-specific. .IP \fBDEB_HOST_ARCH\fR 4 .IX Item "DEB_HOST_ARCH" Sets the host architecture. This affects the build flags that are emitted, which is typically relevant when cross-compiling, where \fBDEB_HOST_ARCH\fR is different to \fBDEB_BUILD_ARCH\fR. .IP \fBDPKG_COLORS\fR 4 .IX Item "DPKG_COLORS" Sets the color mode (since dpkg 1.18.5). The currently accepted values are: \fBauto\fR (default), \fBalways\fR and \&\fBnever\fR. .IP \fBDPKG_NLS\fR 4 .IX Item "DPKG_NLS" If set, it will be used to decide whether to activate Native Language Support, also known as internationalization (or i18n) support (since dpkg 1.19.0). The accepted values are: \fB0\fR and \fB1\fR (default). .SH FILES .IX Header "FILES" .SS "Configuration files" .IX Subsection "Configuration files" .IP \fB/etc/dpkg/buildflags.conf\fR 4 .IX Item "/etc/dpkg/buildflags.conf" System wide configuration file. .ie n .IP "\fR\fB$XDG_CONFIG_HOME\fR\fB/dpkg/buildflags.conf\fR or" 4 .el .IP "\fR\f(CB$XDG_CONFIG_HOME\fR\fB/dpkg/buildflags.conf\fR or" 4 .IX Item "$XDG_CONFIG_HOME/dpkg/buildflags.conf or" .PD 0 .ie n .IP \fR\fB$HOME\fR\fB/.config/dpkg/buildflags.conf\fR 4 .el .IP \fR\f(CB$HOME\fR\fB/.config/dpkg/buildflags.conf\fR 4 .IX Item "$HOME/.config/dpkg/buildflags.conf" .PD User configuration file. .SS "Packaging support" .IX Subsection "Packaging support" .IP \fB/usr/share/dpkg/buildflags.mk\fR 4 .IX Item "/usr/share/dpkg/buildflags.mk" Makefile snippet that will load (and optionally export) all flags supported by \fBdpkg-buildflags\fR into variables (since dpkg 1.16.1). .SH EXAMPLES .IX Header "EXAMPLES" To pass build flags to a build command in a Makefile: .Sp .Vb 1 \& $(MAKE) $(shell dpkg\-buildflags \-\-export=cmdline) \& \& ./configure $(shell dpkg\-buildflags \-\-export=cmdline) .Ve .PP To set build flags in a shell script or shell fragment, \fBeval\fR can be used to interpret the output and to export the flags in the environment: .Sp .Vb 1 \& eval "$(dpkg\-buildflags \-\-export=sh)" && make .Ve .PP or to set the positional parameters to pass to a command: .Sp .Vb 2 \& eval "set \-\- $(dpkg\-buildflags \-\-export=cmdline)" \& for dir in a b c; do (cd $dir && ./configure "$@" && make); done .Ve .SS "Usage in debian/rules" .IX Subsection "Usage in debian/rules" You should call \fBdpkg-buildflags\fR or include \fBbuildflags.mk\fR from the \fBdebian/rules\fR file to obtain the needed build flags to pass to the build system. Note that older versions of \fBdpkg-buildpackage\fR (before dpkg 1.16.1) exported these flags automatically. However, you should not rely on this, since this breaks manual invocation of \fBdebian/rules\fR. .PP For packages with autoconf-like build systems, you can pass the relevant options to configure or \fBmake\fR\|(1) directly, as shown above. .PP For other build systems, or when you need more fine-grained control about which flags are passed where, you can use \fB\-\-get\fR. Or you can include \fBbuildflags.mk\fR instead, which takes care of calling \&\fBdpkg-buildflags\fR and storing the build flags in make variables. .PP If you want to export all buildflags into the environment (where they can be picked up by your build system): .Sp .Vb 2 \& DPKG_EXPORT_BUILDFLAGS = 1 \& include /usr/share/dpkg/buildflags.mk .Ve .PP For some extra control over what is exported, you can manually export the variables (as none are exported by default): .Sp .Vb 2 \& include /usr/share/dpkg/buildflags.mk \& export CPPFLAGS CFLAGS LDFLAGS .Ve .PP And you can of course pass the flags to commands manually: .Sp .Vb 3 \& include /usr/share/dpkg/buildflags.mk \& build\-arch: \& $(CC) \-o hello hello.c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .Ve