[erlang-questions] R16 + Centos + Crypto + ESL Package

Scott Lystig Fritchie <>
Fri Aug 1 10:18:07 CEST 2014


Scott Lystig Fritchie <> wrote:

slf> The autoconf toolchain seems to go to great lengths to disable all
slf> -O compiler optimizations whenever the CFLAGS environment variable
slf> is specified, regardless of what it's set to?

Hahaha, oh, how I delude myself.  It's amazing what a person can learn
from reading documentation ... in this case, the GNU Make docs.

    $(subst from,to,text)

        Performs a textual replacement on the text text: each occurrence
        of from is replaced by to. The result is substituted for the
        function call.

So, I was mis-reading all of the Makefile.in templates.  For example,
from erts/emulator/Makefile.in:

    $(OBJDIR)/%.o: beam/%.c
        $(CC) $(subst -O2, $(GEN_OPT_FLGS), $(CFLAGS)) $(INCLUDES) -c $< -o $@

My misunderstanding was that -O2 was the result of the $(subst ...).
Silly me.

My interpretation of all of the Makefile.in template files is that they
embed the following assumption: if a default CFLAGS-related variable or
compiler-optimization-related variable is going to contain an -O flag of
some kind, it's going to be "-O2".  There are many places where the
Makefile.in templates then decide:

    * I'm going to change the default optimization to $(GEN_OPT_FLGS)
    * I'm going to remove the default optimization entirely, e.g.,
      done in a handful of places when building a valgrind or debug
      version.

Furthermore, the location for the default optimization is the top-level
"configure" script itself.  "Configure" checks whether you're using GCC,
and based on the result will set CFLAGS to be:

    1. The value of CFLAGS environment variable is, if it was set
       prior to running "configure"
    2. If using GCC, then "-g -O2" or "-O2", depending on if GCC
       understands "-g" or not.
    3. If using GCC, then "-g" or "", depending on if the compiler
       understands "-g" or not.

So, it seems to me that Danila and I/Basho can solve our optimizer
problem and our CentOS-6-broken-SSL-problem at the same time by adding
"-O2" to CFLAGS before running "configure" ... then the rest of the
autoconf stuff will magically change -O2 -> -O3 in the appropriate
places, use -O2 elsewhere, etc., and the world will sing and dance and
be fast(er).

-Scott



More information about the erlang-questions mailing list