[PATCH] gold: Add -z noreloc-overflow option
H.J. Lu
hjl.tools@gmail.com
Sun Nov 8 12:13:57 GMT 2020
On Sat, Nov 7, 2020 at 2:06 PM Fangrui Song <i@maskray.me> wrote:
>
> On 2020-11-03, H.J. Lu wrote:
> >On Mon, Nov 2, 2020 at 11:02 PM Fangrui Song <i@maskray.me> wrote:
> >>
> >> On 2020-11-03, Hang Deng (handeng) via Binutils wrote:
> >> >HJ, Cary,
> >> >
> >> >Thanks, we tried your patch for X86_64, it works well.
> >> >
> >> >And the patch below also works with arm64, but I am not familiar with the test case and review/commit process, can you please help to commit this patch as well?
> >> >
> >> >Thanks,
> >> >Hunter
> >> >
> >> >diff --git a/gold/aarch64.cc b/gold/aarch64.cc
> >> >index b207dcdc..29da1e35 100644
> >> >--- a/gold/aarch64.cc
> >> >+++ b/gold/aarch64.cc
> >> >@@ -5972,7 +5972,6 @@ Target_aarch64<size, big_endian>::Scan::local(
> >> > case elfcpp::R_AARCH64_NONE:
> >> > break;
> >> >
> >> >- case elfcpp::R_AARCH64_ABS32:
> >> > case elfcpp::R_AARCH64_ABS16:
> >> > if (parameters->options().output_is_position_independent())
> >> > {
> >> >@@ -5981,6 +5980,13 @@ Target_aarch64<size, big_endian>::Scan::local(
> >> > }
> >> > break;
> >> >
> >> >+ case elfcpp::R_AARCH64_ABS32:
> >> >+ if ( parameters->options().output_is_position_independent() &&
> >> >+ !parameters->options().noreloc_overflow()) {
> >> >+ gold_error(_("%s: unsupported reloc %u in pos independent link."),
> >> >+ object->name().c_str(), r_type);
> >> >+ break;
> >> >+ }
> >>
> >> Cary raised the point that -z noreloc-overflow should be related to the
> >> link-time value, rather than the possibility of runtime overflow.
> >>
> >
> >From ld manual:
> >
> > 'noreloc-overflow'
> > Disable relocation overflow check. This can be used to
> > disable relocation overflow check if there will be no dynamic
> > relocation overflow at run-time. Supported for x86_64.
> >
> >H.J.
>
> I am now wondering whether -z noreloc-overflow is a misnomer or a
> misfeature.
>
> I can see that the resolution of
> https://sourceware.org/bugzilla/show_bug.cgi?id=19807 introduced -z
> noreloc-overflow and the only usage is in the Linux kernel.
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a2c4fc4d4e2c40b07534094810d915c7354d84a7
> which I reviewed
> properly fixed fix the x86 code and it will be included in Linux 5.10.
> This paragraph of the commit message explained why the option can be
> dangerous pretty well:
>
> ... This is because these instructions cannot really be
> relocated: the displacement field is only 32-bits wide, and thus
> cannot be relocated for a 64-bit load address. The -z noreloc-overflow
> option simply overrides the linker error, and results in
> R_X86_64_RELATIVE relocations that apply a 64-bit relocation to a
> 32-bit field anyway. This happens to work because nothing will
> process these run-time relocations.
>
> The test pr19807-2e.d well demonstrated that an R_X86_64_RELATIVE
> relocates a 32-bit field, which looks very dangerous.
>
> Note, the meaning of -z noreloc-overflow in PR19807 seems very different
> from this Gold patch.
My -z noreloc-overflow patch for gold includes the same testcases
from ld testsuite.
--
H.J.
More information about the Binutils
mailing list