Skip to content

[Darwin][Driver][clang] Prioritise command line args over DEFAULT_SYSROOT #115993

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

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,17 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,

// Give --sysroot= preference, over the Apple specific behavior to also use
// --isysroot as the syslibroot.
StringRef sysroot = C.getSysRoot();
if (sysroot != "") {
// We check `OPT__sysroot_EQ` directly instead of `getSysRoot` to make sure we
// prioritise command line arguments over configuration of `DEFAULT_SYSROOT`.
if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
CmdArgs.push_back("-syslibroot");
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
CmdArgs.push_back(A->getValue());
} else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
CmdArgs.push_back("-syslibroot");
CmdArgs.push_back(A->getValue());
} else if (StringRef sysroot = C.getSysRoot(); sysroot != "") {
CmdArgs.push_back("-syslibroot");
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
}

Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
Expand Down
3 changes: 1 addition & 2 deletions clang/test/Driver/sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// CHECK-SYSROOTEQ: "-cc1"{{.*}} "-isysroot" "{{[^"]*}}/FOO"

// Apple Darwin uses -isysroot as the syslib root, too.
// We pass --sysroot="" to defeat any -DDEFAULT_SYSROOT parameter.
// RUN: touch %t2.o
// RUN: %clang -target i386-apple-darwin10 \
// RUN: -isysroot /FOO --sysroot="" -### %t2.o 2> %t2
// RUN: -isysroot /FOO -### %t2.o 2> %t2
// RUN: FileCheck --check-prefix=CHECK-APPLE-ISYSROOT < %t2 %s
// CHECK-APPLE-ISYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "{{[^"]*}}/FOO"

Expand Down
Loading