# Noticed that compiling OTP with kerl or from the source binaries (elf files) are built with the debug info - is that intentional?

**URL:** <https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243>\
**Category:** Questions / Help\
**Tags:** kerl\
**Created:** [January 7, 2023, 5:59pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243 "2023-01-07T17:59:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pickme467](https://erlangforums.com/user_avatar/erlangforums.com/pickme467/32/1802_2.png) [@pickme467](https://erlangforums.com/u/pickme467)\
**Post date:** [January 7, 2023, 5:59pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/1 "2023-01-07T17:59:53Z")

</div>

Hello,

Compiling the OTP either with kerl or from the source I noticed that binaries (elf files) are built with the debug information and are not stripped. It makes them quite big. Is that intentional? I mean wouldn’t default be just optimized binary without the debug information?

I noticed it because previously I used Erlang Solutions’ provided installations (for CentOS) and the binary files there are free from the debug information and are stripped.

I was looking for configuration options, but I failed miserably.

Here is a sample from the latest OTP:

```erlang
file /usr/local/lib/erlang/erts-13.1.3/bin/beam.smp
/usr/local/lib/erlang/erts-13.1.3/bin/beam.smp: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=be8c0b6d161441fff42012f14461ef058c61b5e5, with debug_info, not stripped

```

And here is some old release installed from Erlang Solutions:

```erlang
file erts-11.2.2.4/bin/beam.smp
erts-11.2.2.4/bin/beam.smp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=d989fd155818e2c602f0dc74a902276ad137771f, stripped

```

Greetings,  
pickme467

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [January 17, 2023, 6:39pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/2 "2023-01-17T18:39:54Z")

</div>

> [@pickme467](#):
>
> I mean wouldn’t default be just optimized binary without the debug information?

The Autoconf toolchain default to using “-O2 -g” as CFLAGS, which means that Erlang and all systems that use Autoconf (which is a lot of systems) also include debug information by default.

> [@pickme467](#):
>
> I was looking for configuration options, but I failed miserably.

To remove the debug info you can set the CFLAGS variable to “-g” when running `configure`, or you can strip the executables after the fact.

---

<div class="post-metadata">

**Author:** ![pickme467](https://erlangforums.com/user_avatar/erlangforums.com/pickme467/32/1802_2.png) [@pickme467](https://erlangforums.com/u/pickme467)\
**Post date:** [January 18, 2023, 7:47am UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/3 "2023-01-18T07:47:35Z")

</div>

Thank you for the answer.

Meanwhile I dug the configurations and compiled without debug for my use.

I also checked the official Erlang docker image. It doesn’t change default which means it’s quite a big image. I thought that maybe for containers the build procedure is different since container world strives for small images.

If that’s intendend then I’m ok with that.

I’m not that aware of Autoconf toolchain and I’m not sure how many of Erlang developers is, so maybe it would be good to describe it in the install manual in more explicit way ([Erlang -- Building and Installing Erlang/OTP](https://www.erlang.org/doc/installation_guide/install))? There is a section called “How to Build a Debug Enabled Erlang RunTime System”, which was kind of misleading to me, because I thought that it is about the debug version of the RunTime system (elf binaries). Since I wasn’t interested in the debug version I thought that the non-debug version is just free from any debug information. A section called “How to Build a Non-Debug, Small and Optimized Erlang RunTime System” might be a good symmetric section that would clear up this area.

---

<div class="post-metadata">

**Author:** ![shortishly](https://erlangforums.com/user_avatar/erlangforums.com/shortishly/32/495_2.png) [@shortishly](https://erlangforums.com/u/shortishly)\
**Post date:** [January 19, 2023, 12:50pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/4 "2023-01-19T12:50:34Z")

</div>

> [@pickme467](#):
>
> I also checked the official Erlang docker image. It doesn’t change default which means it’s quite a big image. I thought that maybe for containers the build procedure is different since container world strives for small images.

The Official image has quite a few use cases - which might include wanting debug, and it is pretty easy to strip out after the fact for those that don’t.

If you’re wanting small containers - there is an [escript that will strip binaries](https://github.com/shortishly/beam-docker-release-action/blob/main/bin/mkimage#L145-L166) that is part of a GitHub action to build minimal [BEAM containers from scratch](https://github.com/shortishly/beam-docker-release-action) (which uses the Official image as a build stage). It should be pretty easy to “strip” out if you’re using another CI system. The resulting containers just have a stripped Erlang runtime with only the dependent shared libraries without a shell - original [motivation background here](https://shortishly.com/blog/erlang-in-docker-from-scratch/).

---

<div class="post-metadata">

**Author:** ![pickme467](https://erlangforums.com/user_avatar/erlangforums.com/pickme467/32/1802_2.png) [@pickme467](https://erlangforums.com/u/pickme467)\
**Post date:** [January 19, 2023, 1:19pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/5 "2023-01-19T13:19:01Z")

</div>

Stripping is just a way to remove debug information. But as far as I know debug information doesn’t get along with the optimization applied to the code. I’m not sure what are defaults for the official release, but I know that for my production docker I want a small footprint and a good performance. So to me it would be a better approach to control not only debug information but also generated code optimizations, thus the approach that involves autoconf mechanisms is more tempting to me.

I’m ok with tinkering, but I would like to know what is the “default”. That’s why I pointed to documentation as a nice solution of my issue.

---

<div class="post-metadata">

**Author:** ![zabrane](https://erlangforums.com/letter_avatar_proxy/v4/letter/z/7ba0ec/32.png) [@zabrane](https://erlangforums.com/u/zabrane)\
**Post date:** [January 19, 2023, 4:32pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/6 "2023-01-19T16:32:40Z")

</div>

@pickme467 i’m also interested on how to build `Erlang VM` without debugging symbols with `kerl`.

---

<div class="post-metadata">

**Author:** ![LeonardB](https://erlangforums.com/user_avatar/erlangforums.com/leonardb/32/1856_2.png) [@LeonardB](https://erlangforums.com/u/LeonardB)\
**Post date:** [January 19, 2023, 4:50pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/7 "2023-01-19T16:50:45Z")

</div>

May be of help: [https://github.com/kerl/kerl#enable-autoconf](https://github.com/kerl/kerl#enable-autoconf)  
Has an example of setting CFLAGS for the build

---

<div class="post-metadata">

**Author:** ![zabrane](https://erlangforums.com/letter_avatar_proxy/v4/letter/z/7ba0ec/32.png) [@zabrane](https://erlangforums.com/u/zabrane)\
**Post date:** [January 19, 2023, 6:10pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/8 "2023-01-19T18:10:59Z")

</div>

@LeonardB does enabling `KERL_USE_AUTOCONF=yes` will overwrite the defaults (i.e drop the “-O2 -g”`?

---

<div class="post-metadata">

**Author:** ![LeonardB](https://erlangforums.com/user_avatar/erlangforums.com/leonardb/32/1856_2.png) [@LeonardB](https://erlangforums.com/u/LeonardB)\
**Post date:** [January 19, 2023, 6:48pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/9 "2023-01-19T18:48:10Z")

</div>

I’m realizing I meant to link to [https://github.com/kerl/kerl#using-shell-export-command-in-kerlrc](https://github.com/kerl/kerl#using-shell-export-command-in-kerlrc)

This section shows you can use exported environment variables to set CFLAGS for the build  
so if you just `export CFLAGS="-O2 -g0"` (or omitting the -g entirely) before the build you should have the result you’re looking for

(edited. an ‘-O’ value is required in CFLAGS)

I’m currently doing a test with asdf/kerl to confirm it works and will edit with results

---

<div class="post-metadata">

**Author:** ![LeonardB](https://erlangforums.com/user_avatar/erlangforums.com/leonardb/32/1856_2.png) [@LeonardB](https://erlangforums.com/u/LeonardB)\
**Post date:** [January 19, 2023, 7:19pm UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/10 "2023-01-19T19:19:11Z")

</div>

Appears to work

```erlang
$ export CFLAGS="-O2"
$ KERL_CONFIGURE_OPTIONS="--enable-smp-support --without-odbc --enable-kernel-poll --without-javac --enable-threads --enable-hipe --with-ssl"
$ asdf install erlang 23.3.4.18
asdf_23.3.4.18 is not a kerl-managed Erlang/OTP installation
....
Extracting source code
Building Erlang/OTP 23.3.4.18 (asdf_23.3.4.18), please wait...
....
Erlang/OTP 23.3.4.18 (asdf_23.3.4.18) has been successfully built
Cleaning up compilation products for 
Cleaned up compilation products for under /home/leonard/.asdf/plugins/erlang/kerl-home/builds

$ objdump --syms /home/leonard/.asdf/installs/erlang/23.3.4.18/bin/erlc | grep debug
000000000001f20c l O .bss 0000000000000004 debug

and a couple of previous builds (default "-O2 -g")

$ objdump --syms /home/leonard/.asdf/installs/erlang/23.3.4.14/bin/erlc | grep debug
0000000000000000 l d .debug_aranges 0000000000000000 .debug_aranges
0000000000000000 l d .debug_info 0000000000000000 .debug_info
0000000000000000 l d .debug_abbrev 0000000000000000 .debug_abbrev
0000000000000000 l d .debug_line 0000000000000000 .debug_line
0000000000000000 l d .debug_str 0000000000000000 .debug_str
0000000000000000 l d .debug_loc 0000000000000000 .debug_loc
0000000000000000 l d .debug_ranges 0000000000000000 .debug_ranges
000000000001f20c l O .bss 0000000000000004 debug

$ objdump --syms /home/leonard/.asdf/installs/erlang/23.3.4.10/bin/erlc | grep debug
0000000000000000 l d .debug_aranges 0000000000000000 .debug_aranges
0000000000000000 l d .debug_info 0000000000000000 .debug_info
0000000000000000 l d .debug_abbrev 0000000000000000 .debug_abbrev
0000000000000000 l d .debug_line 0000000000000000 .debug_line
0000000000000000 l d .debug_str 0000000000000000 .debug_str
0000000000000000 l d .debug_loc 0000000000000000 .debug_loc
0000000000000000 l d .debug_ranges 0000000000000000 .debug_ranges
000000000001f20c l O .bss 0000000000000004 debug

```

and size comparisons

```erlang
$ ls -lah /home/leonard/.asdf/installs/erlang/23.3.4.*/bin/erlc
-rwxr-xr-x 1 leonard leonard 704K Jan 5 2022 /home/leonard/.asdf/installs/erlang/23.3.4.10/bin/erlc
-rwxr-xr-x 1 leonard leonard 704K May 6 2022 /home/leonard/.asdf/installs/erlang/23.3.4.14/bin/erlc
-rwxr-xr-x 1 leonard leonard 143K Jan 19 14:12 /home/leonard/.asdf/installs/erlang/23.3.4.18/bin/erlc

```

and finally

```erlang
$ file /home/leonard/.asdf/installs/erlang/23.3.4.*/bin/erlc
/home/leonard/.asdf/installs/erlang/23.3.4.10/bin/erlc: ELF 64-bit .... for GNU/Linux 3.2.0, with debug_info, not stripped
/home/leonard/.asdf/installs/erlang/23.3.4.14/bin/erlc: ELF 64-bit .... for GNU/Linux 3.2.0, with debug_info, not stripped
/home/leonard/.asdf/installs/erlang/23.3.4.18/bin/erlc: ELF 64-bit .... for GNU/Linux 3.2.0, not stripped

```

---

<div class="post-metadata">

**Author:** ![pickme467](https://erlangforums.com/user_avatar/erlangforums.com/pickme467/32/1802_2.png) [@pickme467](https://erlangforums.com/u/pickme467)\
**Post date:** [January 20, 2023, 8:17am UTC](https://erlangforums.com/t/noticed-that-compiling-otp-with-kerl-or-from-the-source-binaries-elf-files-are-built-with-the-debug-info-is-that-intentional/2243/11 "2023-01-20T08:17:01Z")

</div>

That’s exactly what I did for my case. I just used CFLAGS. But I was afraid that maybe CXXFLAGS are also needed. It’s tricky to know exactly what to set, you need to know if the project compiles C++ or just plain C.
