This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ARM/FDPIC v5 03/21] [ARM] FDPIC: Force FDPIC related options unless -mno-fdpic is provided


On 16/07/2019 12:34, Richard Sandiford wrote:
Christophe Lyon <christophe.lyon@st.com> writes:
On 22/05/2019 10:45, Christophe Lyon wrote:
On Wed, 22 May 2019 at 10:39, Szabolcs Nagy <Szabolcs.Nagy@arm.com> wrote:

On 21/05/2019 16:28, Christophe Lyon wrote:
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -89,7 +89,7 @@
   #define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
   #endif
   #define MUSL_DYNAMIC_LINKER \
-  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
+  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E
"%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"

the line break seems wrong (either needs \ or no newline)

Sorry, that's a mailer artifact.

--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -45,7 +45,7 @@ case "${target}" in
          ;;
     sparc*-*-solaris2.11*)
          ;;
-  arm*-*-uclinuxfdpiceabi)
+  arm*-*-fdpiceabi)

should be *fdpiceabi instead of *-fdpiceabi i think.

Indeed, thanks
.

FWIW, here is the updated patch:
- handles musl -fdpic suffix
- disables sanitizers for arm*-*-fdpiceabi
- does not handle -static in a special way, so using -static produces binaries that request the non-existing /usr/lib/ld.so.1, thus effectively making -static broken/unsupported (this does lead to a few more FAIL in the testsuite)

The plan is to work -static-pie later, as discussed.

Could you make -static without -mno-fdpic an error via a %e spec,
so that the failure mode is a bit more user-friendly?

I realise this isn't your preferred option, sorry.


As discussed later, I didn't because I couldn't find a way
to catch linker (-Wl,XXX) options in the specs, and I prefer
to keep the possibility to generic a "static" binary using
"-static -Wl,-dynamic-linker XXX"

However, I've also a new patch in the series to disable tests that involve -static, attached here.


diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h
index e1bacf4..6c25a1a 100644
--- a/gcc/config/arm/bpabi.h
+++ b/gcc/config/arm/bpabi.h
@@ -55,6 +55,8 @@
  #define TARGET_FIX_V4BX_SPEC " %{mcpu=arm8|mcpu=arm810|mcpu=strongarm*"\
    "|march=armv4|mcpu=fa526|mcpu=fa626:--fix-v4bx}"
+#define TARGET_FDPIC_ASM_SPEC ""

Formatting nit: should be a single space before ""

OK

+
  #define BE8_LINK_SPEC							\
    "%{!r:%{!mbe32:%:be8_linkopt(%{mlittle-endian:little}"		\
    "			       %{mbig-endian:big}"			\
@@ -64,7 +66,7 @@
  /* Tell the assembler to build BPABI binaries.  */
  #undef  SUBTARGET_EXTRA_ASM_SPEC
  #define SUBTARGET_EXTRA_ASM_SPEC \
-  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=5}" TARGET_FIX_V4BX_SPEC
+  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=5}" TARGET_FIX_V4BX_SPEC TARGET_FDPIC_ASM_SPEC

Long line.

OK

diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index 66ec0ea..d7cc923 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -89,7 +89,7 @@
  #define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
  #endif
  #define MUSL_DYNAMIC_LINKER \
-  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
+  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
/* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
     use the GNU/Linux version, not the generic BPABI version.  */

Rich, could you confirm that this is (going to be?) the correct name?

This was confirmed by Rich.

diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index 66ec0ea..d7cc923 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -89,7 +89,7 @@
  #define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
  #endif
  #define MUSL_DYNAMIC_LINKER \
-  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
+  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
/* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
     use the GNU/Linux version, not the generic BPABI version.  */
@@ -101,11 +101,14 @@
  #undef  ASAN_CC1_SPEC
  #define ASAN_CC1_SPEC "%{%:sanitize(address):-funwind-tables}"
+#define FDPIC_CC1_SPEC ""
+
  #undef  CC1_SPEC
  #define CC1_SPEC							\
-  LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC,	\
+  LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " "	\
+		       FDPIC_CC1_SPEC,					\
  		       GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " "	\
-		       ANDROID_CC1_SPEC)
+		       ANDROID_CC1_SPEC "" FDPIC_CC1_SPEC)
#define CC1PLUS_SPEC \
    LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)

Does it make sense to add FDPIC_CC1_SPEC to the Android version?

No, now fixed.

