[clang] 291f4a0 - [Driver] -rdynamic: remove duplicate -export-dynamic
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 21:24:16 PST 2023
Author: Fangrui Song
Date: 2023-11-15T21:24:12-08:00
New Revision: 291f4a00232b5742940d67e2ecf9168631251317
URL: https://github.com/llvm/llvm-project/commit/291f4a00232b5742940d67e2ecf9168631251317
DIFF: https://github.com/llvm/llvm-project/commit/291f4a00232b5742940d67e2ecf9168631251317.diff
LOG: [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.
Added:
Modified:
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/dynamic-linker.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 19dff4ec4d45e08..76986481686adc6 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 c7579f4af15bd33..555e46aba5f069b 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"
More information about the cfe-commits
mailing list