[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

Anjan Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 28 08:49:21 PDT 2021


anjankgk updated this revision to Diff 362412.
anjankgk added a comment.

Addressed review comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106688/new/

https://reviews.llvm.org/D106688

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/Xlinker-args.c


Index: clang/test/Driver/Xlinker-args.c
===================================================================
--- clang/test/Driver/Xlinker-args.c
+++ clang/test/Driver/Xlinker-args.c
@@ -11,10 +11,20 @@
 // RUN:   -e _start -T a.lds -Xlinker one -Xlinker --no-demangle \
 // RUN:   -Wl,two,--no-demangle,three -Xlinker four -z five -r %s 2> %t
 // RUN: FileCheck -check-prefix=LINUX < %t %s
-//
+
+// RUN: %clang -target powerpc-unknown-aix -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=AIX < %t %s
+
+// RUN: %clang -target powerpc-unknown-linux -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=NOT-AIX < %t %s
+
 // DARWIN-NOT: --no-demangle
 // DARWIN: "one" "two" "three" "four" "-z" "five" "-r"
 // LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" "-r" {{.*}} "-T" "a.lds"
+// AIX: "-b" "one" 
+// NOT-AIX: error: unsupported option '-b one'
 
 // Check that we forward '-Xlinker' and '-Wl,' on Windows.
 // RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -257,6 +257,17 @@
     // Otherwise, this is a linker input argument.
     const Arg &A = II.getInputArg();
 
+    if (A.getOption().matches(options::OPT_b)) {
+      const llvm::Triple &T = TC.getTriple();
+      if (!T.isOSAIX()) {
+        TC.getDriver().Diag(diag::err_drv_unsupported_opt)
+            << A.getAsString(Args);
+      }
+      // Pass -b prefix for AIX linker.
+      A.claim();
+      A.render(Args, CmdArgs);
+    }
+
     // Handle reserved library options.
     if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
       TC.AddCXXStdlibLibArgs(Args, CmdArgs);
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -815,7 +815,9 @@
 def bind__at__load : Flag<["-"], "bind_at_load">;
 def bundle__loader : Separate<["-"], "bundle_loader">;
 def bundle : Flag<["-"], "bundle">;
-def b : JoinedOrSeparate<["-"], "b">, Flags<[Unsupported]>;
+def b : JoinedOrSeparate<["-"], "b">, Flags<[LinkerInput, RenderAsInput]>,
+  HelpText<"Pass -b <arg> to the linker on AIX (only).">, MetaVarName<"<arg>">,
+  Group<Link_Group>;
 def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group<opencl_Group>, Flags<[CC1Option]>,
   HelpText<"OpenCL only. This option disables all optimizations. By default optimizations are enabled.">;
 def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, Group<opencl_Group>, Flags<[CC1Option]>,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106688.362412.patch
Type: text/x-patch
Size: 2747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210728/df6fc483/attachment-0001.bin>


More information about the cfe-commits mailing list