0

I need to remove unused functions from a big C++ project. After reading a while I used this link: How can I know which parts in the code are never used?

I compile on RedHat using makefiles. I added to compiler the flags:
-Wall -Wconversion -ffunction-sections -fdata-sections
and to the linker the flags:
-Wl,-rpath,--demangle,--gc-sections,--print-gc-sections
For some annoying reason I receive the output after mangling even after using --demangle option. For example:

/usr/bin/ld: Removing unused section '.text._ZN8TRACABLED0Ev' in file 'CMakeFiles/oded.dir/oded.cpp.o' /usr/bin/ld: Removing unused section '.text._ZN8TRACABLED1Ev' in file 'CMakeFiles/oded.dir/oded.cpp.o'

So I have 6000 function names I need to unmangle and I cannot use extern C.

I can write a script to parse it and use c++filt, but Im looking for a solution that will make the linker unmangle the function by itself!

Anyone knows if such a solution exist?

Community
  • 1
  • 1
Oded Itzhaky
  • 445
  • 5
  • 16

1 Answers1

1

For some annoying reason I receive the output after mangling even after using --demangle option

From man ld:

--demangle[=style]
--no-demangle

These options control whether to demangle symbol names in
error messages and other output.

But these messages:

Removing unused section '.text._ZN8TRACABLED0Ev' in file

are not about symbol names. They are about section names, which just happen to sometimes include the symbol name. So this is working as documented.

Now, if you really wanted to do something about it, you could develop a linker patch to also demangle section names, and send it to GNU binutils maintainers.

But an easier option might be to simply pipe the messages you want to be demangled through c++filt. For example:

echo "Removing unused section '.text._ZN8TRACABLED0Ev' in file" |
  sed -e 's/_ZN/ _ZN/' | c++filt

produces:

Removing unused section '.text.  TRACABLE::~TRACABLE()' in file
Employed Russian
  • 199,314
  • 34
  • 295
  • 362