]> granicus.if.org Git - llvm/commitdiff
MC: ensure that we have a section before accessing it
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 22 Nov 2016 04:32:54 +0000 (04:32 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 22 Nov 2016 04:32:54 +0000 (04:32 +0000)
We would attempt to access the symbol section without ensuring that the symbol
was not absolute.  When the assembler referenced relocation is not evaluated to
the absolute, but when we record the relocation, we would query the section.
Because the symbol is absolute, it does not have a section associated with it,
triggering an assertion.  Just be more careful about the access of the section.

Addresses PR31064!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287619 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ARM/ehabi-personality-abs.s [new file with mode: 0644]

index b115aabc8affb835c19c033c227e75ec61d04cc5..a8c88dda69362e50fd9ee90bc0693c1caa5df33a 100644 (file)
@@ -568,25 +568,27 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
   // If we change such a relocation to use the section, the linker would think
   // that it pointed to another string and subtracting 42 at runtime will
   // produce the wrong value.
-  auto &Sec = cast<MCSectionELF>(Sym->getSection());
-  unsigned Flags = Sec.getFlags();
-  if (Flags & ELF::SHF_MERGE) {
-    if (C != 0)
-      return true;
+  if (Sym->isInSection()) {
+    auto &Sec = cast<MCSectionELF>(Sym->getSection());
+    unsigned Flags = Sec.getFlags();
+    if (Flags & ELF::SHF_MERGE) {
+      if (C != 0)
+        return true;
 
-    // It looks like gold has a bug (http://sourceware.org/PR16794) and can
-    // only handle section relocations to mergeable sections if using RELA.
-    if (!hasRelocationAddend())
+      // It looks like gold has a bug (http://sourceware.org/PR16794) and can
+      // only handle section relocations to mergeable sections if using RELA.
+      if (!hasRelocationAddend())
+        return true;
+    }
+
+    // Most TLS relocations use a got, so they need the symbol. Even those that
+    // are just an offset (@tpoff), require a symbol in gold versions before
+    // 5efeedf61e4fe720fd3e9a08e6c91c10abb66d42 (2014-09-26) which fixed
+    // http://sourceware.org/PR16773.
+    if (Flags & ELF::SHF_TLS)
       return true;
   }
 
-  // Most TLS relocations use a got, so they need the symbol. Even those that
-  // are just an offset (@tpoff), require a symbol in gold versions before
-  // 5efeedf61e4fe720fd3e9a08e6c91c10abb66d42 (2014-09-26) which fixed
-  // http://sourceware.org/PR16773.
-  if (Flags & ELF::SHF_TLS)
-    return true;
-
   // If the symbol is a thumb function the final relocation must set the lowest
   // bit. With a symbol that is done by just having the symbol have that bit
   // set, so we would lose the bit if we relocated with the section.
diff --git a/test/MC/ARM/ehabi-personality-abs.s b/test/MC/ARM/ehabi-personality-abs.s
new file mode 100644 (file)
index 0000000..fd8bf73
--- /dev/null
@@ -0,0 +1,13 @@
+@ RUN: llvm-mc -triple armv7-linux -filetype obj -o - %s | llvm-objdump -triple armv7 -D -r - | FileCheck %s
+
+       .text
+
+__aeabi_unwind_cpp_pr0 = 0xdeadbeef
+
+f:
+       .fnstart
+       bx lr
+       .fnend
+
+@ CHECK: R_ARM_NONE __aeabi_unwind_cpp_pr0
+