Skip to content

Commit

Permalink
[AIX][Clang][K] Create -K Option for AIX.
Browse files Browse the repository at this point in the history
`-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
  • Loading branch information
KappaMikey1337 committed May 8, 2023
1 parent d15491e commit 5da7f30
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Expand Up @@ -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>;
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Expand Up @@ -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");
Expand Down
24 changes: 24 additions & 0 deletions clang/test/Driver/aix-ld.c
Expand Up @@ -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]
8 changes: 8 additions & 0 deletions 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'

0 comments on commit 5da7f30

Please sign in to comment.