This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Remove obscure -dp and GNU ld incompatible --[no-]define-common, ignore -d/-dc
ClosedPublic

Authored by MaskRay on Feb 6 2022, 11:25 PM.

Details

Summary

https://maskray.me/blog/2022-02-06-all-about-common-symbols#no-define-common

In GNU ld, -dc only affects -r links and causes COMMON symbols to be allocated.
--no-define-common is defined to make COMMON symbols undefined for -shared.
AIUI --no-define-common is a workaround around glibc 2.1 time and not really useful.

gold confuses --define-common with -d/FORCE_COMMON_ALLOCATION and implements
--define-common with -d semantics. Its --no-define-common is incompatible with
GNU ld.

In ld.lld, b2a23cf3c08cee45614f27eb2c6d044e506aa6a6 fixed the default -r
behavior for COMMON symbols but ported the incompatible gold
--[no-]define-common. To the best of my knowledge, no project uses -dp
--[no-]define-common. So just remove these options.

-d/-dc are used by the following projects:

A no-op implementation works for them. Only when a program inspects relocatable
output by itself and does not recognize COMMON symbols, there may be a problem.
This is an extremely unlikely case.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 6 2022, 11:25 PM
MaskRay requested review of this revision.Feb 6 2022, 11:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2022, 11:25 PM
MaskRay edited the summary of this revision. (Show Details)Feb 6 2022, 11:33 PM
MaskRay edited the summary of this revision. (Show Details)
MaskRay updated this revision to Diff 406338.Feb 7 2022, 12:12 AM
MaskRay retitled this revision from [ELF] Clarify -dc and remove GNU ld incompatible --[no-]define-common to [ELF] Remove GNU ld incompatible --[no-]define-common and obscure -dc/-dp.
MaskRay edited the summary of this revision. (Show Details)

remove -dc/-dp

I have tried some Debian Code Search patterns and believe they are not used
for targets we support.

  • -Wl,-dp -Wl,-dc
  • LDFLAGS.*-dc
  • LDFLAGS.*-dp

I keep -d because it is used by grub

While in this case I think you are right, and no-one using LLD will be depending on this. I'm a bit uncomfortable with taking options out without a bit more warning and chance for feedback. I think it could be worth using this to set out LLD's deprecation/removal process. For example for options that maintainers want to remove we've got several options, or even a combination depending on circumstances:

  • Option will be deprecated (with a silenceable warning) for a release, then removed in the subsequent release.
  • Option will be removed if there is no use of it in an open source project.
  • Option will be removed if a post on the community discourse/mailing lists, github issue has no one feedback with a good reason to keep it within a certain time frame.
  • Option will be set to silent ignore if a valid, if sub-optimal output can be produced without applying the option.

I'd strongly recommend that we at least make a github issue (more search engine friendly than a review) and a post on discourse first. Ideally agree some kind of process so that people using LLD can know what to expect.

MaskRay added a comment.EditedFeb 8 2022, 10:37 AM

While in this case I think you are right, and no-one using LLD will be depending on this. I'm a bit uncomfortable with taking options out without a bit more warning and chance for feedback. I think it could be worth using this to set out LLD's deprecation/removal process. For example for options that maintainers want to remove we've got several options, or even a combination depending on circumstances:

  • Option will be deprecated (with a silenceable warning) for a release, then removed in the subsequent release.
  • Option will be removed if there is no use of it in an open source project.
  • Option will be removed if a post on the community discourse/mailing lists, github issue has no one feedback with a good reason to keep it within a certain time frame.
  • Option will be set to silent ignore if a valid, if sub-optimal output can be produced without applying the option.

I'd strongly recommend that we at least make a github issue (more search engine friendly than a review) and a post on discourse first. Ideally agree some kind of process so that people using LLD can know what to expect.

Good idea. Created https://github.com/llvm/llvm-project/issues/53660 & https://discourse.llvm.org/t/remove-gnu-ld-incompatible-no-define-common-and-obscure-dc-dp/59894 as the first step.
Perhaps you may start a post about deprecation policy since you already got the wording:) ?

I think for -dc and -dp we can warn about them in the release/14.x branch. The warning will (a) give us idea whether they are really unused, (b) push projects to remove the options, (c) decide whether we should (actually quite trivial) keep them with full functionality, keep them as ignored options, or remove them altogether.

For release/14.x, I am thinking of this warning:

if (args.hasArg(OPT_define_common, OPT_no_define_common))                                                                                                                                                                      
  warn("-d, -dc, -dp, and --[no-]define-common are ignored and will be removed. See https://github.com/llvm/llvm-project/issues/53660");
MaskRay updated this revision to Diff 407048.Feb 8 2022, 10:04 PM
MaskRay retitled this revision from [ELF] Remove GNU ld incompatible --[no-]define-common and obscure -dc/-dp to [ELF] Remove obscure -dp and GNU ld incompatible --[no-]define-common, ignore -d/-dc.
MaskRay edited the summary of this revision. (Show Details)

Keep -dc since used by FreeBSD crunchgen (though being removed by https://reviews.freebsd.org/D34215)

peter.smith accepted this revision.Feb 9 2022, 1:21 AM

LGTM for the changes. It will be worth giving the messages some time to see if there are any others affected.

Perhaps you may start a post about deprecation policy since you already got the wording:) ?

Me and my big mouth! I should have some time on Friday to write a post.

This revision is now accepted and ready to land.Feb 9 2022, 1:21 AM

Thanks:) 14.0.0 will have this diagnostic: https://github.com/llvm/llvm-project/commit/7efa49801166f221d8fd7b20ac0d04368b8ea9d5

The FreeBSD crunchgen and grub usage of -d/-dc are being removed but we will keep no-op -d/-dc for a while.
-dp and --[no-]define-common will be removed by this patch (milestone: 15.0.0).