Skip to content

[Driver] Add linker options to support statical linking to shared flang-rt on AIX. #131822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,18 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs a test somewhere at flang/test/Driver/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment!
Yes. I will add test.


// Force static linking when "-static" is present.
if (Args.hasArg(options::OPT_static))
if (Args.hasArg(options::OPT_static)) {
CmdArgs.push_back("-bnso");

if (D.IsFlangMode()) {
// The folllowing linker options are needed to statically link to the
// shared libflang_rt.runtime.a on AIX
CmdArgs.push_back("-bI:/usr/lib/syscalls.exp");
Copy link
Member

@daltenty daltenty Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit misplaced, IIUC these options are needed to link libc statically, not flang_rt itself (-static just happens to mean we link both).

Thus, I think this belongs where we push_back -lc for the AIX toolchain, so here:

CmdArgs.push_back("-lc");

Also, I don't think this really belongs under the -static option, that is really an ld option which says, only link to static libs. Typically there are separate options to link particular runtimes statically. Since this is really for libc, I'd suggest -static-libc.

CmdArgs.push_back("-bI:/usr/lib/threads.exp");
CmdArgs.push_back("-lcrypt");
}
}

// Add options for shared libraries.
if (Args.hasArg(options::OPT_shared)) {
CmdArgs.push_back("-bM:SRE");
Expand Down