[Issue 9655] Two functions with identical implementations are allowed to have the same address

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 6 02:06:00 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9655


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #1 from bearophile_hugs at eml.cc 2013-03-06 02:05:52 PST ---
(In reply to comment #0)
> In regards to:
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=9623
> 
> Related C++ article "Can Two Functions Have the Same Address?"
> http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=561
> 
> This quote pretty much sells me:
> 
> --
> Additionally, Google's compiler team have experimented with Identical Code
> Folding (ICF) and reported that "[d]etailed experiments on the x86 platform
> show that ICF can reduce the text size [the program section in which functions'
> code is stored, DK] of some Google binaries, whose average text size is 50 MB,
> by up to 7%."
> --
> 
> We should settle the issue by updating the D spec to explicitly allow functions
> to have the same address.

1) What are the downsides of such folding in D?

2) Since recently, LLVM (used by LDC) folds identical functions if you use a
compiler switch. IF you use such switch, where the compiler sees two identical
functions, replaces one of them with just a jump to the other. So their address
is distinct, but the amount of wasted space in the binary is minimal.

3) Often templates generate not just identical functions, but functions that
differ only in a small part, for only few asm instructions. So a good D
compiler could try to split those functions in virtual chunks (maybe if the
parts are not inside a loop), keep only one copy of the shared part. I presume
this is not easy to do in general.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list