aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hsieh <andrewhsieh@google.com>2014-12-16 15:26:01 +0800
committerAndrew Hsieh <andrewhsieh@google.com>2015-03-24 11:56:25 -0700
commit48604b20a5daaa114c9cad67f1811c321ec0d947 (patch)
tree70e29b1f0fbb6a6736548235150972540dfd1095
parent977fd992c7b9b97ffc5b01d3d2c5f132ab10f343 (diff)
downloadllvm-48604b20a5daaa114c9cad67f1811c321ec0d947.tar.gz
[ndk][mips] 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 858181dd4af..8015ebbfb32 100644
--- a/lib/MC/MCObjectFileInfo.cpp
+++ b/lib/MC/MCObjectFileInfo.cpp
@@ -264,6 +264,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:
@@ -350,6 +352,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:
@@ -502,7 +527,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;