From: Joseph Huber Date: Fri, 4 Feb 2022 17:51:10 +0000 (-0500) Subject: [OpenMP] Add -Bsymbolic to arguments for GNU linker X-Git-Tag: upstream/15.0.7~17743 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eeb29c8477d96ad821b3283dad8ed060a3426118;p=platform%2Fupstream%2Fllvm.git [OpenMP] Add -Bsymbolic to arguments for GNU linker This patch adds the '-Bsymbolic' flag when we perform linking for the offloading device. We already pass '-fvisibility=protected' but this is not properly handled when using the bfd linker as is described in https://maskray.me/blog/2021-05-16-elf-interposition-and-bsymbolic. Previously this caused linker errors when creating the shared library. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D119018 --- diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 12eaf1f..d0808d0 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -572,6 +572,14 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, } CmdArgs.push_back("-lm"); } + + // If we are linking for the device all symbols should be bound locally. The + // symbols are already protected which makes this redundant. This is only + // necessary to work around a problem in bfd. + // TODO: Remove this once 'lld' becomes the only linker for offloading. + if (JA.isDeviceOffloading(Action::OFK_OpenMP)) + CmdArgs.push_back("-Bsymbolic"); + // Silence warnings when linking C code with a C++ '-stdlib' argument. Args.ClaimAllArgs(options::OPT_stdlib_EQ);