Skip to content

Commit 2f3b708

Browse files
committed
SWDEV-355608 - deprecate/cleanup hipcc link flags
- deprecate -use-staticlib, -use-sharedlib which no longer provide any functional values - use --hip-link instead of specifying the HIP runtime by name when linking - fix linker option bug in HIT test's cmake - update build options for unit tests requiring pthread or rt This is essentially a C++ port of this patch in Perl: ROCm/hip#3128
1 parent 63b13c3 commit 2f3b708

File tree

1 file changed

+24
-49
lines changed

1 file changed

+24
-49
lines changed

amd/hipcc/src/hipBin_amd.h

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,13 @@ const string& HipBinAmd::getHipLdFlags() const {
144144

145145

146146
void HipBinAmd::initializeHipLdFlags() {
147-
string hipLibPath;
148147
string hipLdFlags;
149148
const string& hipClangPath = getCompilerPath();
150149
// If $HIPCC clang++ is not compiled, use clang instead
151150
string hipCC = "\"" + hipClangPath + "/clang++";
152151
if (!fs::exists(hipCC)) {
153152
hipLdFlags = "--driver-mode=g++";
154153
}
155-
hipLibPath = getHipLibPath();
156-
hipLdFlags += " -L\"" + hipLibPath + "\"";
157-
const OsType& os = getOSInfo();
158-
if (os == windows) {
159-
hipLdFlags += " -lamdhip64";
160-
}
161154
hipLdFlags_ = hipLdFlags;
162155
}
163156

@@ -385,17 +378,13 @@ bool HipBinAmd::detectPlatform() {
385378
string HipBinAmd::getHipLibPath() const {
386379
string hipLibPath;
387380
const EnvVariables& env = getEnvVariables();
388-
if (env.hipLibPathEnv_.empty()) {
389-
const string& rocclrHomePath = getRocclrHomePath();
390-
fs::path libPath = rocclrHomePath;
391-
libPath /= "lib";
392-
hipLibPath = libPath.string();
381+
if (!env.hipLibPathEnv_.empty()) {
382+
hipLibPath = env.hipLibPathEnv_;
393383
}
394-
if (hipLibPath.empty()) {
395-
const string& hipPath = getHipPath();
396-
fs::path libPath = hipPath;
397-
libPath /= "lib";
398-
hipLibPath = libPath.string();
384+
else if (!env.hipPathEnv_.empty()) {
385+
fs::path p = env.hipLibPathEnv_;
386+
p /= "lib";
387+
hipLibPath = p.string();
399388
}
400389
return hipLibPath;
401390
}
@@ -500,8 +489,6 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
500489
bool printLDFlags = 0; // print HIPLDFLAGS
501490
bool runCmd = 1;
502491
bool buildDeps = 0;
503-
bool linkType = 1;
504-
bool setLinkType = 0;
505492
string hsacoVersion;
506493
bool funcSupp = 0; // enable function support
507494
bool rdc = 0; // whether -fgpu-rdc is on
@@ -616,14 +603,13 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
616603
compileOnly = 1;
617604
buildDeps = 1;
618605
}
619-
if ((trimarg == "-use-staticlib") && (setLinkType == 0)) {
620-
linkType = 0;
621-
setLinkType = 1;
622-
swallowArg = 1;
606+
if ((trimarg == "-use-staticlib")) {
607+
std::cerr << "Warning: The -use-staticlib option has been deprecated and is no longer needed.\n";
608+
swallowArg = true;
623609
}
624-
if ((trimarg == "-use-sharedlib") && (setLinkType == 0)) {
625-
linkType = 1;
626-
setLinkType = 1;
610+
if ((trimarg == "-use-sharedlib")) {
611+
std::cerr << "Warning: The -use-sharedlib option has been deprecated and is no longer needed.\n";
612+
swallowArg = true;
627613
}
628614
if (hipBinUtilPtr_->stringRegexMatch(arg, "^-O.*")) {
629615
optArg = arg;
@@ -846,11 +832,6 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
846832
if (buildDeps) {
847833
HIPCXXFLAGS += " --cuda-host-only";
848834
}
849-
// Add --hip-link only if it is compile only and -fgpu-rdc is on.
850-
if (rdc && !compileOnly) {
851-
HIPLDFLAGS += " --hip-link";
852-
HIPLDFLAGS += HIPLDARCHFLAGS;
853-
}
854835

855836
// hipcc currrently requires separate compilation of source files,
856837
// ie it is not possible to pass
@@ -884,27 +865,21 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
884865
HIPCXXFLAGS += hip_device_lib_str;
885866
}
886867
}
887-
if (os != windows) {
888-
HIPLDFLAGS += " -lgcc_s -lgcc -lpthread -lm -lrt";
889-
}
890868

891-
if (os != windows && !compileOnly) {
892-
string hipClangVersion, toolArgTemp;
893-
if (linkType == 0) {
894-
toolArgTemp = " -L"+ hipLibPath + "-lamdhip64 -L" +
895-
roccmPath+ "/lib -lhsa-runtime64 -ldl -lnuma " + toolArgs;
896-
toolArgs = toolArgTemp;
897-
} else {
898-
toolArgTemp = toolArgs + " -Wl,-rpath=" + hipLibPath + ":"
899-
+ roccmPath+"/lib -lamdhip64 ";
900-
toolArgs = toolArgTemp;
869+
if (!compileOnly) {
870+
string hip_path = getHipLibPath();
871+
if (!hip_path.empty()) {
872+
HIPLDFLAGS += " -L" + hip_path;
873+
}
874+
HIPLDFLAGS += " --hip-link";
875+
if (rdc) {
876+
HIPLDFLAGS += HIPLDARCHFLAGS;
877+
}
878+
if (!windows) {
879+
HIPLDFLAGS += " --rtlib=compiler-rt -unwindlib=libgcc";
901880
}
902-
903-
hipClangVersion = getCompilerVersion();
904-
// To support __fp16 and _Float16, explicitly link with compiler-rt
905-
toolArgs += " -L" + hipClangPath + "/../lib/clang/" +
906-
hipClangVersion + "/lib/linux -lclang_rt.builtins-x86_64 ";
907881
}
882+
908883
if (!var.hipccCompileFlagsAppendEnv_.empty()) {
909884
HIPCXXFLAGS += " " + var.hipccCompileFlagsAppendEnv_ + " ";
910885
HIPCFLAGS += " " + var.hipccCompileFlagsAppendEnv_ + " ";

0 commit comments

Comments
 (0)