[llvm-objcopy] Make removeSectionReferences batched
authorJordan Rupprecht <rupprecht@google.com>
Thu, 21 Feb 2019 16:45:42 +0000 (16:45 +0000)
committerJordan Rupprecht <rupprecht@google.com>
Thu, 21 Feb 2019 16:45:42 +0000 (16:45 +0000)
commit52d5781c8711c334c48f48ffdd1211331ce3a573
tree669ade256e5966f77af5f2cdcec37cc887282ced
parent12a21e4b69d4f156490cc82bee3d4b28368b4840
[llvm-objcopy] Make removeSectionReferences batched

Summary:
Removing a large number of sections from a file with a lot of symbols can have abysmal (i.e. O(n^2)) performance, e.g. when running `--only-section` to extract one section out of a large file.

This comes from iterating over all symbols in the symbol table each time we remove a section, to remove references to the section we just removed.
Instead, do just one pass of symbol removal by passing a hash set of all the sections we'd like to remove references to.

This fixes a regression when running llvm-objcopy -j <one section> on an object file with many sections and symbols -- on my machine, running `objcopy -j .keep_me huge-input.o /tmp/foo.o` takes .3s with GNU objcopy, 1.3s with an updated llvm-objcopy, and 7+ minutes with llvm-objcopy prior to this patch.

Reviewers: MaskRay, jhenderson, jakehehrlich, alexshap, espindola

Reviewed By: MaskRay, jhenderson

Subscribers: echristo, emaste, arichardson, mgrang, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58296

llvm-svn: 354597
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/ELF/Object.h