From 474aa36a84295a481c749514f3d30e0e11f7df87 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Tue, 16 Dec 2014 15:26:01 +0800 Subject: [3.5] writable .gcc_except_table for mips[64] To match gcc behavior and avoid ld warning like this on project using prebuilts/ndk 's libc++ .../ld: warning: creating a DT_TEXTREL in a shared object. (*1) switch_to_exception_section (const char * ARG_UNUSED (fnname)) { .... if (EH_TABLES_CAN_BE_READ_ONLY) { int tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1); # DW_EH_PE_indirect which is 0x80 flags = ((! flag_pic || ((tt_format & 0x70) != DW_EH_PE_absptr/*0x00*/ && (tt_format & 0x70) != DW_EH_PE_aligned/*0x50*/)) ? 0 : SECTION_WRITE); } else flags = SECTION_WRITE; ... } Note that PIC is the default for Android toolchain. For MIPS, ASM_PREFERRED_EH_DATA_FORMAT returns 0x80 and fails condition about "DW_EH_PE_absptr" The exact reason why .gcc_except_table contain reloc (and causes ld warning turns in to error thanks to -Wl,--fatal-warnings when it isn't writable thus requires load-time fixup in read-only section and security concern) isn't well understood, though Change-Id: I5e05ee052af48f06e8c4e3a01c317f4010a2ddaf --- lib/MC/MCObjectFileInfo.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index aeb92991b3d..d0e6990e93b 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -265,6 +265,8 @@ void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) { } void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { + bool writable_gcc_except_table = false; + switch (T.getArch()) { case Triple::mips: case Triple::mipsel: @@ -346,6 +348,29 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { // eh_frame section can be read-only. DW.ref.personality will be generated // for relocation. PersonalityEncoding = dwarf::DW_EH_PE_indirect; + if (TT.getEnvironment() == llvm::Triple::Android) { + // To match GCC/mips behavior in gcc/except.c as below, to avoid + // .../ld: warning: creating a DT_TEXTREL in a shared object. + // + // switch_to_exception_section (const char * ARG_UNUSED (fnname)) + // { + // .... + // if (EH_TABLES_CAN_BE_READ_ONLY) + // { + // int tt_format = + // ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1); # DW_EH_PE_indirect which is 0x80 + // flags = ((! flag_pic + // || ((tt_format & 0x70) != DW_EH_PE_absptr/*0x00*/ + // && (tt_format & 0x70) != DW_EH_PE_aligned/*0x50*/)) + // ? 0 : SECTION_WRITE); + // } + // else + // flags = SECTION_WRITE; + // + // FIXME: Check PIC (default in Android, though) + // + writable_gcc_except_table = true; + } break; case Triple::ppc64: case Triple::ppc64le: @@ -498,7 +523,7 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { // adjusted or this should be a data section. LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, - ELF::SHF_ALLOC, + ELF::SHF_ALLOC | (writable_gcc_except_table? ELF::SHF_WRITE : 0), SectionKind::getReadOnly()); COFFDebugSymbolsSection = nullptr; -- cgit v1.2.3