[lld] r189196 - [lld][ELF] process fini_array sections

Shankar Easwaran shankare at codeaurora.org
Sun Aug 25 11:05:12 PDT 2013


Author: shankare
Date: Sun Aug 25 13:05:12 2013
New Revision: 189196

URL: http://llvm.org/viewvc/llvm-project?rev=189196&view=rev
Log:
[lld][ELF] process fini_array sections

This change processes fini_array section in addition to processing
init_array sections. This also makes functions registered at compile
time for initialization and finalization to be run during execution

Added:
    lld/trunk/test/elf/X86_64/Inputs/initfini.c
    lld/trunk/test/elf/X86_64/Inputs/initfini.o
    lld/trunk/test/elf/X86_64/initfini.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Atoms.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
    lld/trunk/lib/ReaderWriter/ELF/File.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=189196&r1=189195&r2=189196&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Sun Aug 25 13:05:12 2013
@@ -326,6 +326,7 @@ public:
         ret = typeZeroFill;
       break;
     case llvm::ELF::SHT_INIT_ARRAY:
+    case llvm::ELF::SHT_FINI_ARRAY:
       ret = typeData;
       break;
     }
@@ -432,6 +433,7 @@ public:
       return _permissions = permRW_;
 
     case llvm::ELF::SHT_INIT_ARRAY:
+    case llvm::ELF::SHT_FINI_ARRAY:
       return _permissions = permRW_;
 
     default:

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=189196&r1=189195&r2=189196&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Sun Aug 25 13:05:12 2013
@@ -329,6 +329,7 @@ Layout::SectionOrder DefaultLayout<ELFT>
   case DefinedAtom::typeDataFast:
     return llvm::StringSwitch<Reference::Kind>(name)
         .StartsWith(".init_array", ORDER_INIT_ARRAY)
+        .StartsWith(".fini_array", ORDER_FINI_ARRAY)
         .Default(ORDER_DATA);
 
   case DefinedAtom::typeZeroFill:

Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=189196&r1=189195&r2=189196&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Sun Aug 25 13:05:12 2013
@@ -181,7 +181,9 @@ public:
       }
 
       // Create a sectionSymbols entry for every progbits section.
-      if (section->sh_type == llvm::ELF::SHT_PROGBITS)
+      if ((section->sh_type == llvm::ELF::SHT_PROGBITS) ||
+          (section->sh_type == llvm::ELF::SHT_INIT_ARRAY) ||
+          (section->sh_type == llvm::ELF::SHT_FINI_ARRAY))
         _sectionSymbols[section];
 
       if (section->sh_type == llvm::ELF::SHT_RELA) {

Added: lld/trunk/test/elf/X86_64/Inputs/initfini.c
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/initfini.c?rev=189196&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/Inputs/initfini.c (added)
+++ lld/trunk/test/elf/X86_64/Inputs/initfini.c Sun Aug 25 13:05:12 2013
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+void  __attribute__ ((constructor)) constructor() {
+ printf("%s\n", __FUNCTION__);
+}
+
+void __attribute__ ((destructor)) destructor() {
+ printf("%s\n", __FUNCTION__);
+}
+
+int main() {
+  return 0;
+}
+

Added: lld/trunk/test/elf/X86_64/Inputs/initfini.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/initfini.o?rev=189196&view=auto
==============================================================================
Binary files lld/trunk/test/elf/X86_64/Inputs/initfini.o (added) and lld/trunk/test/elf/X86_64/Inputs/initfini.o Sun Aug 25 13:05:12 2013 differ

Added: lld/trunk/test/elf/X86_64/initfini.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/initfini.test?rev=189196&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/initfini.test (added)
+++ lld/trunk/test/elf/X86_64/initfini.test Sun Aug 25 13:05:12 2013
@@ -0,0 +1,23 @@
+# This tests the functionality that lld is able to read
+# init_array/fini_array sections in the input ELF. This
+# corresponds to the the .init_array/.fini_array sections
+# in the output ELF. 
+
+RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/initfini.o  \
+RUN: --noinhibit-exec -emit-yaml -o %t
+RUN: FileCheck %s < %t
+
+CHECK:  - type:            data
+CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+CHECK:    section-name:    .init_array
+CHECK:    references:      
+CHECK:      - kind:            R_X86_64_64
+CHECK:        offset:          0
+CHECK:        target:          constructor
+CHECK:  - type:            data
+CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+CHECK:    section-name:    .fini_array
+CHECK:    references:      
+CHECK:      - kind:            R_X86_64_64
+CHECK:        offset:          0
+CHECK:        target:          destructor





More information about the llvm-commits mailing list