dkA64 gcc patch: add support for -mtp=soft (needed for Switch TLS)

This commit is contained in:
fincs 2017-10-16 15:03:11 +02:00 committed by Dave Murphy
parent 609cfef3f5
commit 2502104350

View File

@ -1,6 +1,7 @@
diff -NBaur gcc-7.2.0/gcc/config/aarch64/aarch64-elf-raw.h gcc-7.2.0-aarch64/gcc/config/aarch64/aarch64-elf-raw.h
--- gcc-7.2.0/gcc/config/aarch64/aarch64-elf-raw.h 2017-01-01 12:07:43.905435000 +0000
+++ gcc-7.2.0-aarch64/gcc/config/aarch64/aarch64-elf-raw.h 2017-09-11 09:44:35.042230491 +0100
diff --git a/gcc/config/aarch64/aarch64-elf-raw.h b/gcc/config/aarch64/aarch64-elf-raw.h
index c56261062..3a5b4b012 100644
--- a/gcc/config/aarch64/aarch64-elf-raw.h
+++ b/gcc/config/aarch64/aarch64-elf-raw.h
@@ -22,6 +22,7 @@
#ifndef GCC_AARCH64_ELF_RAW_H
#define GCC_AARCH64_ELF_RAW_H
@ -9,10 +10,128 @@ diff -NBaur gcc-7.2.0/gcc/config/aarch64/aarch64-elf-raw.h gcc-7.2.0-aarch64/gcc
#define STARTFILE_SPEC " crti%O%s crtbegin%O%s crt0%O%s"
#define ENDFILE_SPEC \
" crtend%O%s crtn%O%s " \
diff -NBaur gcc-7.2.0/gcc/config/aarch64/t-aarch64 gcc-7.2.0-aarch64/gcc/config/aarch64/t-aarch64
--- gcc-7.2.0/gcc/config/aarch64/t-aarch64 2017-01-01 12:07:43.905435000 +0000
+++ gcc-7.2.0-aarch64/gcc/config/aarch64/t-aarch64 2017-09-11 09:44:35.042230491 +0100
@@ -68,5 +68,7 @@
diff --git a/gcc/config/aarch64/aarch64-opts.h b/gcc/config/aarch64/aarch64-opts.h
index ba5d052e9..d5e83b60d 100644
--- a/gcc/config/aarch64/aarch64-opts.h
+++ b/gcc/config/aarch64/aarch64-opts.h
@@ -48,6 +48,12 @@ enum aarch64_tls_type {
TLS_DESCRIPTORS
};
+/* Which thread pointer access sequence to use. */
+enum aarch64_tp_type {
+ TP_HARD,
+ TP_SOFT
+};
+
/* The code model defines the address generation strategy.
Most have a PIC and non-PIC variant. */
enum aarch64_code_model {
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1bd010be7..6180fd2cd 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -10015,8 +10015,24 @@ aarch64_load_tp (rtx target)
|| !register_operand (target, Pmode))
target = gen_reg_rtx (Pmode);
- /* Can return in any reg. */
- emit_insn (gen_aarch64_load_tp_hard (target));
+ if (TARGET_HARD_TP)
+ {
+ /* Can return in any reg. */
+ emit_insn (gen_aarch64_load_tp_hard (target));
+ }
+ else
+ {
+ /* Always returned in r0. Immediately copy the result into a pseudo,
+ otherwise other uses of r0 (e.g. setting up function arguments) may
+ clobber the value. */
+
+ rtx tmp;
+
+ emit_insn (gen_aarch64_load_tp_soft ());
+
+ tmp = gen_rtx_REG (DImode, R0_REGNUM);
+ emit_move_insn (target, tmp);
+ }
return target;
}
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index e4fb96fd0..e72e917ec 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -887,6 +887,10 @@ typedef struct
/* Check TLS Descriptors mechanism is selected. */
#define TARGET_TLS_DESC (aarch64_tls_dialect == TLS_DESCRIPTORS)
+/* Check selected thread pointer access sequence to use. */
+#define TARGET_HARD_TP (target_thread_pointer == TP_HARD)
+#define TARGET_SOFT_TP (target_thread_pointer == TP_SOFT)
+
extern enum aarch64_code_model aarch64_cmodel;
/* When using the tiny addressing model conditional and unconditional branches
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 51368e29f..931dc181d 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -5230,11 +5230,22 @@
(define_insn "aarch64_load_tp_hard"
[(set (match_operand:DI 0 "register_operand" "=r")
(unspec:DI [(const_int 0)] UNSPEC_TLS))]
- ""
- "mrs\\t%0, tpidr_el0"
+ "TARGET_HARD_TP"
+ "mrs\\t%0, tpidr_el0\\t// aarch64_load_tp_hard"
[(set_attr "type" "mrs")]
)
+(define_insn "aarch64_load_tp_soft"
+ [(set (reg:DI 0) (unspec:DI [(const_int 0)] UNSPEC_TLS))
+ (clobber (reg:DI IP0_REGNUM))
+ (clobber (reg:DI IP1_REGNUM))
+ (clobber (reg:DI LR_REGNUM))
+ (clobber (reg:CC CC_REGNUM))]
+ "TARGET_SOFT_TP"
+ "bl\\t__aarch64_read_tp\\t// aarch64_load_tp_soft"
+ [(set_attr "type" "branch")]
+)
+
;; The TLS ABI specifically requires that the compiler does not schedule
;; instructions in the TLS stubs, in order to enable linker relaxation.
;; Therefore we treat the stubs as an atomic sequence.
diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt
index 942a7d558..0f18d8e77 100644
--- a/gcc/config/aarch64/aarch64.opt
+++ b/gcc/config/aarch64/aarch64.opt
@@ -115,6 +115,20 @@ Enum(aarch64_tls_size) String(32) Value(32)
EnumValue
Enum(aarch64_tls_size) String(48) Value(48)
+mtp=
+Target RejectNegative Joined Enum(aarch64_tp_type) Var(target_thread_pointer) Init(TP_HARD)
+Specify how to access the thread pointer.
+
+Enum
+Name(aarch64_tp_type) Type(enum aarch64_tp_type)
+Valid arguments to -mtp=:
+
+EnumValue
+Enum(aarch64_tp_type) String(hard) Value(TP_HARD)
+
+EnumValue
+Enum(aarch64_tp_type) String(soft) Value(TP_SOFT)
+
march=
Target RejectNegative ToLower Joined Var(aarch64_arch_string)
-march=ARCH Use features of architecture ARCH.
diff --git a/gcc/config/aarch64/t-aarch64 b/gcc/config/aarch64/t-aarch64
index 32532864c..581474f1d 100644
--- a/gcc/config/aarch64/t-aarch64
+++ b/gcc/config/aarch64/t-aarch64
@@ -68,5 +68,7 @@ cortex-a57-fma-steering.o: $(srcdir)/config/aarch64/cortex-a57-fma-steering.c \
$(srcdir)/config/aarch64/cortex-a57-fma-steering.c
comma=,
@ -22,10 +141,11 @@ diff -NBaur gcc-7.2.0/gcc/config/aarch64/t-aarch64 gcc-7.2.0-aarch64/gcc/config/
+MULTILIB_DIRNAMES = large pic
+MULTILIB_REQUIRED = mcmodel=large fPIC
+MULTILIB_MATCHES = fPIC=fpic fPIC=fpie fPIC=fPIE
diff -NBaur gcc-7.2.0/gcc/gcc.c gcc-7.2.0-aarch64/gcc/gcc.c
--- gcc-7.2.0/gcc/gcc.c 2017-06-22 12:38:56.224791000 +0100
+++ gcc-7.2.0-aarch64/gcc/gcc.c 2017-09-11 09:44:35.042230491 +0100
@@ -779,6 +779,11 @@
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 9721f94b4..d7cd97b0e 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -779,6 +779,11 @@ proper position among the other output files. */
#endif
#endif
@ -37,7 +157,7 @@ diff -NBaur gcc-7.2.0/gcc/gcc.c gcc-7.2.0-aarch64/gcc/gcc.c
/* config.h can define STARTFILE_SPEC to override the default crt0 files. */
#ifndef STARTFILE_SPEC
#define STARTFILE_SPEC \
@@ -1074,6 +1079,7 @@
@@ -1074,6 +1079,7 @@ static const char *link_spec = LINK_SPEC;
static const char *lib_spec = LIB_SPEC;
static const char *link_gomp_spec = "";
static const char *libgcc_spec = LIBGCC_SPEC;
@ -45,7 +165,7 @@ diff -NBaur gcc-7.2.0/gcc/gcc.c gcc-7.2.0-aarch64/gcc/gcc.c
static const char *endfile_spec = ENDFILE_SPEC;
static const char *startfile_spec = STARTFILE_SPEC;
static const char *linker_name_spec = LINKER_NAME;
@@ -1579,6 +1585,7 @@
@@ -1579,6 +1585,7 @@ static struct spec_list static_specs[] =
INIT_STATIC_SPEC ("lib", &lib_spec),
INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
@ -53,34 +173,11 @@ diff -NBaur gcc-7.2.0/gcc/gcc.c gcc-7.2.0-aarch64/gcc/gcc.c
INIT_STATIC_SPEC ("startfile", &startfile_spec),
INIT_STATIC_SPEC ("cross_compile", &cross_compile),
INIT_STATIC_SPEC ("version", &compiler_version),
diff -NBaur gcc-7.2.0/libcpp/Makefile.in gcc-7.2.0-aarch64/libcpp/Makefile.in
--- gcc-7.2.0/libcpp/Makefile.in 2017-08-14 09:03:31.162084275 +0100
+++ gcc-7.2.0-aarch64/libcpp/Makefile.in 2017-09-11 09:44:35.042230491 +0100
@@ -208,8 +208,7 @@
# Note that we put the dependencies into a .Tpo file, then move them
# into place if the compile succeeds. We need this because gcc does
# not atomically write the dependency output file.
-COMPILE = $(COMPILE.base) -o $@ -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Tpo
-POSTCOMPILE = @mv $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+COMPILE = $(COMPILE.base) -o $@
else
COMPILE = source='$<' object='$@' libtool=no DEPDIR=$(DEPDIR) $(DEPMODE) \
$(depcomp) $(COMPILE.base)
diff -NBaur gcc-7.2.0/libgcc/crtstuff.c gcc-7.2.0-aarch64/libgcc/crtstuff.c
--- gcc-7.2.0/libgcc/crtstuff.c 2017-01-01 12:07:43.905435000 +0000
+++ gcc-7.2.0-aarch64/libgcc/crtstuff.c 2017-09-11 09:44:35.046230483 +0100
@@ -47,6 +47,7 @@
/* Target machine header files require this define. */
#define IN_LIBGCC2
+#define USED_FOR_TARGET
/* FIXME: Including auto-host is incorrect, but until we have
identified the set of defines that need to go into auto-target.h,
diff -NBaur gcc-7.2.0/libgcc/Makefile.in gcc-7.2.0-aarch64/libgcc/Makefile.in
--- gcc-7.2.0/libgcc/Makefile.in 2017-04-19 09:08:44.446150000 +0100
+++ gcc-7.2.0-aarch64/libgcc/Makefile.in 2017-09-11 09:44:35.046230483 +0100
@@ -844,7 +844,7 @@
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index a1a392de8..6d3d71b93 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -844,7 +844,7 @@ endif
# libgcc_eh.a, only LIB2ADDEH matters. If we do, only LIB2ADDEHSTATIC and
# LIB2ADDEHSHARED matter. (Usually all three are identical.)
@ -89,3 +186,15 @@ diff -NBaur gcc-7.2.0/libgcc/Makefile.in gcc-7.2.0-aarch64/libgcc/Makefile.in
ifeq ($(enable_shared),yes)
diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index 52ed6d39c..85f6a66fb 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -47,6 +47,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
/* Target machine header files require this define. */
#define IN_LIBGCC2
+#define USED_FOR_TARGET
/* FIXME: Including auto-host is incorrect, but until we have
identified the set of defines that need to go into auto-target.h,