summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/ICF.cpp4
-rw-r--r--lld/test/ELF/icf9.s20
2 files changed, 22 insertions, 2 deletions
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 81c6a89e20d..c9d0c40ff8a 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -162,8 +162,8 @@ static bool isEligible(InputSection *S) {
// .init and .fini contains instructions that must be executed to
// initialize and finalize the process. They cannot and should not
// be merged.
- return S->Live && (S->Flags & SHF_ALLOC) && !(S->Flags & SHF_WRITE) &&
- S->Name != ".init" && S->Name != ".fini";
+ return S->Live && (S->Flags & SHF_ALLOC) && (S->Flags & SHF_EXECINSTR) &&
+ !(S->Flags & SHF_WRITE) && S->Name != ".init" && S->Name != ".fini";
}
// Split an equivalence class into smaller classes.
diff --git a/lld/test/ELF/icf9.s b/lld/test/ELF/icf9.s
new file mode 100644
index 00000000000..c5a532915cc
--- /dev/null
+++ b/lld/test/ELF/icf9.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+
+### Make sure that we do not merge data.
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
+
+# CHECK-NOT: selected .data.d1
+# CHECK-NOT: selected .data.d2
+
+.globl _start, d1, d2
+_start:
+ ret
+
+.section .data.f1, "a"
+d1:
+ .byte 1
+
+.section .data.f2, "a"
+d2:
+ .byte 1
OpenPOWER on IntegriCloud