https://github.com/kkwli updated https://github.com/llvm/llvm-project/pull/235101
>From b0d48f72f3a8320996a4fbbf7031be3d6d60548a Mon Sep 17 00:00:00 2001 From: Kelvin Li <[email protected]> Date: Fri, 23 Oct 2026 16:57:24 -0400 Subject: [PATCH 1/2] [flang][AIX] Enable -b flag This patch is to enable -b flag in flang for AIX only. The '-b <arg>' option is passed to the linker. --- clang/include/clang/Options/Options.td | 1 + clang/lib/Driver/ToolChains/Flang.cpp | 8 ++++++++ flang/docs/ReleaseNotes.md | 2 ++ flang/test/Driver/linker-options.f90 | 12 ++++++++++++ 4 files changed, 23 insertions(+) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index bc2d305fc45242..b65a0c0de6516d 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -1146,6 +1146,7 @@ def bundle__loader : Separate<["-"], "bundle_loader">; def bundle : Flag<["-"], "bundle">; def b : JoinedOrSeparate<["-"], "b">, Flags<[LinkerInput]>, HelpText<"Pass -b <arg> to the linker on AIX">, MetaVarName<"<arg>">, + Visibility<[ClangOption, FlangOption]>, Group<Link_Group>; defm offload_uniform_block : BoolFOption<"offload-uniform-block", diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 94b092e711be64..5b0671e1a442e2 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -1353,6 +1353,14 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, } } + // Reject AIX-specific link option on other targets. + if (!Triple.isOSAIX()) { + for (const Arg *A : Args.filtered(options::OPT_b)) { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << Triple.str(); + } + } + const InputInfo &Input = Inputs[0]; types::ID InputType = Input.getType(); diff --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md index 147b15106b9146..3fe7f989c27713 100644 --- a/flang/docs/ReleaseNotes.md +++ b/flang/docs/ReleaseNotes.md @@ -163,6 +163,8 @@ page](https://llvm.org/releases/). equal the array's declared leading extent, so that the common case has a constant trip count. +- Added `-b <arg>` on AIX, which passes `-b <arg>` to the linker. + ## Windows Support ## Fortran Language Changes in Flang diff --git a/flang/test/Driver/linker-options.f90 b/flang/test/Driver/linker-options.f90 index b07c51452be1b4..ccf1157a7cafd3 100644 --- a/flang/test/Driver/linker-options.f90 +++ b/flang/test/Driver/linker-options.f90 @@ -92,6 +92,18 @@ ! NO-PIE-NOT: "-pie" ! UNUSED: warning: argument unused during compilation: '{{(-no)?}}-pie' ! ------------------------------------------------------------------------------ +! +! On AIX, '-b <arg>' is passed to the linker. +! RUN: %flang --target=powerpc-ibm-aix -bmaxdata:0x80000000 -### %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=B-OPT +! RUN: %flang --target=powerpc-ibm-aix -b maxdata:0x80000000 -### %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=B-OPT +! RUN: not %flang --target=x86_64-unknown-linux-gnu -bmaxdata:0x80000000 -### %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=B-OPT-NON-AIX +! +! B-OPT: "-b" "maxdata:0x80000000" +! B-OPT-NON-AIX: error: unsupported option '-b' for target 'x86_64-unknown-linux-gnu' +! ------------------------------------------------------------------------------ program hello write(*,*), "Hello world!" >From 64d24cdbc5d8ca47dced7b26f582cdc6b46e4469 Mon Sep 17 00:00:00 2001 From: Kelvin Li <[email protected]> Date: Wed, 28 Oct 2026 14:59:43 -0400 Subject: [PATCH 2/2] address review comments --- clang/lib/Driver/ToolChains/Flang.cpp | 3 +-- flang/test/Driver/linker-options.f90 | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 5b0671e1a442e2..d801e359a5d015 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -1355,10 +1355,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, // Reject AIX-specific link option on other targets. if (!Triple.isOSAIX()) { - for (const Arg *A : Args.filtered(options::OPT_b)) { + if (const Arg *A = Args.getLastArg(options::OPT_b)) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getSpelling() << Triple.str(); - } } const InputInfo &Input = Inputs[0]; diff --git a/flang/test/Driver/linker-options.f90 b/flang/test/Driver/linker-options.f90 index ccf1157a7cafd3..1c3a59e87f6e3c 100644 --- a/flang/test/Driver/linker-options.f90 +++ b/flang/test/Driver/linker-options.f90 @@ -94,14 +94,18 @@ ! ------------------------------------------------------------------------------ ! ! On AIX, '-b <arg>' is passed to the linker. -! RUN: %flang --target=powerpc-ibm-aix -bmaxdata:0x80000000 -### %s 2>&1 \ +! RUN: %flang --target=powerpc64-ibm-aix -bmaxdata:0x80000000 -### %s 2>&1 \ ! RUN: | FileCheck %s --check-prefix=B-OPT -! RUN: %flang --target=powerpc-ibm-aix -b maxdata:0x80000000 -### %s 2>&1 \ +! RUN: %flang --target=powerpc64-ibm-aix -b maxdata:0x80000000 -### %s 2>&1 \ ! RUN: | FileCheck %s --check-prefix=B-OPT ! RUN: not %flang --target=x86_64-unknown-linux-gnu -bmaxdata:0x80000000 -### %s 2>&1 \ ! RUN: | FileCheck %s --check-prefix=B-OPT-NON-AIX +! RUN: not %flang --target=x86_64-unknown-linux-gnu -bmaxdata:0x80000000 \ +! RUN: -bmaxstack:2000000 -### %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=B-OPT-NON-AIX --implicit-check-not="error:" ! -! B-OPT: "-b" "maxdata:0x80000000" +! B-OPT: "{{.*}}ld{{(\.lld)?(\.exe)?}}" +! B-OPT-SAME: "-b" "maxdata:0x80000000" ! B-OPT-NON-AIX: error: unsupported option '-b' for target 'x86_64-unknown-linux-gnu' ! ------------------------------------------------------------------------------ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
