diff options
author | Fangrui Song <i@maskray.me> | 2023-11-15 21:24:12 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-11-15 21:24:12 -0800 |
commit | 291f4a00232b5742940d67e2ecf9168631251317 (patch) | |
tree | 3bd050d2291378b949ec2008e4458adc75fae511 /clang | |
parent | 0f8c51a5230b37331bd62d3e4ad73ac4a5deb106 (diff) | |
download | llvm-291f4a00232b5742940d67e2ecf9168631251317.zip llvm-291f4a00232b5742940d67e2ecf9168631251317.tar.gz llvm-291f4a00232b5742940d67e2ecf9168631251317.tar.bz2 |
[Driver] -rdynamic: remove duplicate -export-dynamic
-export-dynamic is specified twice when -static is not specified. Fix
it.
While here, make some simplification, which can match GCC behavior as a
side benefit: suppress -export-dynamic for -static-pie/-shared. (GCC
passes -export-dynamic when -r is specified. This is unimportant
trivia).
This change largely has no behavior difference, since GNU ld and gold
ignore -export-dynamic when creating a statically linked executable or a
shared object.
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Driver/ToolChains/Gnu.cpp | 15 | ||||
-rw-r--r-- | clang/test/Driver/dynamic-linker.c | 12 |
2 files changed, 11 insertions, 16 deletions
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 19dff4e..7698648 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -417,9 +417,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("text"); } - if (Args.hasArg(options::OPT_rdynamic)) - CmdArgs.push_back("-export-dynamic"); - if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); @@ -459,16 +456,14 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (IsStatic) { CmdArgs.push_back("-static"); - } else { + } else if (!Args.hasArg(options::OPT_r) && + !Args.hasArg(options::OPT_shared) && !IsStaticPIE) { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); - if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE && - !Args.hasArg(options::OPT_r)) { - CmdArgs.push_back("-dynamic-linker"); - CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + - ToolChain.getDynamicLinker(Args))); - } + CmdArgs.push_back("-dynamic-linker"); + CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + + ToolChain.getDynamicLinker(Args))); } CmdArgs.push_back("-o"); diff --git a/clang/test/Driver/dynamic-linker.c b/clang/test/Driver/dynamic-linker.c index c7579f4..555e46ab 100644 --- a/clang/test/Driver/dynamic-linker.c +++ b/clang/test/Driver/dynamic-linker.c @@ -11,11 +11,11 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -### -shared /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s -// RUN: %clang -target armv7-unknown-linux-gnueabi -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED -check-prefix CHECK-RDYNAMIC %s -// RUN: %clang -target i386-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED -check-prefix CHECK-RDYNAMIC %s -// RUN: %clang -target mips64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED -check-prefix CHECK-RDYNAMIC %s -// RUN: %clang -target powerpc64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED -check-prefix CHECK-RDYNAMIC %s -// RUN: %clang -target x86_64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED -check-prefix CHECK-RDYNAMIC %s +// RUN: %clang -target armv7-unknown-linux-gnueabi -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s +// RUN: %clang -target i386-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s +// RUN: %clang -target mips64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s +// RUN: %clang -target powerpc64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s +// RUN: %clang -target x86_64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s // RUN: %clang -target armv7-unknown-linux-gnueabi -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s // RUN: %clang -target i386-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s @@ -23,8 +23,8 @@ // RUN: %clang -target powerpc64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s // RUN: %clang -target x86_64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s -// CHECK-RDYNAMIC: "-export-dynamic" // CHECK-SHARED: "-shared" +// CHECK-RDYNAMIC: "-export-dynamic" // CHECK-STATIC: "-{{B?}}static" // CHECK-DYNAMIC-LINKER: "-dynamic-linker" // CHECK-SHARED-NOT: "-dynamic-linker" |