<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 5, 2015 at 6:16 PM, Michael J. Spencer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mspencer<br>
Date: Mon Oct  5 20:16:17 2015<br>
New Revision: 249367<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249367&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249367&view=rev</a><br>
Log:<br>
[elf2] Add __preinit_array, and __fini_array start and end symbols.<br>
<br>
Added:<br>
    lld/trunk/test/elf2/pre_init_fini_array.s<br>
      - copied, changed from r249365, lld/trunk/test/elf2/init_array.s<br>
    lld/trunk/test/elf2/pre_init_fini_array_missing.s<br>
Removed:<br>
    lld/trunk/test/elf2/init_array.s<br>
    lld/trunk/test/elf2/init_array_missing.s<br>
Modified:<br>
    lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249367&r1=249366&r2=249367&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249367&r1=249366&r2=249367&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Mon Oct  5 20:16:17 2015<br>
@@ -329,13 +329,24 @@ template <class ELFT> void Writer<ELFT>:<br>
   DynamicSec.FiniArraySec =<br>
       Map.lookup({".fini_array", SHT_FINI_ARRAY, SHF_WRITE | SHF_ALLOC});<br>
<br>
-  if (OutputSection<ELFT> *OS = DynamicSec.InitArraySec) {<br>
-    Symtab.addSyntheticSym<ELFT>("__init_array_start", *OS, 0);<br>
-    Symtab.addSyntheticSym<ELFT>("__init_array_end", *OS, OS->getSize());<br>
-  } else {<br>
-    Symtab.addIgnoredSym<ELFT>("__init_array_start");<br>
-    Symtab.addIgnoredSym<ELFT>("__init_array_end");<br>
-  }<br>
+  auto addStartEnd = [&Symtab](StringRef StartName, StringRef EndName,<br>
+    OutputSection<ELFT> *OS) {<br>
+    if (OS) {<br>
+      Symtab.addSyntheticSym<ELFT>(StartName, *OS, 0);<br>
+      Symtab.addSyntheticSym<ELFT>(EndName, *OS, OS->getSize());<br>
+    }<br>
+    else {<br></blockquote><div><br></div><div>format</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      Symtab.addIgnoredSym<ELFT>(StartName);<br>
+      Symtab.addIgnoredSym<ELFT>(EndName);<br>
+    }<br>
+  };<br>
+<br>
+  addStartEnd("__preinit_array_start", "__preinit_array_end",<br>
+    DynamicSec.PreInitArraySec);<br>
+  addStartEnd("__init_array_start", "__init_array_end",<br>
+    DynamicSec.InitArraySec);<br>
+  addStartEnd("__fini_array_start", "__fini_array_end",<br>
+    DynamicSec.FiniArraySec);<br>
<br>
   // FIXME: Try to avoid the extra walk over all global symbols.<br>
   std::vector<DefinedCommon<ELFT> *> CommonSymbols;<br>
