* [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking
@ 2024-02-07 17:31 YunQiang Su
2024-02-21 8:48 ` YunQiang Su
2024-02-21 12:59 ` Maciej W. Rozycki
0 siblings, 2 replies; 3+ messages in thread
From: YunQiang Su @ 2024-02-07 17:31 UTC (permalink / raw)
To: nickc; +Cc: binutils, macro, xry111
The asm code like:
b (8)
will emit absolute relocs like:
R_MIPS_PC16 *ABS*
If they are included into PIC shared objects or PIE executables,
the branch target will be like 0x12340000, which will make the
programs crash.
---
bfd/elfxx-mips.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 69dd71419ff..9542250dec4 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -9258,6 +9258,15 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
(h) ? h->root.root.string : "a local symbol");
break;
default:
+ if (branch_reloc_p (r_type) && r_symndx == STN_UNDEF)
+ {
+ howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, NEWABI_P (abfd));
+ info->callbacks->einfo
+ /* xgettext:c-format */
+ (_("%X%H: relocation %s against `*ABS*' cannot be used"
+ " when making a PIC/PIE object\n"),
+ abfd, sec, rel->r_offset, howto->name);
+ }
break;
}
}
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking
2024-02-07 17:31 [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking YunQiang Su
@ 2024-02-21 8:48 ` YunQiang Su
2024-02-21 12:59 ` Maciej W. Rozycki
1 sibling, 0 replies; 3+ messages in thread
From: YunQiang Su @ 2024-02-21 8:48 UTC (permalink / raw)
To: nickc; +Cc: binutils, macro, xry111
YunQiang Su <syq@gcc.gnu.org> 于2024年2月8日周四 01:31写道:
>
> The asm code like:
> b (8)
> will emit absolute relocs like:
> R_MIPS_PC16 *ABS*
>
> If they are included into PIC shared objects or PIE executables,
> the branch target will be like 0x12340000, which will make the
> programs crash.
@Maciej ping.
> ---
> bfd/elfxx-mips.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> index 69dd71419ff..9542250dec4 100644
> --- a/bfd/elfxx-mips.c
> +++ b/bfd/elfxx-mips.c
> @@ -9258,6 +9258,15 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
> (h) ? h->root.root.string : "a local symbol");
> break;
> default:
> + if (branch_reloc_p (r_type) && r_symndx == STN_UNDEF)
> + {
> + howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, NEWABI_P (abfd));
> + info->callbacks->einfo
> + /* xgettext:c-format */
> + (_("%X%H: relocation %s against `*ABS*' cannot be used"
> + " when making a PIC/PIE object\n"),
> + abfd, sec, rel->r_offset, howto->name);
> + }
> break;
> }
> }
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking
2024-02-07 17:31 [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking YunQiang Su
2024-02-21 8:48 ` YunQiang Su
@ 2024-02-21 12:59 ` Maciej W. Rozycki
1 sibling, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2024-02-21 12:59 UTC (permalink / raw)
To: YunQiang Su; +Cc: Nick Clifton, binutils, xry111
On Thu, 8 Feb 2024, YunQiang Su wrote:
> The asm code like:
> b (8)
> will emit absolute relocs like:
> R_MIPS_PC16 *ABS*
>
> If they are included into PIC shared objects or PIE executables,
> the branch target will be like 0x12340000, which will make the
> programs crash.
This needs a proper LD test case. I don't think `8' needs to be
parenthesised here.
Maciej
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-21 12:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 17:31 [PATCH v5] MIPS: Reject branch absolute relocs for PIC for linking YunQiang Su
2024-02-21 8:48 ` YunQiang Su
2024-02-21 12:59 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).