diff --git a/gcc/config/arm/uclinuxfdpiceabi.h b/gcc/config/arm/uclinuxfdpiceabi.h
new file mode 100644
index 0000000..3180bcd
--- /dev/null
+++ b/gcc/config/arm/uclinuxfdpiceabi.h
@@ -0,0 +1,52 @@
+/* Configuration file for ARM GNU/Linux FDPIC EABI targets.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   Contributed by STMicroelectronics.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* On uClibc EABI GNU/Linux, we want to force -mfdpic by default,
+   which also means we produce PIE code by default.  */
+#undef FDPIC_CC1_SPEC
+#define FDPIC_CC1_SPEC \
+  "%{!mno-fdpic:-mfdpic %{!no-PIE:%{!fpie:%{!fPIC:%{!fpic: -fPIE}}}}}"

Looks like the !no-PIE should be !fno-PIE.

Thanks for catching this.

+/* Add --fdpic assembler flag by default.  */
+#undef TARGET_FDPIC_ASM_SPEC
+#define TARGET_FDPIC_ASM_SPEC  "%{!mno-fdpic: --fdpic}"

Single space before the ".

OK

Thanks,
Richard
.


Thanks a lot,

Christophe

>From 5a5c74bcfc349af51abf963e1005cfab1a827fcf Mon Sep 17 00:00:00 2001
From: Christophe Lyon <christophe.lyon@linaro.org>
Date: Thu, 8 Feb 2018 11:11:56 +0100
Subject: [ARM/FDPIC v6 03/24] [ARM] FDPIC: Force FDPIC related options unless
 -mno-fdpic is provided
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In FDPIC mode, we set -fPIE unless the user provides -fno-PIE, -fpie,
-fPIC or -fpic: indeed FDPIC code is PIC, but we want to generate code
for executables rather than shared libraries by default.

We also make sure to use the --fdpic assembler option, and select the
appropriate linker emulation.

At link time, we also default to -pie, unless we are generating a
shared library or a relocatable file (-r). Note that static link is
not supported as it requires specifying the dynamic linker because the
executable still has to relocate itself at startup.

We also force 'now' binding since lazy binding is not supported.

We should also apply the same behavior for -Wl,-Ur as for -r, but I
couldn't find how to describe that in the specs fragment.

2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>
	Mickaël Guêné <mickael.guene@st.com>

	gcc/
	* config.gcc: Handle arm*-*-uclinuxfdpiceabi.
	* config/arm/bpabi.h (TARGET_FDPIC_ASM_SPEC): New.
	(SUBTARGET_EXTRA_ASM_SPEC): Use TARGET_FDPIC_ASM_SPEC.
	* config/arm/linux-eabi.h (FDPIC_CC1_SPEC): New.
	(CC1_SPEC): Use FDPIC_CC1_SPEC.
	(MUSL_DYNAMIC_LINKER): Add -fdpic suffix when needed.
	* config/arm/uclinuxfdpiceabi.h: New file.

	libsanitizer/
	* configure.tgt (arm*-*-*fdpiceabi): Sanitizers are
	unsupported in this configuration.

Change-Id: I74ac1fbb2e809e864d2b0acce66b173e76bcf92b

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 67780fb..495cbc2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1177,6 +1177,11 @@ arm*-*-linux-* | arm*-*-uclinuxfdpiceabi)			# ARM GNU/Linux with ELF
 	esac
 	tmake_file="${tmake_file} arm/t-arm arm/t-arm-elf arm/t-bpabi arm/t-linux-eabi"
 	tm_file="$tm_file arm/bpabi.h arm/linux-eabi.h arm/aout.h arm/arm.h"
+	case $target in
+	arm*-*-uclinuxfdpiceabi)
+	    tm_file="$tm_file arm/uclinuxfdpiceabi.h"
+	    ;;
+	esac
 	# Generation of floating-point instructions requires at least ARMv5te.
 	if [ "$with_float" = "hard" -o "$with_float" = "softfp" ] ; then
 	    target_cpu_cname="arm10e"
diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h
index e1bacf4..75d9a99 100644
--- a/gcc/config/arm/bpabi.h
+++ b/gcc/config/arm/bpabi.h
@@ -55,6 +55,8 @@
 #define TARGET_FIX_V4BX_SPEC " %{mcpu=arm8|mcpu=arm810|mcpu=strongarm*"\
   "|march=armv4|mcpu=fa526|mcpu=fa626:--fix-v4bx}"
 
+#define TARGET_FDPIC_ASM_SPEC ""
+
 #define BE8_LINK_SPEC							\
   "%{!r:%{!mbe32:%:be8_linkopt(%{mlittle-endian:little}"		\
   "			       %{mbig-endian:big}"			\
@@ -64,7 +66,8 @@
 /* Tell the assembler to build BPABI binaries.  */
 #undef  SUBTARGET_EXTRA_ASM_SPEC
 #define SUBTARGET_EXTRA_ASM_SPEC \
-  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=5}" TARGET_FIX_V4BX_SPEC
+  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=5}" TARGET_FIX_V4BX_SPEC \
+  TARGET_FDPIC_ASM_SPEC
 
 #ifndef SUBTARGET_EXTRA_LINK_SPEC
 #define SUBTARGET_EXTRA_LINK_SPEC ""
diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index 66ec0ea..b348971 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -89,7 +89,7 @@
 #define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
 #endif
 #define MUSL_DYNAMIC_LINKER \
-  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
+  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
 
 /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
    use the GNU/Linux version, not the generic BPABI version.  */
@@ -101,9 +101,12 @@
 #undef  ASAN_CC1_SPEC
 #define ASAN_CC1_SPEC "%{%:sanitize(address):-funwind-tables}"
 
+#define FDPIC_CC1_SPEC ""
+
 #undef  CC1_SPEC
 #define CC1_SPEC							\
-  LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC,	\
+  LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " "	\
+		       FDPIC_CC1_SPEC,					\
 		       GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " "	\
 		       ANDROID_CC1_SPEC)
 
diff --git a/gcc/config/arm/uclinuxfdpiceabi.h b/gcc/config/arm/uclinuxfdpiceabi.h
new file mode 100644
index 0000000..2d0c04b
--- /dev/null
+++ b/gcc/config/arm/uclinuxfdpiceabi.h
@@ -0,0 +1,54 @@
+/* Configuration file for ARM GNU/Linux FDPIC EABI targets.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   Contributed by STMicroelectronics.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+/* On uClibc EABI GNU/Linux, we want to force -mfdpic by default,
+   which also means we produce PIE code by default.  */
+#undef FDPIC_CC1_SPEC
+#define FDPIC_CC1_SPEC \
+  "%{!mno-fdpic:-mfdpic %{!fno-PIE:%{!fpie:%{!fPIC:%{!fpic: -fPIE}}}}}"
+
+/* Add --fdpic assembler flag by default.  */
+#undef TARGET_FDPIC_ASM_SPEC
+#define TARGET_FDPIC_ASM_SPEC "%{!mno-fdpic: --fdpic}"
+
+/* TARGET_BIG_ENDIAN_DEFAULT is set in
+   config.gcc for big endian configurations.  */
+#if TARGET_BIG_ENDIAN_DEFAULT
+#define TARGET_FDPIC_LINKER_EMULATION "armelfb_linux_fdpiceabi"
+#else
+#define TARGET_FDPIC_LINKER_EMULATION "armelf_linux_fdpiceabi"
+#endif
+
+/* Unless we generate a shared library or a relocatable object, we
+   force -pie.  */
+/* -static is not supported, because we have to define the
+   dynamic-linker, as we have some relocations to resolve at load
+   time. We do not generate an error in case the user explictly passes
+   the -dynamic-linker option to the linker.  */
+#undef  SUBTARGET_EXTRA_LINK_SPEC
+#define SUBTARGET_EXTRA_LINK_SPEC			    \
+  "%{!mno-fdpic: -m " TARGET_FDPIC_LINKER_EMULATION	    \
+   "%{!shared:%{!r: -pie}} }"				    \
+  "%{mno-fdpic: -m " TARGET_LINKER_EMULATION "}"	    \
+  "%{!r:%{!mno-fdpic: -z now}}"
+
+#undef	STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!mno-fdpic:%{!shared:crtreloc.o%s}} " \
+  LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index b241ddb..34b21f8 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -45,6 +45,9 @@ case "${target}" in
 	;;
   sparc*-*-solaris2.11*)
 	;;
+  arm*-*-*fdpiceabi)
+	UNSUPPORTED=1
+	;;
   arm*-*-linux*)
 	;;
   mips*64*-*-linux*)
-- 
2.6.3

>From b3b1fef359d8fa75a6e06886c5dad7d58e1e5b84 Mon Sep 17 00:00:00 2001
From: Christophe Lyon <christophe.lyon@linaro.org>
Date: Thu, 29 Aug 2019 13:13:02 +0000
Subject: [ARM/FDPIC v6 22/24] [ARM][testsuite] FDPIC: Skip tests that require
 -static support

Since FDPIC does not support -static, skip the related tests.

2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

	gcc/testsuite/
	* lib/target-supports.exp (check_effective_target_static): Disable
	for ARM FDPIC target.

Change-Id: I119d0541e53f2f1e531540b20e7bc47d8338d89a

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 3f091c5..0c1ddcf 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -1070,6 +1070,9 @@ proc check_effective_target_pe_aligned_commons {} {
 
 # Return 1 if the target supports -static
 proc check_effective_target_static {} {
+    if { [istarget arm*-*-uclinuxfdpiceabi] } {
+	return 0;
+    }
     return [check_no_compiler_messages static executable {
 	int main (void) { return 0; }
     } "-static"]
-- 
2.6.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]