<br>
Removed: lld/trunk/test/elf2/init_array.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array.s?rev=249366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array.s?rev=249366&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/init_array.s (original)<br>
+++ lld/trunk/test/elf2/init_array.s (removed)<br>
@@ -1,90 +0,0 @@<br>
-// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
-// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2<br>
-// RUN: lld -flavor gnu2 %t2 -o t2.so -shared<br>
-// RUN: lld -flavor gnu2 %t t2.so -o %t2<br>
-// RUN: llvm-readobj -symbols -sections -dynamic-table %t2 | FileCheck %s<br>
-// RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM %s<br>
-// REQUIRES: x86<br>
-<br>
-.globl _start<br>
-_start:<br>
-  call __init_array_start<br>
-  call __init_array_end<br>
-<br>
-<br>
-.section .init_array,"aw",@init_array<br>
-  .quad 0<br>
-<br>
-.section .preinit_array,"aw",@preinit_array<br>
-        .quad 0<br>
-        .byte 0<br>
-<br>
-.section .fini_array,"aw",@fini_array<br>
-        .quad 0<br>
-        .short 0<br>
-<br>
-// CHECK:      Name: .init_array<br>
-// CHECK-NEXT: Type: SHT_INIT_ARRAY<br>
-// CHECK-NEXT: Flags [<br>
-// CHECK-NEXT:   SHF_ALLOC<br>
-// CHECK-NEXT:   SHF_WRITE<br>
-// CHECK-NEXT: ]<br>
-// CHECK-NEXT: Address: [[INIT_ADDR:.*]]<br>
-// CHECK-NEXT: Offset:<br>
-// CHECK-NEXT: Size: [[INIT_SIZE:.*]]<br>
-<br>
-<br>
-// CHECK:     Name: .preinit_array<br>
-// CHECK-NEXT: Type: SHT_PREINIT_ARRAY<br>
-// CHECK-NEXT: Flags [<br>
-// CHECK-NEXT:   SHF_ALLOC<br>
-// CHECK-NEXT:   SHF_WRITE<br>
-// CHECK-NEXT:    ]<br>
-// CHECK-NEXT: Address: [[PREINIT_ADDR:.*]]<br>
-// CHECK-NEXT: Offset:<br>
-// CHECK-NEXT: Size: [[PREINIT_SIZE:.*]]<br>
-<br>
-<br>
-// CHECK:      Name: .fini_array<br>
-// CHECK-NEXT: Type: SHT_FINI_ARRAY<br>
-// CHECK-NEXT: Flags [<br>
-// CHECK-NEXT:   SHF_ALLOC<br>
-// CHECK-NEXT:   SHF_WRITE<br>
-// CHECK-NEXT: ]<br>
-// CHECK-NEXT: Address: [[FINI_ADDR:.*]]<br>
-// CHECK-NEXT: Offset:<br>
-// CHECK-NEXT: Size: [[FINI_SIZE:.*]]<br>
-<br>
-// CHECK:        Name: __init_array_end<br>
-// CHECK-NEXT:   Value: 0x13008<br>
-// CHECK-NEXT:   Size: 0<br>
-// CHECK-NEXT:   Binding: Local<br>
-// CHECK-NEXT:   Type: None<br>
-// CHECK-NEXT:   Other: 0<br>
-// CHECK-NEXT:   Section: .init_array<br>
-// CHECK-NEXT: }<br>
-// CHECK-NEXT: Symbol {<br>
-// CHECK-NEXT:   Name: __init_array_start<br>
-// CHECK-NEXT:   Value: [[INIT_ADDR]]<br>
-// CHECK-NEXT:   Size: 0<br>
-// CHECK-NEXT:   Binding: Local<br>
-// CHECK-NEXT:   Type: None<br>
-// CHECK-NEXT:   Other: 0<br>
-// CHECK-NEXT:   Section: .init_array<br>
-// CHECK-NEXT: }<br>
-<br>
-<br>
-// CHECK: DynamicSection<br>
-// CHECK: PREINIT_ARRAY        [[PREINIT_ADDR]]<br>
-// CHECK: PREINIT_ARRAYSZ      [[PREINIT_SIZE]] (bytes)<br>
-// CHECK: INIT_ARRAY           [[INIT_ADDR]]<br>
-// CHECK: INIT_ARRAYSZ         [[INIT_SIZE]] (bytes)<br>
-// CHECK: FINI_ARRAY           [[FINI_ADDR]]<br>
-// CHECK: FINI_ARRAYSZ         [[FINI_SIZE]] (bytes)<br>
-<br>
-<br>
-// 0x13000 - (0x12000 + 5) = 4091<br>
-// 0x13008 - (0x12005 + 5) = 4094<br>
-// DISASM:      _start:<br>
-// DISASM-NEXT:   12000:  e8 fb 0f 00 00  callq  4091<br>
-// DISASM-NEXT:   12005:  e8 fe 0f 00 00  callq  4094<br>
<br>
Removed: lld/trunk/test/elf2/init_array_missing.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array_missing.s?rev=249366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/init_array_missing.s?rev=249366&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/init_array_missing.s (original)<br>
+++ lld/trunk/test/elf2/init_array_missing.s (removed)<br>
@@ -1,18 +0,0 @@<br>
-// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
-// RUN: lld -flavor gnu2 %t -o %t2<br>
-// RUN: llvm-objdump -d %t2 | FileCheck %s<br>
-// REQUIRES: x86<br>
-<br>
-.globl _start<br>
-_start:<br>
-  call __init_array_start<br>
-  call __init_array_end<br>
-<br>
-// With no .init_array section the symbols resolve to 0<br>
-// 0 - (0x11000 + 5) = -69637<br>
-// 0 - (0x11005 + 5) = -69642<br>
-<br>
-// CHECK: Disassembly of section .text:<br>
-// CHECK-NEXT:  _start:<br>
-// CHECK-NEXT:   11000:        e8 fb ef fe ff  callq   -69637<br>
-// CHECK-NEXT:   11005:        e8 f6 ef fe ff  callq   -69642<br>
<br>
Copied: lld/trunk/test/elf2/pre_init_fini_array.s (from r249365, lld/trunk/test/elf2/init_array.s)<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array.s?p2=lld/trunk/test/elf2/pre_init_fini_array.s&p1=lld/trunk/test/elf2/init_array.s&r1=249365&r2=249367&rev=249367&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array.s?p2=lld/trunk/test/elf2/pre_init_fini_array.s&p1=lld/trunk/test/elf2/init_array.s&r1=249365&r2=249367&rev=249367&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/init_array.s (original)<br>
+++ lld/trunk/test/elf2/pre_init_fini_array.s Mon Oct  5 20:16:17 2015<br>
@@ -8,8 +8,12 @@<br>
<br>
 .globl _start<br>
 _start:<br>
