From a10cfef5e7c4b111975821d6acdbca9acc3be418 Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 23 May 2016 14:45:13 -0400
Subject: [PATCH] P4 to Git Change 1272070 by smekhano@stas-nova-hsa on
2016/05/23 14:39:45
SWDEV-85602 - switch to use of linkonce_odr for library and obsolete linkWithModule patches
The linkonce_odr linkage is set to any non-local functions in the library during library build.
Libraries are linked left to right and never back resolved. For that reason clp on the fly library
is moved to the end of the library list. Otherwise by the time clp would like to use the scalar version
of a builtin function for vector expansion this scalar function will not be available anymore.
With the linkonce_odr linkage the linker includes any referenced function from a linked in module.
That is true even for unused declarations. Therefor after every module my new code drops all unused
declarations from the composite. If we do not do it a wrapper library such as builtins-hsail would
reference all symbols from the wrapping library such as ocml and the wrapping library would be linked in
almost as a whole. Dropping unused declarations solves it.
Testing: smoke, pecheckin, conformance 2.0 with and w/o optimization
Reviewed by Nikolay Haustov, Daniil Fukalov and Evgeny Mankov
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#144 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.hpp#17 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/include/AMDResolveLinker.h#4 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/lib/AMDResolveLinker.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/tools/opencl-link/opencl-link.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/include/llvm/Linker/Linker.h#3 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Linker/LinkModules.cpp#51 edit
... //depot/stg/opencl/drivers/opencl/library/x86/common/src/amdrt/build/Makefile.amdrt#24 edit
... //depot/stg/opencl/drivers/opencl/opencldefs#169 edit
---
rocclr/compiler/lib/backends/common/linker.cpp | 12 +++++-------
rocclr/compiler/lib/backends/common/linker.hpp | 3 +--
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp
index 8d9fbfb11c..3e3e549a1c 100644
--- a/rocclr/compiler/lib/backends/common/linker.cpp
+++ b/rocclr/compiler/lib/backends/common/linker.cpp
@@ -266,9 +266,7 @@ static std::set *getAmdRtFunctions()
bool
-amdcl::OCLLinker::linkWithModule(
- llvm::Module* Dst, llvm::Module* Src,
- std::map *ModuleRefMap)
+amdcl::OCLLinker::linkWithModule(llvm::Module* Dst, llvm::Module* Src)
{
#ifndef NDEBUG
if (Options()->oVariables->EnableDebugLinker) {
@@ -277,7 +275,7 @@ amdcl::OCLLinker::linkWithModule(
}
#endif
std::string ErrorMessage;
- if (llvm::linkWithModule(Dst, Src, ModuleRefMap, &ErrorMessage)) {
+ if (llvm::linkWithModule(Dst, Src, &ErrorMessage)) {
DEBUG(llvm::dbgs() << "Error: " << ErrorMessage << "\n");
BuildLog() += "\nInternal Error: linking libraries failed!\n";
LogError("linkWithModule(): linking bc libraries failed!");
@@ -336,7 +334,7 @@ amdcl::OCLLinker::linkLLVMModules(std::vector &libs)
// Link input modules together
for (size_t i = 0; i < libs.size(); ++i) {
DEBUG(llvm::dbgs() << "LinkWithModule " << i << ":\n");
- if (amdcl::OCLLinker::linkWithModule(LLVMBinary(), libs[i], NULL)) {
+ if (amdcl::OCLLinker::linkWithModule(LLVMBinary(), libs[i])) {
Failed = true;
}
}
@@ -724,8 +722,8 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs)
}
if (OnFlyLib) {
- // OnFlyLib must be the last!
- LibMs.push_back(OnFlyLib);
+ // OnFlyLib must be the first!
+ LibMs.insert(LibMs.begin(), OnFlyLib);
}
if (Options()->oVariables->EnableBuildTiming) {
diff --git a/rocclr/compiler/lib/backends/common/linker.hpp b/rocclr/compiler/lib/backends/common/linker.hpp
index 8dc89321cf..09d7a31d33 100644
--- a/rocclr/compiler/lib/backends/common/linker.hpp
+++ b/rocclr/compiler/lib/backends/common/linker.hpp
@@ -77,8 +77,7 @@ namespace amdcl
int link(llvm::Module* input, std::vector &libs);
protected:
bool linkLLVMModules(std::vector &libs);
- bool linkWithModule(llvm::Module* Dst, llvm::Module* Src,
- std::map *ModuleRefMap);
+ bool linkWithModule(llvm::Module* Dst, llvm::Module* Src);
private: