This is an archive of the discontinued LLVM Phabricator instance.

[ELF][PPC][X86] Use [-2**(n-1), 2**n) to check overflows for R_PPC_ADDR16, R_PPC64_ADDR{16,32}, R_X86_64_{8,16}
ClosedPublic

Authored by MaskRay on Jun 22 2019, 10:20 PM.

Details

Summary

Similar to R_AARCH64_ABS32, R_PPC64_ADDR32 can represent either a signed
value or unsigned value, thus we should use [-2**(n-1), 2**n) instead of
[-2**(n-1), 2**(n-1)) to check overflows.

The issue manifests as a bogus linker error when linking the powerpc64le Linux kernel.
The new behavior is compatible with ld.bfd's complain_overflow_bitfield.

The upper bound of the error message is not correct. Fix it as well.

The changes to R_PPC_ADDR16, R_PPC64_ADDR16, R_X86_64_8 and R_X86_64_16 are similar.

Event Timeline

MaskRay created this revision.Jun 22 2019, 10:20 PM
MaskRay updated this revision to Diff 206132.Jun 22 2019, 10:23 PM
MaskRay edited the summary of this revision. (Show Details)

Add `` to fix markdown code blocks

MaskRay updated this revision to Diff 206133.Jun 22 2019, 10:59 PM
MaskRay retitled this revision from [ELF][PPC] Check overflow using [-2**(n-1), 2**n) for R_PPC_ADDR16 and R_PPC64_ADDR{16,32} to [ELF][PPC][X86] Check overflow using [-2**(n-1), 2**n) for R_PPC_ADDR16, R_PPC64_ADDR{16,32}, R_X86_64_{8,16}.
MaskRay edited the summary of this revision. (Show Details)
MaskRay added a reviewer: grimar.

Fix R_X86_64_{8,16} as well

MaskRay marked an inline comment as done.Jun 22 2019, 11:00 PM
MaskRay added inline comments.
ELF/Arch/X86_64.cpp
368 ↗(On Diff #206133)

This is special, bfd uses complain_overflow_unsigned for this, so this does not need a fix..

ruiu accepted this revision.Jun 23 2019, 9:44 PM

LGTM

This revision is now accepted and ready to land.Jun 23 2019, 9:44 PM
MaskRay updated this revision to Diff 206156.Jun 23 2019, 10:34 PM
MaskRay retitled this revision from [ELF][PPC][X86] Check overflow using [-2**(n-1), 2**n) for R_PPC_ADDR16, R_PPC64_ADDR{16,32}, R_X86_64_{8,16} to [ELF][PPC][X86] Use [-2**(n-1), 2**n) to check overflows for R_PPC_ADDR16, R_PPC64_ADDR{16,32}, R_X86_64_{8,16}.
MaskRay edited the summary of this revision. (Show Details)

use .code16 to make i386 tests more reasonable

This revision was automatically updated to reflect the committed changes.
test/ELF/ppc32-reloc-addr.s