This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Merging identical functions in GCC


Ian Lance Taylor wrote:
>I think Danny has a 75% implementation based on hashing the RTL for a
>section and using that to select the COMDAT section signature.

I don't think this is a good idea.  With different compiler options the
same RTL can generate different assembly instructions.  Consider the case
of compiling the same function multiple times with different names and
different CPU architectures selected.  You'd actually want the linker
to merge the functions that ended up having the same assembly, but not
the ones with the same RTL but different assembly.

Also, I don't think it's safe if you merge only functions in COMDAT
sections.

Consider:

	#include <assert.h>

	template <class T> T foo(T a) { return a; }
	template <class T> T bar(T a) { return a; }

	int
	main() {
		assert((int (*)(int)) foo<int> != (int (*)(int)) bar<int>);
	}

Both foo<int> and bar<int> get put in their own COMDAT section and their
RTL and assembly are the same, but it's not safe to merge them.

Simply merging identical COMDAT sections would have to be optional and
disabled by default as Michael Popov said at the start of this thread.
The only way I can see to do it safely would be to emit some sort
instruction not to merge a function when the compiler sees that its
address is taken.

					Ross Ridge


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]