[clang] 5da7f30 - [AIX][Clang][K] Create `-K` Option for AIX.

Michael Francis via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 15:53:53 PDT 2023


Author: Michael Francis
Date: 2023-05-08T22:53:44Z
New Revision: 5da7f30f24c4620c4f4425206fbdd0921d333dc0

URL: https://github.com/llvm/llvm-project/commit/5da7f30f24c4620c4f4425206fbdd0921d333dc0
DIFF: https://github.com/llvm/llvm-project/commit/5da7f30f24c4620c4f4425206fbdd0921d333dc0.diff

LOG: [AIX][Clang][K] Create `-K` Option for AIX.

`-K` is a linker option on AIX, that is used to align the header, text, data, and loader sections of the output file so that each section begins on a page boundary.

This patch creates the `-K` option in clang. On non-AIX targets, the "unsupported option" error is thrown.

Differential Revision: https://reviews.llvm.org/D146399

Added: 
    clang/test/Driver/unsupported-target-K.c

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/aix-ld.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 182f0290736d8..496264b74d460 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3421,6 +3421,7 @@ def vfsoverlay : JoinedOrSeparate<["-", "--"], "vfsoverlay">, Flags<[CC1Option,
   HelpText<"Overlay the virtual filesystem described by file over the real file system. "
            "Additionally, pass this overlay file to the linker if it supports it">;
 def imultilib : Separate<["-"], "imultilib">, Group<gfortran_Group>;
+def K : Flag<["-"], "K">, Flags<[LinkerInput]>;
 def keep__private__externs : Flag<["-"], "keep_private_externs">;
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>,
         Group<Link_Group>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 32ba56066af58..c12a6ab88097b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6326,6 +6326,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     }
   }
 
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_K);
+      A && !TC.getTriple().isOSAIX())
+    D.Diag(diag::err_drv_unsupported_opt_for_target)
+        << A->getAsString(Args) << TripleStr;
+
   if (Args.getLastArg(options::OPT_fapple_kext) ||
       (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
     CmdArgs.push_back("-fapple-kext");

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index eb2910db239ff..d5c595495976a 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1096,3 +1096,27 @@
 // CHECK-RELOCATABLE-NOT:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
 // CHECK-RELOCATABLE-NOT:     "-l{{.*}}"
 // CHECK-RELOCATABLE-NOT:     "-L{{.*}}"
+
+// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option.
+// RUN: %clang %s 2>&1 -### \
+// RUN:        --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        --unwindlib=libunwind \
+// RUN:        -K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K %s
+// CHECK-K:     "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-K:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-K:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-K:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
+// CHECK-K:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-K:     "-K"
+
+// Check powerpc-ibm-aix7.1.0.0. -K unused when not linking.
+// RUN: %clang %s 2>&1 -### \
+// RUN:        --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        --unwindlib=libunwind \
+// RUN:        -K \
+// RUN:        -c \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-UNUSED %s
+// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument]

diff  --git a/clang/test/Driver/unsupported-target-K.c b/clang/test/Driver/unsupported-target-K.c
new file mode 100644
index 0000000000000..8b9a6f529c326
--- /dev/null
+++ b/clang/test/Driver/unsupported-target-K.c
@@ -0,0 +1,8 @@
+// Check powerpc64-unknown-linux-gnu. -K not supported.
+// RUN: %clang %s 2>&1 -### \
+// RUN:        --target=powerpc64-unknown-linux-gnu \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        --unwindlib=libunwind \
+// RUN:        -K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-SUPPORT %s
+// CHECK-K-SUPPORT: clang: error: unsupported option '-K' for target 'powerpc64-unknown-linux-gnu'


        


More information about the cfe-commits mailing list