[PATCH] D13104: Mips - Mark the section .eh_frame as writeable for pic

Dean De Leo via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 09:24:57 PDT 2015


dean created this revision.
dean added reviewers: grosbach, dsanders, logan, theraven.
dean added a subscriber: llvm-commits.
dean set the repository for this revision to rL LLVM.
Herald added subscribers: danalbert, tberghammer.

This patch aims to solve the issue of loading libraries having an .eh_frame with relocations in android mips/mips64 platforms. The problem has been originally seen in the vanilla aosp mips64 emulator, when emitting objects with the section .eh_frame, then the mclinker shipped within the AOSP issues the warning ``creating a DT_TEXTREL in a shared object'' when creating a shared library out of the object file, while the dynamic linker fails to load the created library issuing the error: ``dlopen failed: text relocations (DT_TEXTREL) found in 64-bit ELF file''. The warning by the linker is issued for both mips32 & mips64, but for mips32 the library is however successfully loaded by the emulator.
Noting that the same problem does not show up when utilising the gnu linker, a bug has been reported to the mclinker community [1]. It turned out that a conceptually similar patch has been merged for the LLVM fork part of the Android NDK [2] and this problem does not occur when using the NDK toolchain, but only with the LLVM libraries inside Android. It has also been pointed out that the GNU linker is able to transform the absolute addresses in the .eh_frame in relative ones, while this functionality is not currently provided by the mclinker [3].  
As a way to address the issue, this patch marks the section .eh_frame as writeable in ELF objects for mips/mips64, so that required relocations can be applied by the dynamic linker at runtime. This resembles the behaviour in the patch in the Android NDK, except that in the NDK is the section for the exception handlers the one marked, while in this case the problem is with .eh_frame. I do not know the rationale for this difference. 

References:
[1] Bug report for the MClinker: https://groups.google.com/forum/#!topic/mclinker/9eJJGDjIwy4
[2] Andrew Hsieh patch for the NDK: https://android.googlesource.com/toolchain/llvm/+/48604b20a5daaa114c9cad67f1811c321ec0d947%5E!/
[3] Conversion of absolute FDE relocations into relative ones, MClinker mailing list -  https://groups.google.com/forum/#!topic/mclinker/mpqg4lFjlfE

Repository:
  rL LLVM

http://reviews.llvm.org/D13104

Files:
  lib/MC/MCObjectFileInfo.cpp

Index: lib/MC/MCObjectFileInfo.cpp
===================================================================
--- lib/MC/MCObjectFileInfo.cpp
+++ lib/MC/MCObjectFileInfo.cpp
@@ -246,6 +246,8 @@
 }
 
 void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
+  bool eh_frame_writable = false;
+
   switch (T.getArch()) {
   case Triple::mips:
   case Triple::mipsel:
@@ -338,6 +340,15 @@
                     dwarf::DW_EH_PE_sdata4;
     // We don't support PC-relative LSDA references in GAS so we use the default
     // DW_EH_PE_absptr for those.
+
+    // The section .eh_frame exhibits absolute addresses which require fixups.
+    // While the gnu linker can transform them in relative references at
+    // linking time, at the moment the mclinker does not provide this
+    // functionality. Setting the section as writable allows the fixups to be
+    // resolved at run time.
+    if(RelocM == Reloc::PIC_){
+        eh_frame_writable = true;
+    }
     break;
   case Triple::ppc64:
   case Triple::ppc64le:
@@ -402,6 +413,9 @@
     else
       EHSectionFlags |= ELF::SHF_WRITE;
   }
+  if (eh_frame_writable){
+    EHSectionFlags |= ELF::SHF_WRITE;
+  }
 
   // ELF
   BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13104.35510.patch
Type: text/x-patch
Size: 1233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150923/af6c4327/attachment.bin>


More information about the llvm-commits mailing list