[PATCH] D44376: [ELF] - Drop special flags for empty output sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 13 01:35:30 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327374: [ELF] - Drop special flags for empty output sections. (authored by grimar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44376?vs=137984&id=138134#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44376

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/empty-link-order.test


Index: lld/trunk/test/ELF/linkerscript/empty-link-order.test
===================================================================
--- lld/trunk/test/ELF/linkerscript/empty-link-order.test
+++ lld/trunk/test/ELF/linkerscript/empty-link-order.test
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=arm-arm-none-eabi -o %t.o < /dev/null
+
+SECTIONS {
+  .foo : {
+    bar = .;
+    *(.ARM.exidx*)
+  }
+}
+
+# RUN: ld.lld %t.o -o %t --script %s
+
+## Check we do not crash and do not set SHF_LINK_ORDER flag for .foo
+# RUN: llvm-readobj -s %t | FileCheck %s
+# CHECK:      Section {
+# CHECK:       Index:
+# CHECK:       Name: .foo
+# CHECK-NEXT:  Type: SHT_ARM_EXIDX
+# CHECK-NEXT:  Flags [
+# CHECK-NEXT:    SHF_ALLOC
+# CHECK-NEXT:  ]
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -813,7 +813,7 @@
   for (BaseCommand *Base : Sec.SectionCommands)
     if (!isa<InputSectionDescription>(*Base))
       return false;
-  return getInputSections(&Sec).empty();
+  return true;
 }
 
 void LinkerScript::adjustSectionsBeforeSorting() {
@@ -845,14 +845,18 @@
       continue;
 
     // A live output section means that some input section was added to it. It
-    // might have been removed (gc, or empty synthetic section), but we at least
-    // know the flags.
+    // might have been removed (if it was empty synthetic section), but we at
+    // least know the flags.
     if (Sec->Live)
-      Flags = Sec->Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR);
-    else
-      Sec->Flags = Flags;
+      Flags = Sec->Flags;
 
-    if (isDiscardable(*Sec)) {
+    // We do not want to keep any special flags for output section
+    // in case it is empty.
+    bool IsEmpty = getInputSections(Sec).empty();
+    if (IsEmpty)
+      Sec->Flags = Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR);
+
+    if (IsEmpty && isDiscardable(*Sec)) {
       Sec->Live = false;
       Cmd = nullptr;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44376.138134.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180313/19d44c5d/attachment.bin>


More information about the llvm-commits mailing list