This is an archive of the discontinued LLVM Phabricator instance.

[X86] Selective relocation relaxation for +tagged-globals
ClosedPublic

Authored by morehouse on Nov 4 2021, 3:41 PM.

Details

Summary

For tagged-globals, we only need to disable relaxation for globals that
we actually tag. With this patch function pointer relocations, which
we do not instrument, can be relaxed.

This patch also makes tagged-globals work properly with LTO, as
-Wa,-mrelax-relocations=no doesn't work with LTO.

Diff Detail

Event Timeline

morehouse created this revision.Nov 4 2021, 3:41 PM
morehouse requested review of this revision.Nov 4 2021, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2021, 3:41 PM
pcc added a comment.Nov 10 2021, 1:55 PM

I think it ought to be possible to write these non-relaxable relocations from assembly, so that the behavior with -c is equivalent to the behavior with -S and then assembling the output. For example, you should be able to assemble

mov foo@gotpcrel_norelax(%rip), %rax

and the -S output from the compiler should look like that as well.

I think it ought to be possible to write these non-relaxable relocations from assembly, so that the behavior with -c is equivalent to the behavior with -S and then assembling the output. For example, you should be able to assemble

mov foo@gotpcrel_norelax(%rip), %rax

and the -S output from the compiler should look like that as well.

Won't this cause incompatibility with all other assemblers?

pcc added a comment.Nov 10 2021, 2:59 PM

I think it ought to be possible to write these non-relaxable relocations from assembly, so that the behavior with -c is equivalent to the behavior with -S and then assembling the output. For example, you should be able to assemble

mov foo@gotpcrel_norelax(%rip), %rax

and the -S output from the compiler should look like that as well.

Won't this cause incompatibility with all other assemblers?

We are not required to remain compatible with other assemblers in our assembly output unless -no-integrated-as is specified, but any extensions should be documented here: https://llvm.org/docs/Extensions.html

Indeed, LLVM will use a number of its own extensions by default in its assembly output, e.g. .addrsig.

morehouse updated this revision to Diff 386660.Nov 11 2021, 2:13 PM
  • Add @GOTPCREL_NORELAX as an assembly extension.
pcc accepted this revision.Nov 11 2021, 3:16 PM

LGTM

This revision is now accepted and ready to land.Nov 11 2021, 3:16 PM
MaskRay added a comment.EditedNov 11 2021, 3:31 PM

GNU ld's behavior and LLD's are not the same, and we may not end up on the same page. However, for courtesy it would be nice to ask binutils@sourceware.org whether they may adopt a similar notation.
We can still proceed if they don't do anything, but this makes for a possible common ground in case they have an opinion on the notation.

This revision was landed with ongoing or failed builds.Nov 19 2021, 7:19 AM
This revision was automatically updated to reflect the committed changes.
kstoimenov added inline comments.
llvm/lib/Target/X86/X86AsmPrinter.cpp
192–195

Maybe format the rest of the lines to align like they did before your change? Either that or format them to have a single space after the ";".

kstoimenov added inline comments.Dec 9 2021, 5:11 PM
llvm/lib/Target/X86/X86AsmPrinter.cpp
192–195

Correction: after ":".