Skip to content

Commit 896bdd6

Browse files
MaskRaySixWeining
authored andcommitted
[Driver] Default LoongArch to -fno-direct-access-external-data for non-PIC (llvm#72221)
For -fno-pic, if an extern variable is defined in a DSO, a copy relocation will be needed. However, loongarch*-linux does not and will not support copy relocations. Change Driver to default to -fno-direct-access-external-data for LoongArch && non-PIC. Keep Frontend conditions unchanged (-fdirect-access-external-data || -fno-direct-access-external-data && PIC>0 => direct access). Fix llvm#71645 (cherry picked from commit 47eeee2) Change-Id: I9be865d2a200fcaf6e1aca6e784d85410f7f56ab
1 parent 3131389 commit 896bdd6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5595,10 +5595,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
55955595
// defaults to -fno-direct-access-external-data. Pass the option if different
55965596
// from the default.
55975597
if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
5598-
options::OPT_fno_direct_access_external_data))
5598+
options::OPT_fno_direct_access_external_data)) {
55995599
if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
56005600
(PICLevel == 0))
56015601
A->render(Args, CmdArgs);
5602+
} else if (PICLevel == 0 && Triple.isLoongArch()) {
5603+
// Some targets default to -fno-direct-access-external-data even for
5604+
// -fno-pic.
5605+
CmdArgs.push_back("-fno-direct-access-external-data");
5606+
}
56025607

56035608
if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
56045609
CmdArgs.push_back("-fno-plt");

clang/test/Driver/fdirect-access-external-data.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
// RUN: %clang -### -c -target aarch64 %s -fpic 2>&1 | FileCheck %s --check-prefix=DEFAULT
1010
// RUN: %clang -### -c -target aarch64 %s -fpic -fdirect-access-external-data 2>&1 | FileCheck %s --check-prefix=DIRECT
1111

12+
/// loongarch* targets default to -fno-direct-access-external-data even for -fno-pic.
13+
// RUN: %clang -### -c --target=loongarch64 -fno-pic %s 2>&1 | FileCheck %s --check-prefix=INDIRECT
14+
// RUN: %clang -### -c --target=loongarch64 -fpie %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
15+
// RUN: %clang -### -c --target=loongarch32 -fno-pic -fdirect-access-external-data %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
16+
// RUN: %clang -### -c --target=loongarch32 -fpie -fdirect-access-external-data %s 2>&1 | FileCheck %s --check-prefix=DIRECT
17+
1218
// DEFAULT-NOT: direct-access-external-data"
1319
// DIRECT: "-fdirect-access-external-data"
1420
// INDIRECT: "-fno-direct-access-external-data"

0 commit comments

Comments
 (0)