This is an archive of the discontinued LLVM Phabricator instance.

[X86] Avoid generating invalid R_X86_64_GOTPCRELX relocations
ClosedPublic

Authored by hvdijk on Dec 18 2020, 12:28 PM.

Details

Summary

We need to make sure not to emit R_X86_64_GOTPCRELX relocations for instructions that use a REX prefix. If a REX prefix is present, we need to instead use a R_X86_64_REX_GOTPCRELX relocation. The existing logic for CALL64m, JMP64m, etc. already handles this by checking the HasREX parameter and using it to determine which relocation type to use. Do this for all instructions that can use relaxed relocations.

Diff Detail

Event Timeline

hvdijk created this revision.Dec 18 2020, 12:28 PM
hvdijk requested review of this revision.Dec 18 2020, 12:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 18 2020, 12:28 PM
MaskRay added inline comments.Dec 18 2020, 1:12 PM
llvm/test/MC/X86/gotpcrelx.s
91

LG.

May I bother you to delete ELF/got-relaxed-rex.s and add its test coverage into this file as well?

The lld/test/ELF tests need fixing (check-lld-elf)

hvdijk updated this revision to Diff 312885.Dec 18 2020, 2:30 PM

Merge ELF/got-relaxed-rex.s into X86/gotpcrelx.s, update lld/test/ELF/x86-64-gotpc-relax-nopic.s.

hvdijk marked an inline comment as done.Dec 18 2020, 2:32 PM

The lld/test/ELF tests need fixing (check-lld-elf)

Good spot, it was a single test that needed updating, done.

MaskRay accepted this revision.Dec 18 2020, 2:48 PM

LGTM.

llvm/test/MC/X86/gotpcrelx.s
17

Consider moving add R_X86_64_REX_GOTPCRELX instructions below R_X86_64_REX_GOTPCRELX ones.

This revision is now accepted and ready to land.Dec 18 2020, 2:48 PM
hvdijk marked an inline comment as done.Dec 18 2020, 3:40 PM
hvdijk added inline comments.
llvm/test/MC/X86/gotpcrelx.s
17

I'm assuming you meant below R_X86_64_GOTPCRELX :) Sure, pushed with that change.