
Specialization of Run-time Configuration Space at Compile-time: An Exploratory Study Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
The used
--cabac
,
--mbtree
, and
--mixed-refs
options are
Boolean. They also have their variant to negate their func-
tionality, for example, --mbtree has --no-mbtree.
x264
is a free software application for encoding video
streams into the H.264 compression format. It is often used as
a library in large systems, such as in space ight hardware
7
where its (i) binary size and (ii) performance matters. Besides,
(iii) a vulnerability in the
x264
’s (H.264 decoder) function
could be used to attack a larger system, such as the case with
the Cisco Meeting Servers
8
. Nowadays, the security of mod-
ern software systems is mostly threatened internally, that
is, by reusing their existing code, without the need for code
injection [
46
]. This kind of attack allows an attacker to exe-
cute arbitrary code on a victim’s machine. In this attack, the
attacker is able to chain some small code sequences (called
gadgets) and threaten the security of the system. Basically,
the exploited code sequences by the attacker end in a return
(RET or JMP) instruction. Therefore, one of the commonly
used metrics for measuring the attack surface in a system is
the number of code reuse gadgets that are available and which
can be exploited by an attacker [11,27,46].
Motivated by similar requirements, we analyse the eects
of specializing
x264
on these three non-functional properties,
namely on its binary size, attack surface, and performance.
3 Specialization approach
3.1 The vision for debloating unused run-time
options at compile-time
At the system level, the usual approach is to keep as much
variability as possible. All run-time options may somehow
be needed one day. Furthermore, packages, binaries, or build
instructions force users to take them all. However, this vari-
ability is sometimes unnecessary: in a given context, some
options may never be tuned and thus they always have the
same value for all actual use cases of a given instance of the
software. For instance,
--cabac
might always have the true
value. In this case, its corresponding variable in the source
code becomes a constant. By setting the option of
--no-cabac
will speed up the video encoding time, but the video quality
may deteriorate. Hence, the tune of run-time options de-
pends on the objectives and constraints of the user. Keeping
an option while actually always using the same value leads
to missed opportunities. First, by knowing that an option has
the same value, compilers do not have to make some assump-
tions and the generated code can be improved. Specically,
compilers can further apply optimizations and constant fold-
ing, including the propagation of constants and the removal
of dead code. Secondly, the presence of unused options at
run-time is likely (i) to increase the executable binary size,
since the related code will be included; (ii) can increase the
7
AVN443 encoder: hps://www.tvbeurope.com/production-post/visionary-
provides-hd-encoders-for-international-space-station.
8A vulnerability: hps://www.cvedetails.com/cve/CVE-2017-12311/.
attack surface (e.g., the number of code-reuse gadgets [
27
]);
and (iii) even slow down the system. The vision is that the
proactive removal of the unused run-time options can be
benecial to several non-functional properties of software.
To technically support this vision, developers should have
the means to debloat run-time options, for example, by lift-
ing them at compile-time, and thus specialize the original
program. With congurable specialization, developers can
build specialized packages (binaries) out of the specialized
program. For example, one can envision delivering new vari-
ants of
x264
:
x264-fast
– with fast encoding time,
x264-hq
– with high quality video encoding,
x264-secured
– with
fewer code-reuse gadgets, or
x264-tinyfast
– a small bi-
nary size yet fast
x264
. Importantly, they do not necessarily
specify a full and complete conguration: not all options are
subject to specialization since a part of the variability can
be preserved at run-time for addressing several usages. But,
some of the unneeded options that may improve the non-
functional properties and the performance of the system can
be eliminated from code. Our idea is inspired by the multi-
staged conguration [
14
,
22
] for a step-wise specialization
of variability models. In our case, specialization occurs at
the code level and regarding the run-time options.
3.2 Process for program specialization
To quantify the benets of such a vision, we report in this
paper about our experiments in debloating run-time options
of
x264
through program specialization (cf. Figure 1). To
achieve our vision, one should be able to specialize
x264
by
removing run-time conguration options on demand. This
implies removing the parts of source code that implement
such options, which is dierent from simply disabling those
options in a congurator or at the command-line parameter
level. Moreover, to be able to remove the unused run-time
options, they rst need to be located in the source code.
Hence, we propose a removal approach which is based on 4
tasks: (
T1
)we rst comprehend the implementation of run-time
options, then (
T2
)we annotate the corresponding code which
implement a given run-time option, and nally (
T3
)we apply
a partial evaluator taking care of the actual code removal. In
addition to these three tasks, we conducted the last task (
T4
)
which consists in validating the program specialization by
comparing the resulting debloated program with the original
one according to a given conguration of run-time options.
The experiments conducted for these 4 tasks in the con-
text of run-time options in C-based systems, taking
x264
as an illustrative example, are presented in the following.
As a partial evaluator, we decided to use the preprocessor
switches [
7
] and all the optimizations (e.g., dead code elim-
ination) provided by GCC (in grey in Figure 1). A partial
evaluator is a method for simplifying programs when pro-
gram parameters are known [
7
,
25
]. For instance, when it
is known that a run-time conguration option in a given
3