backend relocate_section routine for relocatable linking. */
unsigned rela_normal : 1;
+ /* Whether a relocation is rela_normal. Compared with rela_normal,
+ is_rela_normal can set part of relocations to rela_normal. */
+ bool (*is_rela_normal) (Elf_Internal_Rela *);
+
/* Set if DT_REL/DT_RELA/DT_RELSZ/DT_RELASZ should not include PLT
relocations. */
unsigned dtrel_excludes_plt : 1;
{
rel_hash = PTR_ADD (esdo->rela.hashes, esdo->rela.count);
rela_hash_list = rel_hash;
- rela_normal = bed->rela_normal;
+ if (bed->is_rela_normal != NULL)
+ rela_normal = bed->is_rela_normal (irela);
+ else
+ rela_normal = bed->rela_normal;
}
irela->r_offset = _bfd_elf_section_offset (output_bfd,
return _bfd_elf_hash_symbol (h);
}
+/* If a relocation is rela_normal and the symbol associated with the
+ relocation is STT_SECTION type, the addend of the relocation would add
+ sec->output_offset when partial linking (ld -r).
+ See elf_backend_data.rela_normal and elf_link_input_bfd().
+ The addend of R_LARCH_ALIGN is used to represent the first and third
+ expression of .align, it should be a constant when linking. */
+
+static bool
+loongarch_elf_is_rela_normal (Elf_Internal_Rela *rel)
+{
+ if (R_LARCH_ALIGN == ELFNN_R_TYPE (rel->r_info))
+ return false;
+ return true;
+}
+
#define TARGET_LITTLE_SYM loongarch_elfNN_vec
#define TARGET_LITTLE_NAME "elfNN-loongarch"
#define ELF_ARCH bfd_arch_loongarch
#define elf_backend_grok_psinfo loongarch_elf_grok_psinfo
#define elf_backend_hash_symbol elf_loongarch64_hash_symbol
#define bfd_elfNN_bfd_relax_section loongarch_elf_relax_section
+#define elf_backend_is_rela_normal loongarch_elf_is_rela_normal
#define elf_backend_dtrel_excludes_plt 1
#define elf_backend_rela_normal 0
#endif
+#ifndef elf_backend_is_rela_normal
+#define elf_backend_is_rela_normal NULL
+#endif
+
#ifndef elf_backend_dtrel_excludes_plt
#define elf_backend_dtrel_excludes_plt 0
#endif
elf_backend_default_use_rela_p,
elf_backend_rela_plts_and_copies_p,
elf_backend_rela_normal,
+ elf_backend_is_rela_normal,
elf_backend_dtrel_excludes_plt,
elf_backend_sign_extend_vma,
elf_backend_want_got_plt,
if (fragP->fr_subtype != 0 && offset > fragP->fr_subtype). */
if (max > 0 && (bfd_vma) max < worst_case_bytes)
{
- s = symbol_find (".Lla-relax-align");
- if (s == NULL)
- s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg,
- &zero_address_frag, 0);
+ s = symbol_find (now_seg->name);
ex.X_add_symbol = s;
ex.X_op = O_symbol;
ex.X_add_number = (max << 8) | n;
Disassembly of section .text:
-[ ]*0000000000000000 <.Lla-relax-align>:
+[ ]*0000000000000000 <.text>:
[ ]+0:[ ]+4c000020[ ]+ret
[ ]+4:[ ]+03400000[ ]+nop
[ ]+4: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc
[ ]+1c:[ ]+03400000[ ]+nop
[ ]+20:[ ]+4c000020[ ]+ret
[ ]+24:[ ]+03400000[ ]+nop
-[ ]+24: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0x104
+[ ]+24: R_LARCH_ALIGN[ ]+.text\+0x104
[ ]+28:[ ]+03400000[ ]+nop
[ ]+2c:[ ]+03400000[ ]+nop
[ ]+30:[ ]+4c000020[ ]+ret
[ ]+34:[ ]+03400000[ ]+nop
-[ ]+34: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0xb04
+[ ]+34: R_LARCH_ALIGN[ ]+.text\+0xb04
[ ]+38:[ ]+03400000[ ]+nop
[ ]+3c:[ ]+03400000[ ]+nop
[ ]+40:[ ]+4c000020[ ]+ret
--- /dev/null
+SECTIONS
+{
+ /DISCARD/ : { *(.another.*) }
+}
--- /dev/null
+# Use the section name symbol for R_LARCH_ALIGN to avoid discard section problem
+.section ".another.text", "ax"
+.cfi_startproc
+break 0
+.cfi_def_cfa_offset 16
+.p2align 5
+break 1
+.cfi_endproc
+
+.text
+.cfi_startproc
+break 0
+.cfi_def_cfa_offset 16
+.p2align 5
+break 1
+.cfi_endproc
+
"relax-align" \
] \
]
+
+ run_ld_link_tests \
+ [list \
+ [list \
+ "loongarch relax align discard" \
+ "-e 0x0 -T relax-align-discard.lds -r" "" \
+ "" \
+ {relax-align-discard.s} \
+ {} \
+ "relax-align-discard" \
+ ] \
+ ]
}
set objdump_flags "-s -j .data"