Skip to content

[Driver] Allow -e entry but reject -eentry #72804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Nov 19, 2023

This short option taking an argument is unfortunate.

  • If a cc1-only option starts with -e, using it for driver will not be
    reported as an error (e.g. commit
    6cd9886c88d16d288c74846495d89f2fe84ff827).
  • If another -e driver option is intended but a typo is made, the
    option will be recognized as a -e.

gcc -export-dynamic passes -export-dynamic to ld. It's not clear
whether some options behave this way.

It seems -Wl,-eentry and -Wl,--entry=entry are primarily used. There
may also be a few gcc -e entry, but gcc -eentry is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
-e.

This short option taking an argument is unfortunate.

* If a cc1-only option starts with `-e`, using it for driver will not be
  reported as an error (e.g. commit
  6cd9886c88d16d288c74846495d89f2fe84ff827).
* If another `-e` driver option is intended but a typo is made, the
  option will be recognized as a `-e`.

`gcc -export-dynamic` passes `-export-dynamic` to ld. It's not clear
whether some options behave this way.

It seems `-Wl,-eentry` and `-Wl,--entry=entry` are primarily used. There
may also be a few `gcc -e entry`, but `gcc -eentry` is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
`-e`.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Nov 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2023

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

Changes

This short option taking an argument is unfortunate.

  • If a cc1-only option starts with -e, using it for driver will not be
    reported as an error (e.g. commit
    6cd9886c88d16d288c74846495d89f2fe84ff827).
  • If another -e driver option is intended but a typo is made, the
    option will be recognized as a -e.

gcc -export-dynamic passes -export-dynamic to ld. It's not clear
whether some options behave this way.

It seems -Wl,-eentry and -Wl,--entry=entry are primarily used. There
may also be a few gcc -e entry, but gcc -eentry is extremely rare or
not used at all. Therefore, we probably should reject the Joined form of
-e.


Full diff: https://github.com/llvm/llvm-project/pull/72804.diff

2 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+1-1)
  • (added) clang/test/Driver/entry.s (+5)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296a..83b09a892049bb6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1452,7 +1452,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], "extract-api-ignores=">,
   Visibility<[ClangOption, CC1Option]>,
     HelpText<"Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.">,
     MarshallingInfoStringVector<FrontendOpts<"ExtractAPIIgnoresFileList">>;
-def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
+def e : Separate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group<f_Group>,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
diff --git a/clang/test/Driver/entry.s b/clang/test/Driver/entry.s
new file mode 100644
index 000000000000000..60ab89704c35462
--- /dev/null
+++ b/clang/test/Driver/entry.s
@@ -0,0 +1,5 @@
+/// To prevent mistaking -exxx as --entry=xxx, we allow -e xxx but reject -exxx.
+/// GCC -export-dynamic is rejected as well.
+// RUN: not %clang -### --target=x86_64-linux-gnu -export-dynamic %s 2>&1 | FileCheck %s
+
+// CHECK: error: unknown argument: '-export-dynamic'

@MaskRay
Copy link
Member Author

MaskRay commented Nov 21, 2023

Driver used to accept -e but ignore it (at least for Gnu.cpp). My fcf8ada on 2020-07-30 rendered -e (both Joined and Separate). I think if we impose a restriction that -exxx is unsupported, technically it is a breaking change but likely very few projects will notice it (and the issue is pretty straightforward to fix).

This change will get us out of the business to support random -exxx link option that GCC driver happens to accept but we don't, like -export-dynamic #72781 .

@dongjianqiang2 dongjianqiang2 self-requested a review November 23, 2023 12:02
Copy link
Contributor

@dongjianqiang2 dongjianqiang2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MaskRay MaskRay requested a review from brad0 November 26, 2023 05:05
@dongjianqiang2 dongjianqiang2 merged commit 282201d into llvm:main Nov 27, 2023
@MaskRay MaskRay deleted the drv-e branch November 27, 2023 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants