[PECOFF] Only COMDAT symbols are allowed to be dead-stripped.
authorRui Ueyama <ruiu@google.com>
Fri, 18 Oct 2013 23:54:55 +0000 (23:54 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 18 Oct 2013 23:54:55 +0000 (23:54 +0000)
commit1ce8a0a8eded5a57a923fcb0bfb714797b066af2
treebf2709e9baaf06dbfa76f318bf04692bfe7eacdb
parentbe40554915e6f9535eacee40933145dea45775db
[PECOFF] Only COMDAT symbols are allowed to be dead-stripped.

We should dead-strip atoms only if they are created for COMDAT symbols. If we
remove non-COMDAT atoms from a binary, it will no longer be guaranteed that
the binary will work correctly.

In COFF, you can manipulate the order of section contents in the resulting
binary by section name. For example, if you have four sections
.data$unique_prefix_{a,b,c,d}, it's guaranteed that the contents of A, B, C,
and D will be consecutive in the resulting .data section in that order.
Thus, you can access B's and C's contents by incrementing a pointer pointing
to A until it reached to D. That's why we cannot dead-strip B or C even if
no one is directly referencing to them.

Some object files in the standard library actually use that technique.

llvm-svn: 193017
lld/lib/ReaderWriter/PECOFF/Atoms.h
lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/test/pecoff/grouped-sections.test