ELF: Do not ICF sections named with a C identifier.

A user program may enumerate sections named with a C identifier using
__start_* and __stop_* symbols. We cannot ICF any such sections because
that could change program semantics.

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

llvm-svn: 333054
This commit is contained in:
Peter Collingbourne 2018-05-23 02:14:28 +00:00
parent fedae33efa
commit 7ab7f149b2
3 changed files with 17 additions and 2 deletions

View File

@ -188,6 +188,12 @@ static bool isEligible(InputSection *S) {
if (S->Name == ".init" || S->Name == ".fini")
return false;
// A user program may enumerate sections named with a C identifier using
// __start_* and __stop_* symbols. We cannot ICF any such sections because
// that could change program semantics.
if (isValidCIdentifier(S->Name))
return false;
return true;
}

View File

@ -0,0 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0
.section foo,"ax",@progbits,unique,0
.byte 42
.section foo,"ax",@progbits,unique,1
.byte 42

View File

@ -2,8 +2,8 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0
.section foo,"ax"
.section .foo,"ax"
.byte 42
.section bar,"ax"
.section .bar,"ax"
.byte 42