Remove relocation against discarded sections for relocatable link.
[deliverable/binutils-gdb.git] / bfd / elf-bfd.h
index 0c975dcb5184b2b209949ce6086417bab64be359..226b95fe86ae700e56d65e9d95fdd202ab7ec20a 100644 (file)
@@ -2328,6 +2328,48 @@ extern asection _bfd_elf_large_com_section;
     }                                                                  \
   while (0)
 
+/* This macro is to avoid lots of duplicated code in the body of the
+   loop over relocations in xxx_relocate_section() in the various
+   elfxx-xxxx.c files.
+   
+   Handle relocations against symbols from removed linkonce sections,
+   or sections discarded by a linker script.  When doing a relocatable
+   link, we remove such relocations.  Otherwise, we just want the
+   section contents zeroed and avoid any special processing.  */
+#define RELOC_AGAINST_DISCARDED_SECTION(info, input_bfd, input_section,        \
+                                       rel, relend, howto, contents)   \
+  {                                                                    \
+    if (info->relocatable                                              \
+       && (input_section->flags & SEC_DEBUGGING))                      \
+      {                                                                        \
+       /* Only remove relocations in debug sections since other        \
+          sections may require relocations.  */                        \
+       Elf_Internal_Shdr *rel_hdr;                                     \
+                                                                       \
+       rel_hdr = &elf_section_data (input_section->output_section)->rel_hdr; \
+                                                                       \
+       /* Avoid empty output section.  */                              \
+       if (rel_hdr->sh_size > rel_hdr->sh_entsize)                     \
+         {                                                             \
+           rel_hdr->sh_size -= rel_hdr->sh_entsize;                    \
+           rel_hdr = &elf_section_data (input_section)->rel_hdr;       \
+           rel_hdr->sh_size -= rel_hdr->sh_entsize;                    \
+                                                                       \
+           memmove (rel, rel + 1, (relend - rel) * sizeof (*rel));     \
+                                                                       \
+           input_section->reloc_count--;                               \
+           relend--;                                                   \
+           rel--;                                                      \
+           continue;                                                   \
+         }                                                             \
+      }                                                                        \
+                                                                       \
+    _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);  \
+    rel->r_info = 0;                                                   \
+    rel->r_addend = 0;                                                 \
+    continue;                                                          \
+  }
+
 /* Will a symbol be bound to the the definition within the shared
    library, if any.  A unique symbol can never be bound locally.  */
 #define SYMBOLIC_BIND(INFO, H) \
This page took 0.023848 seconds and 4 git commands to generate.