Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--disable-debug-info enables debug information #1646

Open
jefftrull opened this issue Dec 20, 2024 · 23 comments
Open

--disable-debug-info enables debug information #1646

jefftrull opened this issue Dec 20, 2024 · 23 comments

Comments

@jefftrull
Copy link

jefftrull commented Dec 20, 2024

I am building toolchains for use in Docker containers and I find that the --disable-debug-info configure option does nothing - debug info is always present in the toolchain binaries, causing my container images to be very large. For example:

/configure --disable-gdb --disable-debug-info --with-arch=rv32imc \
--with-abi=ilp32 --with-cmodel=medlow --prefix=`pwd`/installed
make
...
file installed/bin/*

shows all the binaries as with debug_info, not stripped.

I can see that --enable-debug-info does add -g to the compile flags, but it seems like it must be there by default in gcc (at least) and what we need is some way of turning that off.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Dec 20, 2024

Doesn't --disable-debug-info only apply to the standard library?

Maybe you need to use something like the following?

make ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 ...

E.g. see here:

@jefftrull
Copy link
Author

That's a great point re: --disable-debug-info. However it does seem as if that too does not work. In the lib directory all the .so files are with debug_info, not stripped. There are some .a files as well and when I extract the .o files from them they also have debug symbols.

Looking at the configure code I think that this switch can only add debug symbols, and it seems that the underlying repos (gcc etc.) already have symbols enabled by default somehow.

I will try your -g0 suggestion.

@TommyMurphyTM1234
Copy link
Collaborator

Probably worth looking at the build log to see what flags are being used. It'll be a day or two before I can try a build myself to check this out.

@jefftrull
Copy link
Author

Thanks for looking at this. I should be able to make some progress with these tips.

Would you mind clarifying about the extra variables? Judging by the fact that CFLAGS_FOR_TARGET_EXTRA gets combined with -mcmodel=medlow in the Makefile, it seems like it applies to the binaries generated by the toolchain, rather than the toolchain itself (which is at issue in this case). Am I confused? If not, is there a different variable I can use?

@TommyMurphyTM1234
Copy link
Collaborator

If you want to affect the toolchain binaries themselves then maybe simply make CFLAGS=-g0 ... or similar? I'm AFK so can't really check at the moment unfortunately.

@jefftrull
Copy link
Author

That was the ticket (for the binaries!). Leaving this open for the libraries.

@TommyMurphyTM1234
Copy link
Collaborator

That was the ticket (for the binaries!). Leaving this open for the libraries.

Does a combination of configure --disable-debug-info ... and make ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 ... not eliminate debug info for the libraries?

@TommyMurphyTM1234
Copy link
Collaborator

FWIW, as far as I can see the riscv-gnu-toolchain top-level Makefile[.in] always uses make install (or equivalent) rather than make install-strip (or equivalent where available) and there is no facility to opt for the stripped install. And, by default, in the absence of configure --disable-debug-info ... and/or make ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 ... and/or make ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 ... etc., everything is built (and installed) with debug information.

I presume that the issue for you @jefftrull is that you want the toolchain to be as lean as possible and not unnecessarily carrying any additional baggage such as debug info/symbols?

Just tagging @ilg-ul to ask if he does something different with his xPack build in order to produce a toolchain distro that bundles some or all components already stripped?

@ilg-ul
Copy link

ilg-ul commented Dec 21, 2024

Just tagging @ilg-ul to ask if he does something different with his xPack build in order to produce a toolchain distro that bundles some or all components already stripped?

Can you be more specific? There are a lot of configuration options, both for GCC and binutils.

@TommyMurphyTM1234
Copy link
Collaborator

Can you be more specific? There are a lot of configuration options, both for GCC and binutils.

Are some, most or all cross development host and RISC-V target binaries/libraries/object files in the xPack RISC-V GCC toolchain stripped (of debug information/symbols)? I just haven't had a chance to check.

@ilg-ul
Copy link

ilg-ul commented Dec 21, 2024

I did not check either, but, as far as I remember, the xPack build scripts strip all native executables and libraries of debug information. There are options to prevent this for development builds.

As for the cross libraries... I don't know, but generally running debug sessions with the GCC runtime and newlib libraries is not possible.

@jefftrull
Copy link
Author

That was the ticket (for the binaries!). Leaving this open for the libraries.

Does a combination of configure --disable-debug-info ... and make ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 ... not eliminate debug info for the libraries?

Unfortunately not. libgcc.a, libstdc++.a, and libc.a all contain object files with debug info. I used the following command lines:

./configure --disable-gdb --disable-debug-info --with-arch=rv32imc --with-abi=ilp32 --with-cmodel=medlow --prefix=`pwd`/installed
GCC_EXTRA_CONFIGURE_FLAGS=--enable-target-optspace BINUTILS_TARGET_FLAGS_EXTRA=--enable-target-optspace NEWLIB_TARGET_FLAGS_EXTRA=--enable-target-optspace  CFLAGS=-g0 CXXFLAGS=-g0 ASFLAGS_FOR_TARGET_EXTRA=-g0 CFLAGS_FOR_TARGET_EXTRA=-g0 CXXFLAGS_FOR_TARGET_EXTRA=-g0 gmake -j4

It looks to me as though --disable-debug-info does nothing, because "disabled" is the default state. Some casual Googling has led me to believe that gcc etc. binaries have debug info by default. If I'm right about this, and a good combination of options can be determined, perhaps --disable-debug-info can be made to select them for the user.

@TommyMurphyTM1234
Copy link
Collaborator

@jefftrull, what is the problem with debug information in the libraries? In a bare-metal deployment scenario the debug info sections are never actually loaded on the target. They just exist in the ELF file on the development host to facilitate debugging.

What is the exact problem that you are trying to address here?

Other than the fact (it seems) that --[dis|en]able-debug-info may not be working as expected?

@ilg-ul
Copy link

ilg-ul commented Dec 21, 2024

The xPack build scripts run lots of post-processing actions, including stripping debug infos.

@jefftrull
Copy link
Author

jefftrull commented Dec 21, 2024

@jefftrull, what is the problem with debug information in the libraries? In a bare-metal deployment scenario the debug info sections are never actually loaded on the target. They just exist in the ELF file on the development host to facilitate debugging.

What is the exact problem that you are trying to address here?

Other than the fact (it seems) that --[dis|en]able-debug-info may not be working as expected?

I am creating Docker container images containing the toolchain, for continuous integration and other purposes. The images produced at the moment are surprisingly large, consuming resources on the host machines as well as taking up time for data transfer. I also discovered that it increases build time (I assume for writing all this data to disk).

@jefftrull
Copy link
Author

I've made an interesting discovery. --disable-debug-info enables debug symbols. That is, it sets enable_debug_info to "no", which is considered a true value by the check here.

So when I tried to remove debug symbols from the toolchain binaries by using --disable-debug-info it ended up enabling them in the libraries!

So maybe the proper procedure is:

  1. leave debug-info alone - libraries will not get debug info
  2. use CFLAGS=-g0 CXXFLAGS=-g0 with make to remove debug info from binaries

@ilg-ul
Copy link

ilg-ul commented Dec 22, 2024

it sets enable_debug_info to "no", which is considered a true value by the check ...

If you identified a bug in the configure script, please report it to GCC bugzilla.

@jefftrull
Copy link
Author

That's the riscv-gnu-toolchain configure script :)

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Dec 22, 2024

I've made an interesting discovery. --disable-debug-info enables debug symbols. That is, it sets enable_debug_info to "no", which is considered a true value by the check here.

Seems to be inverted alright?

./configure --prefix=`pwd`/installed-tools
cp Makefile Makefile.default

./configure --prefix=`pwd`/installed-tools --disable-debug-info
cp Makefile Makefile.disable-debug-info

diff Makefile.disable-debug-info Makefile.default
18c18
< DEBUG_INFO := -g
---
> DEBUG_INFO :=

grep DEBUG_INFO Makefile.disable-debug-info
DEBUG_INFO := -g
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) -mcmodel=medlow

grep DEBUG_INFO Makefile.default
DEBUG_INFO :=
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) -mcmodel=medlow

@jefftrull jefftrull changed the title --disable-debug-info does nothing --disable-debug-info enables debug information Dec 22, 2024
@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Dec 22, 2024

Looks to me like maybe the option --disable-debug-info was provided in the past but then this was changed to --enable-debug-info but relevant PR/change left behind some configuration code that confuses the issue?

Maybe @kito-cheng, @cmuellner or @jeremybennett might know more about this?

Is --disable-debug-info a vestigial option that was accidentally left behind and the only option available should be --enable-debug-info? So that a "regular" configure and make builds the target libs without debug info and if such debug info is desired then one does configure ... --enable-debug-info?

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Dec 22, 2024

For now I think that you need to do this:

# Build libs without debug info
./configure --prefix=...

grep DEBUG_INFO Makefile
DEBUG_INFO :=
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) -mcmodel=medlow

# Build libs with debug info
./configure --prefix=... --enable-debug-info

grep DEBUG_INFO Makefile
DEBUG_INFO := -g
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO)  -mcmodel=medlow
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) -mcmodel=medlow

So, by default and unless explicitly requested otherwise, the libs are built without debug info.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Dec 22, 2024

And to build the toolchain binaries (that run on the cross development host system) with/without debug info:

# Build toolchain binaries with debug info
./configure --prefix=...
make

# Build toolchain binaries without debug info
./configure --prefix=...
make ASFLAGS=-g0 CFLAGS=-g0 CXXFLAGS=-g0

@TommyMurphyTM1234
Copy link
Collaborator

FWIW...

git clone https://github.com/riscv-collab/riscv-gnu-toolchain issue-1646
cd issue-1646

# Build 1: Toolchain host binaries with debug info/not stripped, target libs with debug info
./configure --prefix=`pwd`/installed-tools --enable-debug-info
make 
du -hd0 installed-tools
2.2G    installed-tools

# Build 2: Toolchain host binaries with debug info/not stripped, target libs without debug info
make distclean && rm -rf installed-tools
./configure --prefix=`pwd`/installed-tools
make 
du -hd0 installed-tools
2.1G    installed-tools

# Build 3: Toolchain host binaries without debug info/not stripped, target libs without debug info
make distclean && rm -rf installed-tools
make ASFLAGS==g0 CFLAGS=-g0 CXXFLAGS=-g0
du -hd0 installed-tools
493M    installed-tools

# Build 4: Toolchain host binaries without debug info/stripped, target libs without debug info
strip installed-tools/bin/*
strip: installed-tools/bin/riscv64-unknown-elf-gdb-add-index: file format not recognized
strip installed-tools/lib/*
strip: Warning: 'installed-tools/lib/bfd-plugins' is a directory
strip: Warning: 'installed-tools/lib/gcc' is a directory
strip: installed-tools/lib/libcc1.la: file format not recognized
du -hd0 installed-tools
467M    installed-tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants