Skip to content

Commit 291f4a0

Browse files
committed
[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.
1 parent 0f8c51a commit 291f4a0

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
417417
CmdArgs.push_back("text");
418418
}
419419

420-
if (Args.hasArg(options::OPT_rdynamic))
421-
CmdArgs.push_back("-export-dynamic");
422-
423420
if (Args.hasArg(options::OPT_s))
424421
CmdArgs.push_back("-s");
425422

@@ -459,16 +456,14 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
459456

460457
if (IsStatic) {
461458
CmdArgs.push_back("-static");
462-
} else {
459+
} else if (!Args.hasArg(options::OPT_r) &&
460+
!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
463461
if (Args.hasArg(options::OPT_rdynamic))
464462
CmdArgs.push_back("-export-dynamic");
465463

466-
if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE &&
467-
!Args.hasArg(options::OPT_r)) {
468-
CmdArgs.push_back("-dynamic-linker");
469-
CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
470-
ToolChain.getDynamicLinker(Args)));
471-
}
464+
CmdArgs.push_back("-dynamic-linker");
465+
CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
466+
ToolChain.getDynamicLinker(Args)));
472467
}
473468

474469
CmdArgs.push_back("-o");

clang/test/Driver/dynamic-linker.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
// RUN: %clang -target x86_64-unknown-linux-gnu -### -shared /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
1212

1313

14-
// 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
15-
// 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
16-
// 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
17-
// 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
18-
// 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
14+
// RUN: %clang -target armv7-unknown-linux-gnueabi -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
15+
// RUN: %clang -target i386-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
16+
// RUN: %clang -target mips64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
17+
// RUN: %clang -target powerpc64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
18+
// RUN: %clang -target x86_64-unknown-linux-gnu -### -shared -rdynamic /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-SHARED %s
1919

2020
// RUN: %clang -target armv7-unknown-linux-gnueabi -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
2121
// RUN: %clang -target i386-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
2222
// RUN: %clang -target mips64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
2323
// RUN: %clang -target powerpc64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
2424
// RUN: %clang -target x86_64-unknown-linux-gnu -### -static /dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
2525

26-
// CHECK-RDYNAMIC: "-export-dynamic"
2726
// CHECK-SHARED: "-shared"
27+
// CHECK-RDYNAMIC: "-export-dynamic"
2828
// CHECK-STATIC: "-{{B?}}static"
2929
// CHECK-DYNAMIC-LINKER: "-dynamic-linker"
3030
// CHECK-SHARED-NOT: "-dynamic-linker"

0 commit comments

Comments
 (0)