Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// '-bnocdtors' that '-Wl' might forward.
CmdArgs.push_back("-bcdtors:all:0:s");

if (Args.hasArg(options::OPT_rpath)) {
for (const auto &bopt : Args.getAllArgValues(options::OPT_b))
// Check -b opts prefix for "libpath:" or exact match for "nolibpath"
if (!bopt.rfind("libpath:", 0) || bopt == "nolibpath")
D.Diag(diag::err_drv_cannot_mix_options) << "-rpath" << "-b" + bopt;

for (const auto &wlopt : Args.getAllArgValues(options::OPT_Wl_COMMA))
// Check -Wl, opts prefix for "-blibpath:" or exact match for
// "-bnolibpath"
if (!wlopt.rfind("-blibpath:", 0) || wlopt == "-bnolibpath")
D.Diag(diag::err_drv_cannot_mix_options) << "-rpath" << "-Wl," + wlopt;

for (const auto &xopt : Args.getAllArgValues(options::OPT_Xlinker))
// Check -Xlinker opts prefix for "-blibpath:" or exact match for
// "-bnolibpath"
if (!xopt.rfind("-blibpath:", 0) || xopt == "-bnolibpath")
D.Diag(diag::err_drv_cannot_mix_options)
<< "-rpath" << "-Xlinker " + xopt;

std::string BlibPathStr = "";
for (const auto &dir : Args.getAllArgValues(options::OPT_rpath))
BlibPathStr += dir + ":";
BlibPathStr += "/usr/lib:/lib";
CmdArgs.push_back(Args.MakeArgString(Twine("-blibpath:") + BlibPathStr));
}

// Specify linker input file(s).
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
TC.AddCXXStdlibLibArgs(Args, CmdArgs);
else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
TC.AddCCKextLibArgs(Args, CmdArgs);
// Do not pass OPT_rpath to linker in AIX
else if (A.getOption().matches(options::OPT_rpath) &&
TC.getTriple().isOSAIX())
continue;
else
A.renderAsInput(Args, CmdArgs);
}
Expand Down
41 changes: 41 additions & 0 deletions clang/test/Driver/aix-rpath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Test -R passing search directories to the linker
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -bfakelibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -bfakelibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bloadmap:-blibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bloadmap:-blibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-fakeblibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck %s
// RUN: %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-fakeblibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck %s

// RUN: %clang %s -bsvr4 -Wl,-R/dir1/ -Wl,-blibpath:/dir2/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-LAST %s
// RUN: %clang %s -bsvr4 -Wl,-R/dir1/ -Wl,-blibpath:/dir2/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-LAST %s
// RUN: %clang %s -bsvr4 -Xlinker -R/dir1/ -Xlinker -blibpath:/dir2/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-LAST %s
// RUN: %clang %s -bsvr4 -Xlinker -R/dir1/ -Xlinker -blibpath:/dir2/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-LAST %s
//
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -bnolibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -bnolibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnolibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERWLBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnolibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERWLBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnoentry,-bnolibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERWLBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnoentry,-bnolibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERWLBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Xlinker -bnolibpath -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERXBN %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Xlinker -bnolibpath -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERXBN %s
//
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -blibpath:/dir3/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERB %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -blibpath:/dir3/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERB %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-blibpath:/dir3/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERWL %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-blibpath:/dir3/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERWL %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnoentr,-blibpath:/dir3/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERWL %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Wl,-bnoentr,-blibpath:/dir3/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERWL %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Xlinker -blibpath:/dir3/ -### 2>&1 --target=powerpc-ibm-aix | FileCheck --check-prefix=CHECK-ERX %s
// RUN: not %clang %s -rpath /dir1/ -rpath /dir2/ -Xlinker -blibpath:/dir3/ -### 2>&1 --target=powerpc64-ibm-aix | FileCheck --check-prefix=CHECK-ERX %s

//CHECK: -blibpath:/dir1/:/dir2/:/usr/lib:/lib
//CHECK-LAST: -blibpath:/dir2/
//CHECK-ERBN: error: cannot specify '-bnolibpath' along with '-rpath'
//CHECK-ERWLBN: error: cannot specify '-Wl,-bnolibpath' along with '-rpath'
//CHECK-ERXBN: error: cannot specify '-Xlinker -bnolibpath' along with '-rpath'
//CHECK-ERB: error: cannot specify '-blibpath:/dir3/' along with '-rpath'
//CHECK-ERWL: error: cannot specify '-Wl,-blibpath:/dir3/' along with '-rpath'
//CHECK-ERX: error: cannot specify '-Xlinker -blibpath:/dir3/' along with '-rpath'
8 changes: 6 additions & 2 deletions clang/test/Driver/at_file_missing.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// stream, and also that @file arguments continue to be processed.

// RUN: echo "-D FOO" > %t.args
// RUN: %clang -rpath @executable_path/../lib @%t.args %s -### 2>&1 | FileCheck %s
// CHECK: "-D" "FOO"
// RUN: %clang -rpath @executable_path/../lib @%t.args %s -### 2>&1 | FileCheck %s \
// RUN: --check-prefixes=%if system-aix %{CHECK-AIX,CHECK-ALL%} \
// RUN: %else %{CHECK-ALL,CHECK%}

// CHECK-ALL: "-D" "FOO"
// CHECK: "-rpath" "@executable_path/../lib"
// CHECK-AIX: "-blibpath:@executable_path/../lib:/usr/lib:/lib"