]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gold/aarch64.cc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / aarch64.cc
index bb98edc277b42b96b30cc92af5e42f35f18181ad..e5bd7bda0fec5cb07f4ce71ce13b87958adb3f82 100644 (file)
@@ -1,6 +1,6 @@
 // aarch64.cc -- aarch64 target support for gold.
 
-// Copyright (C) 2014-2019 Free Software Foundation, Inc.
+// Copyright (C) 2014-2024 Free Software Foundation, Inc.
 // Written by Jing Yu <jingyu@google.com> and Han Shen <shenhan@google.com>.
 
 // This file is part of gold.
@@ -1182,7 +1182,8 @@ class Reloc_stub : public Stub_base<size, big_endian>
   aarch64_valid_for_adrp_p(AArch64_address location, AArch64_address dest)
   {
     typedef AArch64_relocate_functions<size, big_endian> Reloc;
-    int64_t adrp_imm = (Reloc::Page(dest) - Reloc::Page(location)) >> 12;
+    int64_t adrp_imm = Reloc::Page (dest) - Reloc::Page (location);
+    adrp_imm = adrp_imm < 0 ? ~(~adrp_imm >> 12) : adrp_imm >> 12;
     return adrp_imm >= MIN_ADRP_IMM && adrp_imm <= MAX_ADRP_IMM;
   }
 
@@ -2915,6 +2916,7 @@ class Target_aarch64 : public Sized_target<size, big_endian>
                        Section_id_hash> AArch64_input_section_map;
   typedef AArch64_insn_utilities<big_endian> Insn_utilities;
   const static int TCB_SIZE = size / 8 * 2;
+  static const Address invalid_address = static_cast<Address>(-1);
 
   Target_aarch64(const Target::Target_info* info = &aarch64_info)
     : Sized_target<size, big_endian>(info),
@@ -6496,6 +6498,17 @@ Target_aarch64<size, big_endian>::Scan::global(
          gold_error(_("%s: unsupported reloc %u in pos independent link."),
                     object->name().c_str(), r_type);
        }
+      // Make a PLT entry if necessary.
+      if (gsym->needs_plt_entry())
+       {
+         target->make_plt_entry(symtab, layout, gsym);
+         // Since this is not a PC-relative relocation, we may be
+         // taking the address of a function. In that case we need to
+         // set the entry in the dynamic symbol table to the address of
+         // the PLT entry.
+         if (gsym->is_from_dynobj() && !parameters->options().shared())
+           gsym->set_needs_dynsym_value();
+       }
       break;
 
     case elfcpp::R_AARCH64_LD_PREL_LO19:        // 273
@@ -6939,7 +6952,7 @@ Target_aarch64<size, big_endian>::do_finalize_sections(
                                  ? NULL
                                  : this->plt_->rela_plt());
   layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
-                                 this->rela_dyn_, true, false);
+                                 this->rela_dyn_, true, false, false);
 
   // Emit any relocs we saved in an attempt to avoid generating COPY
   // relocs.
@@ -8274,6 +8287,27 @@ Target_aarch64<size, big_endian>::relocate_relocs(
 
   gold_assert(sh_type == elfcpp::SHT_RELA);
 
+  if (offset_in_output_section == this->invalid_address)
+    {
+      const Output_relaxed_input_section *poris
+       = output_section->find_relaxed_input_section(relinfo->object,
+                                                    relinfo->data_shndx);
+      if (poris != NULL)
+       {
+         Address section_address = poris->address();
+         section_size_type section_size = poris->data_size();
+
+         gold_assert(section_address >= view_address
+                     && (section_address + section_size
+                         <= view_address + view_size));
+
+         off_t offset = section_address - view_address;
+         view += offset;
+         view_address += offset;
+         view_size = section_size;
+       }
+    }
+
   gold::relocate_relocs<size, big_endian, Classify_reloc>(
     relinfo,
     prelocs,