[PATCH] Fix Android MIPS exception personality encoding.

Logan Chien tzuhsiang.chien at gmail.com
Wed May 21 06:28:53 PDT 2014


Ping?

This commit fixes the linking error for MIPS (on Android) when exception is
enabled.  Without this change, the linker will stop with error unless
-Wl,--no-fatal-error is given.  Besides, in some early Android MIPS
devices, this issue will even cause SEGV due to the write access to the
protected text section.

Is this OK to commit?   Thanks.

Logan


On Tue, May 20, 2014 at 12:57 AM, Logan Chien <tzuhsiang.chien at gmail.com>wrote:

> Hi ahatanak,
>
> Android MIPS executable loader prohibits the relocation
> in the read-only section.  Thus, we have to use
> DW_EH_PE_indirect instead.
>
> http://reviews.llvm.org/D3828
>
> Files:
>   lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
>   lib/CodeGen/TargetLoweringObjectFileImpl.cpp
>   lib/MC/MCObjectFileInfo.cpp
>   test/CodeGen/Mips/ehframe-indirect.ll
>
> Index: lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
> ===================================================================
> --- lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
> +++ lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
> @@ -59,7 +59,8 @@
>
>    unsigned PerEncoding = TLOF.getPersonalityEncoding();
>
> -  if ((PerEncoding & 0x70) != dwarf::DW_EH_PE_pcrel)
> +  if ((PerEncoding & 0x70) != dwarf::DW_EH_PE_pcrel &&
> +      (PerEncoding & 0x80) != dwarf::DW_EH_PE_indirect)
>      return;
>
>    // Emit references to all used personality functions
> Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> ===================================================================
> --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> @@ -48,16 +48,13 @@
>      const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
>      MachineModuleInfo *MMI) const {
>    unsigned Encoding = getPersonalityEncoding();
> -  switch (Encoding & 0x70) {
> -  default:
> -    report_fatal_error("We do not support this DWARF encoding yet!");
> -  case dwarf::DW_EH_PE_absptr:
> -    return TM.getSymbol(GV, Mang);
> -  case dwarf::DW_EH_PE_pcrel: {
> +  if ((Encoding & 0x70) == dwarf::DW_EH_PE_pcrel ||
> +      (Encoding & 0x80) == dwarf::DW_EH_PE_indirect)
>      return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
>                                            TM.getSymbol(GV,
> Mang)->getName());
> -  }
> -  }
> +  if ((Encoding & 0x70) == dwarf::DW_EH_PE_absptr)
> +    return TM.getSymbol(GV, Mang);
> +  report_fatal_error("We do not support this DWARF encoding yet!");
>  }
>
>  void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer
> &Streamer,
> Index: lib/MC/MCObjectFileInfo.cpp
> ===================================================================
> --- lib/MC/MCObjectFileInfo.cpp
> +++ lib/MC/MCObjectFileInfo.cpp
> @@ -319,6 +319,15 @@
>        TTypeEncoding = dwarf::DW_EH_PE_absptr;
>      }
>      break;
> +  case Triple::mipsel:
> +    if (T.getEnvironment() == Triple::Android) {
> +      // For Android, we have to use indirect reference to personality
> +      // function; otherwise, some warning will be raised during link
> time.
> +      // This will even cause some SEGV in the loader on some early
> Android
> +      // MIPS devices.
> +      PersonalityEncoding = dwarf::DW_EH_PE_indirect;
> +    }
> +    break;
>    case Triple::ppc64:
>    case Triple::ppc64le:
>      PersonalityEncoding = dwarf::DW_EH_PE_indirect |
> dwarf::DW_EH_PE_pcrel |
> Index: test/CodeGen/Mips/ehframe-indirect.ll
> ===================================================================
> --- /dev/null
> +++ test/CodeGen/Mips/ehframe-indirect.ll
> @@ -0,0 +1,33 @@
> +; RUN: llc -mtriple=mipsel-linux-android < %s | FileCheck %s
> +
> +define i32 @main() {
> +; CHECK: .cfi_startproc
> +; CHECK: .cfi_personality 128, DW.ref.__gxx_personality_v0
> +
> +entry:
> +  invoke void @foo() to label %cont unwind label %lpad
> +; CHECK: foo
> +; CHECK: jalr
> +
> +lpad:
> +  %0 = landingpad { i8*, i32 } personality i8*
> +    bitcast (i32 (...)* @__gxx_personality_v0 to i8*) catch i8* null
> +  ret i32 0
> +
> +cont:
> +  ret i32 0
> +}
> +; CHECK: .cfi_endproc
> +
> +declare i32 @__gxx_personality_v0(...)
> +
> +declare void @foo()
> +
> +; CHECK: .hidden DW.ref.__gxx_personality_v0
> +; CHECK: .weak DW.ref.__gxx_personality_v0
> +; CHECK: .section
> .data.DW.ref.__gxx_personality_v0,"aGw", at progbits,DW.ref.__gxx_personality_v0,comdat
> +; CHECK: .align 2
> +; CHECK: .type DW.ref.__gxx_personality_v0, at object
> +; CHECK: .size DW.ref.__gxx_personality_v0, 4
> +; CHECK: DW.ref.__gxx_personality_v0:
> +; CHECK: .4byte __gxx_personality_v0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140521/4f7f2054/attachment.html>


More information about the llvm-commits mailing list