aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hsieh <andrewhsieh@google.com>2014-12-16 15:26:01 +0800
committerAndrew Hsieh <andrewhsieh@google.com>2014-12-16 15:40:37 +0800
commit474aa36a84295a481c749514f3d30e0e11f7df87 (patch)
tree140c2f7291cde07be964ab49c1d4bdffb6843c8f
parentcaa91795bad3ee3484d1f16007df2ae21d005ca6 (diff)
downloadllvm-474aa36a84295a481c749514f3d30e0e11f7df87.tar.gz
[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
-rw-r--r--lib/MC/MCObjectFileInfo.cpp27
1 files changed, 26 insertions, 1 deletions
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;