From 1e0a23468d321ed5f8675ca0ffbac203362c6cba Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 17 Dec 2020 14:32:18 +0900 Subject: [PATCH] temporary --- input_sections.cc | 12 ++---------- mold.h | 5 ++++- output_chunks.cc | 12 ++++-------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/input_sections.cc b/input_sections.cc index 80c56408..7a823d74 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -79,7 +79,7 @@ void InputSection::copy_buf() { else *(u64 *)loc = S + A; - if (config.pie) { + if (sym.needs_relative_rel()) { assert(sz == 8); memset(dynrel, 0, sizeof(*dynrel)); dynrel->r_offset = P; @@ -88,12 +88,6 @@ void InputSection::copy_buf() { dynrel++; } break; - case R_ZERO: - if (sz == 4) - *(u32 *)loc = 0; - else - *(u64 *)loc = 0; - break; case R_DYN: memset(dynrel, 0, sizeof(*dynrel)); dynrel->r_offset = P; @@ -218,11 +212,9 @@ void InputSection::scan_relocations() { rel_types[i] = R_DYN; sym.flags |= NEEDS_DYNSYM; file->num_reldyn++; - } else if (sym.is_undef_weak) { - rel_types[i] = R_ZERO; } else { rel_types[i] = R_ABS; - if (config.pie) + if (sym.needs_relative_rel()) file->num_reldyn++; } break; diff --git a/mold.h b/mold.h index 71d9b9a5..0c26d67f 100644 --- a/mold.h +++ b/mold.h @@ -178,6 +178,10 @@ public: inline u64 get_tlsld_addr() const; inline u64 get_plt_addr() const; + bool needs_relative_rel() const { + return config.pie && !is_undef_weak; + } + std::string_view name; InputFile *file = nullptr; const ElfSym *esym = nullptr; @@ -233,7 +237,6 @@ protected: enum RelType : u8 { R_NONE, R_ABS, - R_ZERO, R_DYN, R_PC, R_GOT, diff --git a/output_chunks.cc b/output_chunks.cc index 0dd8c5e3..16c54940 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -143,13 +143,9 @@ void RelDynSection::update_shdr() { int n = 0; - if (config.pie) { - n = out::got->got_syms.size(); - } else { - for (Symbol *sym : out::got->got_syms) - if (sym->is_imported) - n++; - } + for (Symbol *sym : out::got->got_syms) + if (sym->is_imported || sym->needs_relative_rel()) + n++; n += out::got->tlsgd_syms.size() * 2; n += out::got->tlsld_syms.size(); @@ -178,7 +174,7 @@ void RelDynSection::copy_buf() { for (Symbol *sym : out::got->got_syms) { if (sym->is_imported) { write(sym, R_X86_64_GLOB_DAT, sym->get_got_addr()); - } else if (config.pie) { + } else if (sym->needs_relative_rel()) { rel->r_type = R_X86_64_RELATIVE; rel->r_offset = sym->get_got_addr(); rel->r_addend = sym->get_addr();