From bb050128b3713a478caaf2e302dd1c115bac2009 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 8 Jun 2021 19:39:22 +0900 Subject: [PATCH] Allow R_NONE in .rel.eh_frame --- arch_i386.cc | 2 ++ arch_x86_64.cc | 2 ++ elf.h | 2 ++ object_file.cc | 17 ++--------------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/arch_i386.cc b/arch_i386.cc index b3743681..93ecd609 100644 --- a/arch_i386.cc +++ b/arch_i386.cc @@ -99,6 +99,8 @@ void EhFrameSection::apply_reloc(Context &ctx, u8 *base = ctx.buf + this->shdr.sh_offset; switch (rel.r_type) { + case R_386_NONE: + return; case R_386_32: *(u32 *)(base + loc) = val; return; diff --git a/arch_x86_64.cc b/arch_x86_64.cc index ceaee52f..4ba21cec 100644 --- a/arch_x86_64.cc +++ b/arch_x86_64.cc @@ -73,6 +73,8 @@ void EhFrameSection::apply_reloc(Context &ctx, u8 *base = ctx.buf + this->shdr.sh_offset; switch (rel.r_type) { + case R_X86_64_NONE: + return; case R_X86_64_32: *(u32 *)(base + loc) = val; return; diff --git a/elf.h b/elf.h index 89455392..ef1c8f4a 100644 --- a/elf.h +++ b/elf.h @@ -609,6 +609,7 @@ template struct ElfNhdr; struct X86_64 { typedef u64 WordTy; + static constexpr u32 R_NONE = R_X86_64_NONE; static constexpr u32 R_COPY = R_X86_64_COPY; static constexpr u32 R_GLOB_DAT = R_X86_64_GLOB_DAT; static constexpr u32 R_JUMP_SLOT = R_X86_64_JUMP_SLOT; @@ -643,6 +644,7 @@ template <> struct ElfNhdr : public Elf64Nhdr {}; struct I386 { typedef u32 WordTy; + static constexpr u32 R_NONE = R_386_NONE; static constexpr u32 R_COPY = R_386_COPY; static constexpr u32 R_GLOB_DAT = R_386_GLOB_DAT; static constexpr u32 R_JUMP_SLOT = R_386_JUMP_SLOT; diff --git a/object_file.cc b/object_file.cc index 63b2c7ed..45240353 100644 --- a/object_file.cc +++ b/object_file.cc @@ -330,20 +330,6 @@ void ObjectFile::initialize_ehframe_sections(Context &ctx) { } } -template -static bool is_valid_ehframe_reloc(u32 type); - -template <> -bool is_valid_ehframe_reloc(u32 type) { - return type == R_X86_64_32 || type == R_X86_64_64 || - type == R_X86_64_PC32 || type == R_X86_64_PC64; -} - -template <> -bool is_valid_ehframe_reloc(u32 type) { - return type == R_386_32 || type == R_386_PC32; -} - // .eh_frame contains data records explaining how to handle exceptions. // When an exception is thrown, the runtime searches a record from // .eh_frame with the current program counter as a key. A record that @@ -379,7 +365,8 @@ void ObjectFile::read_ehframe(Context &ctx, InputSection &isec) { // Verify relocations. for (i64 i = 1; i < rels.size(); i++) - if (rels[i].r_offset <= rels[i - 1].r_offset) + if (rels[i].r_type != E::R_NONE && + rels[i].r_offset <= rels[i - 1].r_offset) Fatal(ctx) << isec << ": relocation offsets must increase monotonically"; // Read CIEs and FDEs until empty.