Author: Kelvin Li
Date: 2026-11-02T22:00:09-05:00
New Revision: cbb28a1598fdf78035bbfc86db1c33af6d8002ba

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

LOG: [flang][AIX] Enable -b flag (#235101)

This patch is to enable -b flag in flang for AIX only. The '-b <arg>'
option is passed to the linker.

Added: 
    

Modified: 
    clang/include/clang/Options/Options.td
    clang/lib/Driver/ToolChains/Flang.cpp
    flang/docs/ReleaseNotes.md
    flang/test/Driver/linker-options.f90

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 4275eba62bac30..db186f34626128 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..d801e359a5d015 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1353,6 +1353,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
     }
   }
 
+  // Reject AIX-specific link option on other targets.
+  if (!Triple.isOSAIX()) {
+    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];
   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..1c3a59e87f6e3c 100644
--- a/flang/test/Driver/linker-options.f90
+++ b/flang/test/Driver/linker-options.f90
@@ -92,6 +92,22 @@
 ! NO-PIE-NOT: "-pie"
 ! UNUSED: warning: argument unused during compilation: '{{(-no)?}}-pie'
 ! 
------------------------------------------------------------------------------
+!
+! On AIX, '-b <arg>' is passed to the linker.
+! RUN: %flang --target=powerpc64-ibm-aix -bmaxdata:0x80000000 -### %s 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=B-OPT
+! 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: "{{.*}}ld{{(\.lld)?(\.exe)?}}"
+! B-OPT-SAME: "-b" "maxdata:0x80000000"
+! B-OPT-NON-AIX: error: unsupported option '-b' for target 
'x86_64-unknown-linux-gnu'
+! 
------------------------------------------------------------------------------
 
 program hello
   write(*,*), "Hello world!"


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to