[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
MaskRay wrote: > Weirdly, this leads to `warning: argument unused during compilation: > '-nopie'` rather than `error: unknown argument: '-nopie'` Marking `-nopie` as `TargetSpecific` should change this to an error. https://github.com/openbsd/src has some `-nopie` use cases that haven't migrated. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
glandium wrote: Weirdly, this leads to `warning: argument unused during compilation: '-nopie'` rather than `error: unknown argument: '-nopie'` https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
https://github.com/MaskRay closed https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
MaskRay wrote: Rebase to resolve a merge conflict. No change to the diff otherwise. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/72578 >From 23eb2b42bfb0b7148497b9035615a14dc8b7e67c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 16 Nov 2023 14:09:09 -0800 Subject: [PATCH] [Driver] Make ELF -nopie specific to OpenBSD -no-pie[1]/-nopie is rarely used and among the rare uses almost everwhere uses -no-pie, since GCC does not recognize -nopie. However, OpenBSD seems to use -nopie. Therefore, make -nopie specific to OpenBSD to prevent newer ToolChains (Solaris, SerenityOS) from cargo culting and copying -nopie. [1]: https://reviews.llvm.org/D35462 --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 10 +++--- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 7 ++- clang/test/Driver/android-pie.c | 2 -- clang/test/Driver/pic.c | 6 +++--- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df12ba8fbcb296a..b2f2bcb6ac37910 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5158,7 +5158,7 @@ def nofixprebinding : Flag<["-"], "nofixprebinding">; def nolibc : Flag<["-"], "nolibc">; def nomultidefs : Flag<["-"], "nomultidefs">; def nopie : Flag<["-"], "nopie">, Visibility<[ClangOption, FlangOption]>; -def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>, Alias; +def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>; def noprebind : Flag<["-"], "noprebind">; def noprofilelib : Flag<["-"], "noprofilelib">; def noseglinkedit : Flag<["-"], "noseglinkedit">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index ba95ce9c5a28153..2b1e8f02cf66388 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -294,9 +294,7 @@ static const char *getLDMOption(const llvm::Triple , const ArgList ) { static bool getStaticPIE(const ArgList , const ToolChain ) { bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); - // -no-pie is an alias for -nopie. So, handling -nopie takes care of - // -no-pie as well. - if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) { + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { const Driver = TC.getDriver(); const llvm::opt::OptTable = D.getOpts(); StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); @@ -443,10 +441,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (!IsShared) { - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - IsPIE = A ? A->getOption().matches(options::OPT_pie) -: ToolChain.isPIEDefault(Args); + IsPIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + ToolChain.isPIEDefault(Args)); if (IsPIE) CmdArgs.push_back("-pie"); CmdArgs.push_back("-dynamic-linker"); diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index c8f02161d8311e3..21b9004ef2d52d1 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -116,7 +116,7 @@ void openbsd::Linker::ConstructJob(Compilation , const JobAction , const bool Shared = Args.hasArg(options::OPT_shared); const bool Profiling = Args.hasArg(options::OPT_pg); const bool Pie = Args.hasArg(options::OPT_pie); - const bool Nopie = Args.hasArg(options::OPT_nopie); + const bool Nopie = Args.hasArg(options::OPT_no_pie, options::OPT_nopie); const bool Relocatable = Args.hasArg(options::OPT_r); ArgStringList CmdArgs; diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 96757f07a54974f..485730da7df1f8c 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -49,11 +49,8 @@ static bool getPIE(const ArgList , const ToolChain ) { Args.hasArg(options::OPT_r)) return false; - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - if (!A) -return TC.isPIEDefault(Args); - return A->getOption().matches(options::OPT_pie); + return Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + TC.isPIEDefault(Args)); } // FIXME: Need to handle CLANG_DEFAULT_LINKER here? diff --git a/clang/test/Driver/android-pie.c b/clang/test/Driver/android-pie.c index 8620e185654586c..01720edf98fb170 100644 --- a/clang/test/Driver/android-pie.c +++ b/clang/test/Driver/android-pie.c @@ -36,8 +36,6 @@ // RUN: %clang %s -### -o %t.o 2>&1 -no-pie --target=arm-linux-androideabi24 \ // RUN: | FileCheck
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
https://github.com/brad0 approved this pull request. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
brad0 wrote: Continue with this as is. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
brad0 wrote: > > -nopie is for the linker. We only use -fno-pie for the compiler. > > OK. Then it seems that the driver option `-nopie` for linking should be > removed even for OpenBSD? Let me check something before I say anything further. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
MaskRay wrote: > -nopie is for the linker. We only use -fno-pie for the compiler. OK. Then it seems that the driver option `-nopie` for linking should be removed even for OpenBSD? https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
brad0 wrote: -nopie is for the linker. We only use -fno-pie for the compiler. https://github.com/llvm/llvm-project/pull/72578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Fangrui Song (MaskRay) Changes -no-pie[1]/-nopie is rarely used and among the rare uses almost everwhere uses -no-pie, since GCC does not recognize -nopie. However, OpenBSD seems to prefer -nopie. Therefore, make -nopie specific to OpenBSD to prevent newer ToolChains (Solaris, SerenityOS) from cargo culting and copying -nopie. [1]: https://reviews.llvm.org/D35462 --- Full diff: https://github.com/llvm/llvm-project/pull/72578.diff 6 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+3-7) - (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+2-5) - (modified) clang/test/Driver/android-pie.c (-2) - (modified) clang/test/Driver/pic.c (+3-3) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 811550416110b3d..654bf8be78d6259 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5137,7 +5137,7 @@ def nofixprebinding : Flag<["-"], "nofixprebinding">; def nolibc : Flag<["-"], "nolibc">; def nomultidefs : Flag<["-"], "nomultidefs">; def nopie : Flag<["-"], "nopie">, Visibility<[ClangOption, FlangOption]>; -def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>, Alias; +def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>; def noprebind : Flag<["-"], "noprebind">; def noprofilelib : Flag<["-"], "noprofilelib">; def noseglinkedit : Flag<["-"], "noseglinkedit">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index ba95ce9c5a28153..2b1e8f02cf66388 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -294,9 +294,7 @@ static const char *getLDMOption(const llvm::Triple , const ArgList ) { static bool getStaticPIE(const ArgList , const ToolChain ) { bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); - // -no-pie is an alias for -nopie. So, handling -nopie takes care of - // -no-pie as well. - if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) { + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { const Driver = TC.getDriver(); const llvm::opt::OptTable = D.getOpts(); StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); @@ -443,10 +441,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (!IsShared) { - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - IsPIE = A ? A->getOption().matches(options::OPT_pie) -: ToolChain.isPIEDefault(Args); + IsPIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + ToolChain.isPIEDefault(Args)); if (IsPIE) CmdArgs.push_back("-pie"); CmdArgs.push_back("-dynamic-linker"); diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 5d06cd8ab0bad16..e883838e2dc9317 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -117,7 +117,7 @@ void openbsd::Linker::ConstructJob(Compilation , const JobAction , bool Shared = Args.hasArg(options::OPT_shared); bool Profiling = Args.hasArg(options::OPT_pg); bool Pie = Args.hasArg(options::OPT_pie); - bool Nopie = Args.hasArg(options::OPT_nopie); + bool Nopie = Args.hasArg(options::OPT_no_pie, options::OPT_nopie); const bool Relocatable = Args.hasArg(options::OPT_r); // Silence warning for "clang -g foo.o -o foo" diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 96757f07a54974f..485730da7df1f8c 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -49,11 +49,8 @@ static bool getPIE(const ArgList , const ToolChain ) { Args.hasArg(options::OPT_r)) return false; - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - if (!A) -return TC.isPIEDefault(Args); - return A->getOption().matches(options::OPT_pie); + return Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + TC.isPIEDefault(Args)); } // FIXME: Need to handle CLANG_DEFAULT_LINKER here? diff --git a/clang/test/Driver/android-pie.c b/clang/test/Driver/android-pie.c index 8620e185654586c..01720edf98fb170 100644 --- a/clang/test/Driver/android-pie.c +++ b/clang/test/Driver/android-pie.c @@ -36,8 +36,6 @@ // RUN: %clang %s -### -o %t.o 2>&1 -no-pie --target=arm-linux-androideabi24 \ // RUN: | FileCheck --check-prefix=NO-PIE %s -// RUN: %clang %s -### -o %t.o 2>&1 -nopie --target=arm-linux-androideabi24 \ -// RUN: |
[clang] [Driver] Make ELF -nopie specific to OpenBSD (PR #72578)
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/72578 -no-pie[1]/-nopie is rarely used and among the rare uses almost everwhere uses -no-pie, since GCC does not recognize -nopie. However, OpenBSD seems to prefer -nopie. Therefore, make -nopie specific to OpenBSD to prevent newer ToolChains (Solaris, SerenityOS) from cargo culting and copying -nopie. [1]: https://reviews.llvm.org/D35462 >From 2135d365c1820a23826d16293cc59a65b0ae847e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 16 Nov 2023 14:09:09 -0800 Subject: [PATCH] [Driver] Make ELF -nopie specific to OpenBSD -no-pie[1]/-nopie is rarely used and among the rare uses almost everwhere uses -no-pie, since GCC does not recognize -nopie. However, OpenBSD seems to prefer -nopie. Therefore, make -nopie specific to OpenBSD to prevent newer ToolChains (Solaris, SerenityOS) from cargo culting and copying -nopie. [1]: https://reviews.llvm.org/D35462 --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 10 +++--- clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Solaris.cpp | 7 ++- clang/test/Driver/android-pie.c | 2 -- clang/test/Driver/pic.c | 6 +++--- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 811550416110b3d..654bf8be78d6259 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5137,7 +5137,7 @@ def nofixprebinding : Flag<["-"], "nofixprebinding">; def nolibc : Flag<["-"], "nolibc">; def nomultidefs : Flag<["-"], "nomultidefs">; def nopie : Flag<["-"], "nopie">, Visibility<[ClangOption, FlangOption]>; -def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>, Alias; +def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>; def noprebind : Flag<["-"], "noprebind">; def noprofilelib : Flag<["-"], "noprofilelib">; def noseglinkedit : Flag<["-"], "noseglinkedit">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index ba95ce9c5a28153..2b1e8f02cf66388 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -294,9 +294,7 @@ static const char *getLDMOption(const llvm::Triple , const ArgList ) { static bool getStaticPIE(const ArgList , const ToolChain ) { bool HasStaticPIE = Args.hasArg(options::OPT_static_pie); - // -no-pie is an alias for -nopie. So, handling -nopie takes care of - // -no-pie as well. - if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) { + if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) { const Driver = TC.getDriver(); const llvm::opt::OptTable = D.getOpts(); StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie); @@ -443,10 +441,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (!IsShared) { - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - IsPIE = A ? A->getOption().matches(options::OPT_pie) -: ToolChain.isPIEDefault(Args); + IsPIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + ToolChain.isPIEDefault(Args)); if (IsPIE) CmdArgs.push_back("-pie"); CmdArgs.push_back("-dynamic-linker"); diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 5d06cd8ab0bad16..e883838e2dc9317 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -117,7 +117,7 @@ void openbsd::Linker::ConstructJob(Compilation , const JobAction , bool Shared = Args.hasArg(options::OPT_shared); bool Profiling = Args.hasArg(options::OPT_pg); bool Pie = Args.hasArg(options::OPT_pie); - bool Nopie = Args.hasArg(options::OPT_nopie); + bool Nopie = Args.hasArg(options::OPT_no_pie, options::OPT_nopie); const bool Relocatable = Args.hasArg(options::OPT_r); // Silence warning for "clang -g foo.o -o foo" diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 96757f07a54974f..485730da7df1f8c 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -49,11 +49,8 @@ static bool getPIE(const ArgList , const ToolChain ) { Args.hasArg(options::OPT_r)) return false; - Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie, - options::OPT_nopie); - if (!A) -return TC.isPIEDefault(Args); - return A->getOption().matches(options::OPT_pie); + return Args.hasFlag(options::OPT_pie, options::OPT_no_pie, + TC.isPIEDefault(Args)); } // FIXME: Need to handle CLANG_DEFAULT_LINKER