+  call __preinit_array_start<br>
+  call __preinit_array_end<br>
   call __init_array_start<br>
   call __init_array_end<br>
+  call __fini_array_start<br>
+  call __fini_array_end<br>
<br>
<br>
 .section .init_array,"aw",@init_array<br>
@@ -55,7 +59,25 @@ _start:<br>
 // CHECK-NEXT: Offset:<br>
 // CHECK-NEXT: Size: [[FINI_SIZE:.*]]<br>
<br>
-// CHECK:        Name: __init_array_end<br>
+// CHECK:        Name: __fini_array_end<br>
+// CHECK-NEXT:   Value: 0x1301B<br>
+// CHECK-NEXT:   Size: 0<br>
+// CHECK-NEXT:   Binding: Local<br>
+// CHECK-NEXT:   Type: None<br>
+// CHECK-NEXT:   Other: 0<br>
+// CHECK-NEXT:   Section: .fini_array<br>
+// CHECK-NEXT: }<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT:   Name: __fini_array_start<br>
+// CHECK-NEXT:   Value: [[FINI_ADDR]]<br>
+// CHECK-NEXT:   Size: 0<br>
+// CHECK-NEXT:   Binding: Local<br>
+// CHECK-NEXT:   Type: None<br>
+// CHECK-NEXT:   Other: 0<br>
+// CHECK-NEXT:   Section: .fini_array<br>
+// CHECK-NEXT: }<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT:   Name: __init_array_end<br>
 // CHECK-NEXT:   Value: 0x13008<br>
 // CHECK-NEXT:   Size: 0<br>
 // CHECK-NEXT:   Binding: Local<br>
@@ -72,7 +94,24 @@ _start:<br>
 // CHECK-NEXT:   Other: 0<br>
 // CHECK-NEXT:   Section: .init_array<br>
 // CHECK-NEXT: }<br>
-<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT:   Name: __preinit_array_end<br>
+// CHECK-NEXT:   Value: 0x13011<br>
+// CHECK-NEXT:   Size: 0<br>
+// CHECK-NEXT:   Binding: Local<br>
+// CHECK-NEXT:   Type: None<br>
+// CHECK-NEXT:   Other: 0<br>
+// CHECK-NEXT:   Section: .preinit_array<br>
+// CHECK-NEXT: }<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT:   Name: __preinit_array_start<br>
+// CHECK-NEXT:   Value: [[PREINIT_ADDR]]<br>
+// CHECK-NEXT:   Size: 0<br>
+// CHECK-NEXT:   Binding: Local<br>
+// CHECK-NEXT:   Type: None<br>
+// CHECK-NEXT:   Other: 0<br>
+// CHECK-NEXT:   Section: .preinit_array<br>
+// CHECK-NEXT: }<br>
<br>
 // CHECK: DynamicSection<br>
 // CHECK: PREINIT_ARRAY        [[PREINIT_ADDR]]<br>
@@ -83,8 +122,16 @@ _start:<br>
 // CHECK: FINI_ARRAYSZ         [[FINI_SIZE]] (bytes)<br>
<br>
<br>
-// 0x13000 - (0x12000 + 5) = 4091<br>
-// 0x13008 - (0x12005 + 5) = 4094<br>
+// 0x13008 - (0x12000 + 5) = 4099<br>
+// 0x13011 - (0x12005 + 5) = 4103<br>
+// 0x13000 - (0x1200a + 5) = 4081<br>
+// 0x13008 - (0x1200f + 5) = 4084<br>
+// 0x13011 - (0x12014 + 5) = 4088<br>
+// 0x1301B - (0x12019 + 5) = 4093<br>
 // DISASM:      _start:<br>
-// DISASM-NEXT:   12000:  e8 fb 0f 00 00  callq  4091<br>
-// DISASM-NEXT:   12005:  e8 fe 0f 00 00  callq  4094<br>
+// DISASM-NEXT:   12000:  e8 {{.*}}  callq  4099<br>
+// DISASM-NEXT:   12005:  e8 {{.*}}  callq  4103<br>
+// DISASM-NEXT:   1200a:  e8 {{.*}}  callq  4081<br>
+// DISASM-NEXT:   1200f:  e8 {{.*}}  callq  4084<br>
+// DISASM-NEXT:   12014:  e8 {{.*}}  callq  4088<br>
+// DISASM-NEXT:   12019:  e8 {{.*}}  callq  4093<br>
<br>
Added: lld/trunk/test/elf2/pre_init_fini_array_missing.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array_missing.s?rev=249367&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/pre_init_fini_array_missing.s?rev=249367&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/pre_init_fini_array_missing.s (added)<br>
+++ lld/trunk/test/elf2/pre_init_fini_array_missing.s Mon Oct  5 20:16:17 2015<br>
@@ -0,0 +1,30 @@<br>
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
+// RUN: lld -flavor gnu2 %t -o %t2<br>
+// RUN: llvm-objdump -d %t2 | FileCheck %s<br>
+// REQUIRES: x86<br>
+<br>
+.globl _start<br>
+_start:<br>
+  call __preinit_array_start<br>
+  call __preinit_array_end<br>
+  call __init_array_start<br>
+  call __init_array_end<br>
+  call __fini_array_start<br>
+  call __fini_array_end<br>
+<br>
+// With no .init_array section the symbols resolve to 0<br>
+// 0 - (0x11000 + 5) = -69637<br>
+// 0 - (0x11005 + 5) = -69642<br>
+// 0 - (0x1100a + 5) = -69647<br>
+// 0 - (0x1100f + 5) = -69652<br>
+// 0 - (0x11014 + 5) = -69657<br>
+// 0 - (0x11019 + 5) = -69662<br>
+<br>
+// CHECK: Disassembly of section .text:<br>
+// CHECK-NEXT:  _start:<br>
+// CHECK-NEXT:   11000:    e8 fb ef fe ff     callq    -69637<br>
+// CHECK-NEXT:   11005:    e8 f6 ef fe ff     callq    -69642<br>
+// CHECK-NEXT:   1100a:    e8 f1 ef fe ff     callq    -69647<br>
+// CHECK-NEXT:   1100f:    e8 ec ef fe ff     callq    -69652<br>
+// CHECK-NEXT:   11014:    e8 e7 ef fe ff     callq    -69657<br>
+// CHECK-NEXT:   11019:    e8 e2 ef fe ff     callq    -69662<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>