[lld] r299528 - [ELF] - Define __bss_start symbol.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 03:03:26 PDT 2017


Author: grimar
Date: Wed Apr  5 05:03:25 2017
New Revision: 299528

URL: http://llvm.org/viewvc/llvm-project?rev=299528&view=rev
Log:
[ELF] - Define __bss_start symbol.

GNU linkers define __bss_start symbol.
Patch teaches LLD to do that. This is PR32051.

Below is part of standart ld.bfd script:

.data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  .bss            :
  {
Currently LLD can emit up to 3 .bss* sections as one of testcase shows.
Implementation inserts this symbol before first .bss* output section.

Differential revision: https://reviews.llvm.org/D30419

Added:
    lld/trunk/test/ELF/bss-start-common.s
Modified:
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=299528&r1=299527&r2=299528&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Apr  5 05:03:25 2017
@@ -28,6 +28,7 @@ using namespace llvm::ELF;
 using namespace lld;
 using namespace lld::elf;
 
+DefinedRegular *ElfSym::Bss;
 DefinedRegular *ElfSym::Etext;
 DefinedRegular *ElfSym::Etext2;
 DefinedRegular *ElfSym::Edata;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=299528&r1=299527&r2=299528&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Apr  5 05:03:25 2017
@@ -302,6 +302,9 @@ public:
 // Some linker-generated symbols need to be created as
 // DefinedRegular symbols.
 struct ElfSym {
+  // The content for __bss_start symbol.
+  static DefinedRegular *Bss;
+
   // The content for _etext and etext symbols.
   static DefinedRegular *Etext;
   static DefinedRegular *Etext2;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=299528&r1=299527&r2=299528&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Apr  5 05:03:25 2017
@@ -846,6 +846,10 @@ template <class ELFT> void Writer<ELFT>:
   // __ehdr_start is the location of ELF file headers.
   addOptionalRegular<ELFT>("__ehdr_start", Out::ElfHeader, 0, STV_HIDDEN);
 
+  // __bss_start is the location of .bss section.
+  ElfSym::Bss =
+      addOptionalRegular<ELFT>("__bss_start", Out::ElfHeader, 0, STV_DEFAULT);
+
   auto Define = [](StringRef S, DefinedRegular *&Sym1, DefinedRegular *&Sym2) {
     Sym1 = addOptionalRegular<ELFT>(S, Out::ElfHeader, 0, STV_DEFAULT);
     assert(S.startswith("_"));
@@ -1675,6 +1679,9 @@ template <class ELFT> void Writer<ELFT>:
   if (LastRW)
     Set(ElfSym::Edata, ElfSym::Edata2, LastRW->First, LastRW->p_filesz);
 
+  if (ElfSym::Bss)
+    ElfSym::Bss->Section = findSection(".bss");
+
   // Setup MIPS _gp_disp/__gnu_local_gp symbols which should
   // be equal to the _gp symbol's value.
   if (Config->EMachine == EM_MIPS) {

Added: lld/trunk/test/ELF/bss-start-common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/bss-start-common.s?rev=299528&view=auto
==============================================================================
--- lld/trunk/test/ELF/bss-start-common.s (added)
+++ lld/trunk/test/ELF/bss-start-common.s Wed Apr  5 05:03:25 2017
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t2
+# RUN: llvm-objdump -t -section-headers %t2 | FileCheck %s
+
+# CHECK: Sections:
+# CHECK: Idx Name          Size      Address          Type
+# CHECK:   2 .bss          00000004 0000000000201000 BSS
+# CHECK: SYMBOL TABLE:
+# CHECK: 0000000000201000  .bss 00000000 __bss_start
+
+.global __bss_start
+.text
+_start:
+.comm sym1,4,4




More information about the llvm-commits mailing list