[ELF] Fix References being ignored.
authorShankar Easwaran <shankare@codeaurora.org>
Sat, 21 Feb 2015 04:42:43 +0000 (04:42 +0000)
committerShankar Easwaran <shankare@codeaurora.org>
Sat, 21 Feb 2015 04:42:43 +0000 (04:42 +0000)
The ELFReader was skipping references for sections that contained relocations.

This fixes the bug.

llvm-svn: 230127

lld/lib/ReaderWriter/ELF/ELFFile.h
lld/test/elf/X86_64/mergesimilarstrings.test

index 7d2a4a3..6a74bd5 100644 (file)
@@ -930,8 +930,8 @@ ELFFile<ELFT>::createSectionAtom(const Elf_Shdr *section, StringRef sectionName,
   sym->st_shndx = 0;
   sym->st_value = 0;
   sym->st_size = 0;
-  auto *newAtom = new (_readerStorage) ELFDefinedAtom<ELFT>(
-      *this, "", sectionName, sym, section, content, 0, 0, _references);
+  auto *newAtom = createDefinedAtomAndAssignRelocations(
+      "", sectionName, sym, section, content, content);
   newAtom->setOrdinal(++_ordinal);
   return newAtom;
 }
index 5c868ac..3836f0b 100644 (file)
@@ -4,6 +4,8 @@
 # RUN: yaml2obj -format=elf %s > %t.o
 # RUN: lld -flavor gnu -target x86_64 %t.o --noinhibit-exec -o %t1.out
 # RUN: llvm-readobj -sections %t1.out | FileCheck %s
+# RUN: lld -flavor gnu -target x86_64 %t.o --noinhibit-exec -o %t2.out --output-filetype=yaml
+# RUN: FileCheck %s -check-prefix=CHECKRELOCS < %t2.out
 
 FileHeader:
   Class:           ELFCLASS64
@@ -38,3 +40,8 @@ Symbols:
 
 #CHECK:    Name: .rodata
 #CHECK:    Size: 18
+#CHECKRELOCS:   references:
+#CHECKRELOCS:     - kind:            R_X86_64_PC32
+#CHECKRELOCS:       offset:          7
+#CHECKRELOCS:       target:          .rodata
+#CHECKRELOCS:       addend:          -4