[PATCH] D17529: ELF: Implement ICF.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 17:11:32 PST 2016


ruiu created this revision.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.

This patch is in my queue for a long period of time, so I'd like
to flush this although it is not still compatible with most C++
programs.

This patch implements the same algorithm as LLD/COFF's ICF. I'm
not going to repeat the same description about how it works, so you
want to read the comment in ICF.cpp in this patch. This algorithm
should be more powerful than GNU gold ICF algorithm. It can even
merge mutually-recursive functions (which is harder than one might
think).

The lacking feature is "safe" version of ICF. This merges all
identical sections. That is not compatible with C/C++ language
requirement that two distinct functions must not have the address.
I think violation this rule breaks many C++ ABIs.

GNU gold implements so-called "safe ICF" that identifies functions
that are safe to merge by heuristics -- for example, gold think
that constructors are safe to merge because there is no way to
take an address of a constructor in C++. We have a different idea
which David Majnemer suggested, which is to add NOPs at beginning
of merged functions so that two or more pointers can have distinct
values. We can do whichever we want, but this patch does not
include neither one.

http://reviews.llvm.org/D17529

Files:
  ELF/CMakeLists.txt
  ELF/Config.h
  ELF/Driver.cpp
  ELF/ICF.cpp
  ELF/ICF.h
  ELF/InputFiles.cpp
  ELF/InputSection.cpp
  ELF/InputSection.h
  ELF/Options.td
  ELF/OutputSections.cpp
  ELF/Symbols.cpp
  ELF/Symbols.h
  ELF/Writer.cpp
  test/ELF/Inputs/icf2.s
  test/ELF/icf1.s
  test/ELF/icf2.s
  test/ELF/icf3.s
  test/ELF/icf4.s
  test/ELF/icf5.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17529.48761.patch
Type: text/x-patch
Size: 27931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160223/d2eba427/attachment.bin>


More information about the llvm-commits mailing list