This is an archive of the discontinued LLVM Phabricator instance.

[lld][driver] Add `--relax-gp`/`no-relax-gp` flags for GNU compatibility
ClosedPublic

Authored by MaskRay on Apr 10 2023, 5:26 PM.

Details

Summary

GNU LD accepts --relax-gp/--no-relax-gp to control GP relaxation.

Since gp (x3) is being defined as the platform register in the
RISC-V psABI, LLD needs to be able to handle flags that disable gp
relaxation. The use of gp as the shadow call stack register is a prime
example of when a compiler aught to set such a flag for the linker, so
that linker relaxation won't conflict with the platform's usage of the
register.

This patch only adds the flag for compatibility, since LLD does not yet
implement GP relaxation, which will not conflict with a platform's usage
of the RISC-V GP register.

Diff Detail

Event Timeline

paulkirth created this revision.Apr 10 2023, 5:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 5:26 PM
paulkirth requested review of this revision.Apr 10 2023, 5:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 5:26 PM
This revision is now accepted and ready to land.Apr 10 2023, 5:49 PM
MaskRay requested changes to this revision.Apr 11 2023, 12:38 PM

Thank for the patch, but we can just wait for GP relaxation which should land soon.

This revision now requires changes to proceed.Apr 11 2023, 12:38 PM

Thank for the patch, but we can just wait for GP relaxation which should land soon.

If it's not landing literally by tomorrow, then we should land this first to unblock other work that needs to rely on RISC-V linkers accepting these flags since GNU linkers have --relax-gp as the default state and we need target-specific driver logic to be able to override that. This seems far preferable to making such driver logic temporarily omit the option when it thinks it's running LLD.

Thank for the patch, but we can just wait for GP relaxation which should land soon.

If it's not landing literally by tomorrow, then we should land this first to unblock other work that needs to rely on RISC-V linkers accepting these flags since GNU linkers have --relax-gp as the default state and we need target-specific driver logic to be able to override that. This seems far preferable to making such driver logic temporarily omit the option when it thinks it's running LLD.

Thank you for weighing in in shadow call stack. Apologies if I have missed any previous discussions as I had been travelling for quite a while for the past 30 days and just came back and started to check emails.

However, I don't think this is needed to unblock any dependent work.
I added --[no-]relax-gp to GNU ld recently, which isn't in a released binutils version yet.
Clang Driver passing --no-relax-gp to ld will break most GNU ld users.

This patch has some other issues that should be addressed before being in a ready state. For ignored options, we use silent-ignore.test as a convention.
For ignored options, we don't need to use TableGen names defm relax_gp.

With the above said, I acknowledge the need of --relax-gp and just made another comment on D143673 to prioritize the work.

paulkirth updated this revision to Diff 512561.Apr 11 2023, 1:32 PM

Address comments.

paulkirth updated this revision to Diff 512564.Apr 11 2023, 1:35 PM

Fix whitespace and simplify test.

paulkirth updated this revision to Diff 512565.Apr 11 2023, 1:38 PM

Fix remaining whitespace, not added to last commit.

I don't see the issue with landing this change for now , and allowing D143673 to revert it when landing. I think that keeps the world in a more consistent state, right? ToT GNU LD accepts the flags, and thus ToT LLD will too.

The other think I'd point out is that I think we do need to start setting this option in the clang driver as part of adopting the new platform register for shadow call stack.
I don't expect that to affect many users, since AFAIK only Fuchsia and Android are looking into using SCS on RISC-V.

The unfortunate fact is that we're in a situation where people are using the latest GNU LD and running into trouble because the compiler doesn't communicate that well to the linker.
They can certainly work around that, but I don't see this as significantly different from setting other linker related options for other sanitizers.

Would you mind elaborating on your views here, and the rationale for why we wouldn't want to do that now?

I don't see the issue with landing this change for now , and allowing D143673 to revert it when landing. I think that keeps the world in a more consistent state, right? ToT GNU LD accepts the flags, and thus ToT LLD will too.

The other think I'd point out is that I think we do need to start setting this option in the clang driver as part of adopting the new platform register for shadow call stack.
I don't expect that to affect many users, since AFAIK only Fuchsia and Android are looking into using SCS on RISC-V.

The unfortunate fact is that we're in a situation where people are using the latest GNU LD and running into trouble because the compiler doesn't communicate that well to the linker.
They can certainly work around that, but I don't see this as significantly different from setting other linker related options for other sanitizers.

Would you mind elaborating on your views here, and the rationale for why we wouldn't want to do that now?

See https://reviews.llvm.org/D148034#4262991

--no-relax-gp has been added. This can be abandoned.

lld/test/ELF/silent-ignore.test
10

Note: double --no-relax

MaskRay commandeered this revision.Apr 17 2023, 10:17 AM
MaskRay edited reviewers, added: paulkirth; removed: MaskRay.
This revision is now accepted and ready to land.Apr 17 2023, 10:17 AM
MaskRay closed this revision.Apr 17 2023, 10:17 AM