[lld] r228268 - [ELF] Dont discard sections in the input file.

Shankar Easwaran shankare at codeaurora.org
Wed Feb 4 18:56:07 PST 2015


Author: shankare
Date: Wed Feb  4 20:56:06 2015
New Revision: 228268

URL: http://llvm.org/viewvc/llvm-project?rev=228268&view=rev
Log:
[ELF] Dont discard sections in the input file.

The reader was discarding certain types of sections from the input file.

Added:
    lld/trunk/test/elf/note.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/ELFFile.h

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=228268&r1=228267&r2=228268&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Wed Feb  4 20:56:06 2015
@@ -479,12 +479,6 @@ std::error_code ELFFile<ELFT>::createAto
       continue;
     }
 
-    // Create a sectionSymbols entry for every progbits section.
-    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) {
       auto sHdr = _objFile->getSection(section.sh_info);
 
@@ -497,9 +491,7 @@ std::error_code ELFFile<ELFT>::createAto
 
       _relocationAddendReferences[*sectionName] = make_range(rai, rae);
       totalRelocs += std::distance(rai, rae);
-    }
-
-    if (section.sh_type == llvm::ELF::SHT_REL) {
+    } else if (section.sh_type == llvm::ELF::SHT_REL) {
       auto sHdr = _objFile->getSection(section.sh_info);
 
       auto sectionName = _objFile->getSectionName(sHdr);
@@ -511,6 +503,8 @@ std::error_code ELFFile<ELFT>::createAto
 
       _relocationReferences[*sectionName] = make_range(ri, re);
       totalRelocs += std::distance(ri, re);
+    } else {
+      _sectionSymbols[&section];
     }
   }
   _references.reserve(totalRelocs);
@@ -840,7 +834,7 @@ template <class ELFT> void ELFFile<ELFT>
 template <class ELFT>
 bool ELFFile<ELFT>::isIgnoredSection(const Elf_Shdr *section) {
   switch (section->sh_type) {
-  case llvm::ELF::SHT_NOTE:
+  case llvm::ELF::SHT_NULL:
   case llvm::ELF::SHT_STRTAB:
   case llvm::ELF::SHT_SYMTAB:
   case llvm::ELF::SHT_SYMTAB_SHNDX:

Added: lld/trunk/test/elf/note.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/note.test?rev=228268&view=auto
==============================================================================
--- lld/trunk/test/elf/note.test (added)
+++ lld/trunk/test/elf/note.test Wed Feb  4 20:56:06 2015
@@ -0,0 +1,49 @@
+# Check that the linker is not ignoring input sections.
+# RUN: yaml2obj -format=elf %s > %t.obj
+# RUN: lld -flavor gnu -target x86_64 %t.obj -o %t.exe --noinhibit-exec
+# RUN: llvm-objdump -h %t.exe | FileCheck %s
+
+# CHECK: {{[0-9]+}} .note
+
+---
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  OSABI:           ELFOSABI_GNU
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         ''
+  - Name:            .data
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000004
+    Content:         ''
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000004
+    Content:         ''
+  - Name:            .note
+    Type:            SHT_NOTE
+    AddressAlign:    0x0000000000000001
+    Content:         '00'
+Symbols:
+  Local:
+    - Name:            .text
+      Type:            STT_SECTION
+      Section:         .text
+    - Name:            .data
+      Type:            STT_SECTION
+      Section:         .data
+    - Name:            .bss
+      Type:            STT_SECTION
+      Section:         .bss
+    - Name:            .note
+      Type:            STT_SECTION
+      Section:         .note
+...





More information about the llvm-commits mailing list