[lld] r328624 - [ELF] Disable ICF for synthetic sections

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 27 07:10:07 PDT 2018


Author: anng
Date: Tue Mar 27 07:10:07 2018
New Revision: 328624

URL: http://llvm.org/viewvc/llvm-project?rev=328624&view=rev
Log:
[ELF] Disable ICF for synthetic sections

The Data member of synthetic section's is not valid and empty. The Data
member is required to be valid by ICF as it is used by ICF to determine
the equality of section contents. Therefore, exclude synthetic sections
from ICF.

Fixes bug PR36910.

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

Modified:
    lld/trunk/ELF/ICF.cpp
    lld/trunk/test/ELF/icf-merged-sections.s

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=328624&r1=328623&r2=328624&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue Mar 27 07:10:07 2018
@@ -77,6 +77,7 @@
 #include "Config.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
+#include "SyntheticSections.h"
 #include "lld/Common/Threads.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/BinaryFormat/ELF.h"
@@ -166,6 +167,12 @@ static bool isEligible(InputSection *S)
   if (!(S->Flags & SHF_EXECINSTR) && !Config->IgnoreDataAddressEquality)
     return false;
 
+  // Don't merge synthetic sections as their Data member is not valid and empty.
+  // The Data member needs to be valid for ICF as it is used by ICF to determine
+  // the equality of section contents.
+  if (isa<SyntheticSection>(S))
+    return false;
+
   // .init and .fini contains instructions that must be executed to
   // initialize and finalize the process. They cannot and should not
   // be merged.

Modified: lld/trunk/test/ELF/icf-merged-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf-merged-sections.s?rev=328624&r1=328623&r2=328624&view=diff
==============================================================================
--- lld/trunk/test/ELF/icf-merged-sections.s (original)
+++ lld/trunk/test/ELF/icf-merged-sections.s Tue Mar 27 07:10:07 2018
@@ -1,20 +1,28 @@
 # REQUIRES: x86
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck %s --check-prefix ICF
-# RUN: llvm-objdump -s -d -print-imm-hex %t | FileCheck %s
+# RUN: ld.lld %t.o -o %t --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck -allow-empty --check-prefix=NOICF %s
+# RUN: llvm-readobj -s -section-data %t | FileCheck %s
 
-# ICF: selected section <internal>:(.rodata)
-# ICF-NEXT: removing identical section <internal>:(.rodata)
+# Check that merge synthetic sections are not merged by ICF.
 
-# CHECK: {{^}}.text:
-# CHECK-NEXT: movq 0x[[ADDR:[0-9a-f]+]], %rax
-# CHECK-NEXT: movq 0x[[ADDR]], %rax
-# CHECK: Contents of section .rodata:
-# CHECK-NEXT: 2a000000 00000000 67452301 10325476
+# NOICF-NOT: selected section <internal>:(.rodata)
 
-.section .rodata, "a"
-  .quad 42
+# CHECK:      Name: .rodata
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT:   SHF_ALLOC
+# CHECK-NEXT:   SHF_MERGE
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size: 16
+# CHECK-NEXT: Link:
+# CHECK-NEXT: Info:
+# CHECK-NEXT: AddressAlignment: 8
+# CHECK-NEXT: EntrySize: 0
+# CHECK-NEXT: SectionData (
+# CHECK-NEXT:   0000: 67452301 10325476 67452301 10325476
 
 .section .rodata.cst4,"aM", at progbits,4
 rodata4:
@@ -27,7 +35,3 @@ rodata4:
 rodata8:
   .long 0x01234567
   .long 0x76543210
-
-.section .text,"ax"
-  movq rodata4, %rax
-  movq rodata8, %rax




More information about the llvm-commits mailing list