[PATCH] D39399: ELF: Correctly set edata if there are no .bss sections.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 29 15:32:15 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL316877: ELF: Correctly set edata if there are no .bss sections. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D39399?vs=120729&id=120759#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39399

Files:
  lld/trunk/ELF/Writer.cpp
  lld/trunk/test/ELF/edata-no-bss.s


Index: lld/trunk/test/ELF/edata-no-bss.s
===================================================================
--- lld/trunk/test/ELF/edata-no-bss.s
+++ lld/trunk/test/ELF/edata-no-bss.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t --gc-sections
+# RUN: llvm-objdump -t -section-headers %t | FileCheck %s
+
+# CHECK: .data         00000008 0000000000202000 DATA
+
+# CHECK: 0000000000202008         .data                 00000000 _edata
+
+.text
+.globl _start
+_start:
+.long .data - .
+
+.data
+.quad 0
+
+.globl _edata
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -915,37 +915,34 @@
       LastRO = P;
   }
 
-  // _end is the first location after the uninitialized data region.
-  if (Last) {
-    if (ElfSym::End1)
-      ElfSym::End1->Section = Last->LastSec;
-    if (ElfSym::End2)
-      ElfSym::End2->Section = Last->LastSec;
-  }
-
-  // _etext is the first location after the last read-only loadable segment.
   if (LastRO) {
+    // _etext is the first location after the last read-only loadable segment.
     if (ElfSym::Etext1)
       ElfSym::Etext1->Section = LastRO->LastSec;
     if (ElfSym::Etext2)
       ElfSym::Etext2->Section = LastRO->LastSec;
   }
 
-  // _edata points to the end of the last non SHT_NOBITS section.
-  if (LastRW) {
-    size_t I = 0;
-    for (; I < OutputSections.size(); ++I)
-      if (OutputSections[I] == LastRW->FirstSec)
-        break;
-
-    for (; I < OutputSections.size(); ++I)
-      if (OutputSections[I]->Type == SHT_NOBITS)
+  if (Last) {
+    // _edata points to the end of the last mapped initialized section.
+    OutputSection *Edata = nullptr;
+    for (OutputSection *OS : OutputSections) {
+      if (OS->Type != SHT_NOBITS)
+        Edata = OS;
+      if (OS == Last->LastSec)
         break;
+    }
 
     if (ElfSym::Edata1)
-      ElfSym::Edata1->Section = OutputSections[I - 1];
+      ElfSym::Edata1->Section = Edata;
     if (ElfSym::Edata2)
-      ElfSym::Edata2->Section = OutputSections[I - 1];
+      ElfSym::Edata2->Section = Edata;
+
+    // _end is the first location after the uninitialized data region.
+    if (ElfSym::End1)
+      ElfSym::End1->Section = Last->LastSec;
+    if (ElfSym::End2)
+      ElfSym::End2->Section = Last->LastSec;
   }
 
   if (ElfSym::Bss)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39399.120759.patch
Type: text/x-patch
Size: 2444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171029/1360be14/attachment.bin>


More information about the llvm-commits mailing list