[PATCH] D43185: [MIPS] Mark .eh_frame as writable for PIC output

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 06:03:42 PST 2018


arichardson created this revision.
arichardson added reviewers: sdardis, atanasyan.
Herald added a subscriber: llvm-commits.

This is needed since we have a R_MIPS_64 relocation that needs to be
processed at runtime. This allows running LLD without -z notext.


Repository:
  rL LLVM

https://reviews.llvm.org/D43185

Files:
  lib/MC/MCObjectFileInfo.cpp
  test/MC/Mips/eh_frame-section-attrs.s


Index: test/MC/Mips/eh_frame-section-attrs.s
===================================================================
--- /dev/null
+++ test/MC/Mips/eh_frame-section-attrs.s
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o
+# RUN: llvm-readobj -r -s %t.o | FileCheck %s -check-prefix OBJECT
+# RUN: llvm-mc -filetype=obj -position-independent -triple=mips64-unknown-freebsd %s -o %t.o
+# RUN: llvm-readobj -r -s %t.o | FileCheck %s -check-prefixes OBJECT,PIC
+
+
+
+# OBJECT-LABEL:  Section {
+# OBJECT:         Name: .eh_frame
+# OBJECT-NEXT:    Type: SHT_PROGBITS (0x1)
+# OBJECT-NEXT:    Flags [
+# OBJECT-NEXT:      SHF_ALLOC (0x2)
+# For PIC we need to also emit SHF_WRITE since the relocation needs to be processed at runtime
+# PIC-NEXT:         SHF_WRITE (0x1)
+# OBJECT-NEXT:    ]
+
+# OBJECT-LABEL: Relocations [
+# OBJECT-NEXT:   Section ({{.+}}) .rela.eh_frame {
+# OBJECT-NEXT:     0x1C R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE .text 0x0
+# OBJECT-NEXT:   }
+# OBJECT-NEXT: ]
+
+func:
+.cfi_startproc
+lui	$3, 1
+.cfi_endproc
Index: lib/MC/MCObjectFileInfo.cpp
===================================================================
--- lib/MC/MCObjectFileInfo.cpp
+++ lib/MC/MCObjectFileInfo.cpp
@@ -465,6 +465,13 @@
   if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
     EHSectionFlags |= ELF::SHF_WRITE;
 
+  // This is (currently) also true for MIPS
+  // TODO: add a T.isMIPS()?
+  if (PositionIndependent &&
+      (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
+       T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el))
+    EHSectionFlags |= ELF::SHF_WRITE;
+
   // ELF
   BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
                                   ELF::SHF_WRITE | ELF::SHF_ALLOC);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43185.133845.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180212/550de47d/attachment.bin>


More information about the llvm-commits mailing list