Skip to content

Commit

Permalink
[Driver] Wrap -lgcc_s in -z ignore/-z record on Solaris (#65487)
Browse files Browse the repository at this point in the history
`clang` currently links `libgcc_s` unconditionally on Solaris, which is
unnecessary.

This patch wraps it in `-z ignore`/`-z record` instead.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.
  • Loading branch information
rorth committed Sep 6, 2023
1 parent d148767 commit b084d10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Solaris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-latomic");
addAsNeededOption(getToolChain(), Args, CmdArgs, false);
}
addAsNeededOption(getToolChain(), Args, CmdArgs, true);
CmdArgs.push_back("-lgcc_s");
addAsNeededOption(getToolChain(), Args, CmdArgs, false);
CmdArgs.push_back("-lc");
if (!Args.hasArg(options::OPT_shared)) {
CmdArgs.push_back("-lgcc");
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Driver/solaris-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
// CHECK-LD-SPARC32-SAME: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD: "-z" "ignore" "-latomic" "-z" "record"
// CHECK-GLD: "--as-needed" "-latomic" "--no-as-needed"
// CHECK-LD-SPARC32-SAME: "-lgcc_s"
// CHECK-LD: "-z" "ignore" "-lgcc_s" "-z" "record"
// CHECK-GLD: "--as-needed" "-lgcc_s" "--no-as-needed"
// CHECK-LD-SPARC32-SAME: "-lc"
// CHECK-LD-SPARC32-SAME: "-lgcc"
// CHECK-LD-SPARC32-SAME: "-lm"
Expand Down

0 comments on commit b084d10

Please sign in to comment.