Message ID | 20181011133518.17258-4-christophe.lyon@st.com |
---|---|
State | Superseded |
Headers | show |
Series | FDPIC ABI for ARM | expand |
On 11/10/18 14:34, Christophe Lyon wrote: > 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 even for static > link, we must specify 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. > > 2018-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. > * config/arm/uclinuxfdpiceabi.h: New file. > > libsanitizer/ > * configure.tgt (arm*-*-uclinuxfdpiceabi): Sanitizers are > unsupported in this configuration. The documentation (in patch 1) seems to imply that -mfdpic is available in all configurations and has certain effects (such as enabling -fPIE), but this patch set suggests that such behaviours are only available when the compiler is configured explicitly for an fdpic target. I think this needs to be resolved. Either -mfdpic works everywhere, or the option should only be available when configured for -mfdpic. R. > > Change-Id: If369e0a10bb916fd72e38f71498d3c640fa85c4c > > diff --git a/gcc/config.gcc b/gcc/config.gcc > index 793fc69..a4f4331 100644 > --- a/gcc/config.gcc > +++ b/gcc/config.gcc > @@ -1144,6 +1144,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 1e3ecfb..5901154 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,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 > > #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 8585fde..4cee958 100644 > --- a/gcc/config/arm/linux-eabi.h > +++ b/gcc/config/arm/linux-eabi.h > @@ -98,11 +98,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) > diff --git a/gcc/config/arm/uclinuxfdpiceabi.h b/gcc/config/arm/uclinuxfdpiceabi.h > new file mode 100644 > index 0000000..43a17de > --- /dev/null > +++ b/gcc/config/arm/uclinuxfdpiceabi.h > @@ -0,0 +1,53 @@ > +/* 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}}}}}" > + > +/* 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. */ > +/* Even with -static, we have to define the dynamic-linker, as we > + have some relocations to resolve at load time. */ > +#undef SUBTARGET_EXTRA_LINK_SPEC > +#define SUBTARGET_EXTRA_LINK_SPEC \ > + "%{!mno-fdpic: -m " TARGET_FDPIC_LINKER_EMULATION \ > + "%{!shared:%{!r: -pie}} \ > + %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \ > + "%{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 1dce1e6..dff34cd 100644 > --- a/libsanitizer/configure.tgt > +++ b/libsanitizer/configure.tgt > @@ -43,6 +43,9 @@ case "${target}" in > ;; > s390*-*-linux*) > ;; > + arm*-*-uclinuxfdpiceabi) > + UNSUPPORTED=1 > + ;; > arm*-*-linux*) > ;; > mips*64*-*-linux*) >
On Fri, 12 Oct 2018 at 12:01, Richard Earnshaw (lists) < Richard.Earnshaw@arm.com> wrote: > On 11/10/18 14:34, Christophe Lyon wrote: > > 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 even for static > > link, we must specify 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. > > > > 2018-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. > > * config/arm/uclinuxfdpiceabi.h: New file. > > > > libsanitizer/ > > * configure.tgt (arm*-*-uclinuxfdpiceabi): Sanitizers are > > unsupported in this configuration. > > The documentation (in patch 1) seems to imply that -mfdpic is available > in all configurations and has certain effects (such as enabling -fPIE), > but this patch set suggests that such behaviours are only available when > the compiler is configured explicitly for an fdpic target. > > I think this needs to be resolved. Either -mfdpic works everywhere, or > the option should only be available when configured for -mfdpic. > > You are right, this is not clear. I tried to follow what other fdpic targets do, but it's not consistent either, it seems. So, at present, -mfdpic alone is in general not sufficient, and the user has to use -fpic/-fPIC/-fpie/-fPIE as needed. When configured for arm-uclinuxfdpiceabi, this is done implicitly (thanks to this patch). One possibility is to rephrase the doc, and say that -fPIE is only implied when GCC is configured for arm-uclinuxfdpiceabi. Do you mean to also make -mfdpic non-existent/rejected when GCC is not configured for arm-uclinuxfdpiceabi? How to achieve that? R. > > > > > Change-Id: If369e0a10bb916fd72e38f71498d3c640fa85c4c > > > > diff --git a/gcc/config.gcc b/gcc/config.gcc > > index 793fc69..a4f4331 100644 > > --- a/gcc/config.gcc > > +++ b/gcc/config.gcc > > @@ -1144,6 +1144,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 1e3ecfb..5901154 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,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 > > > > #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 8585fde..4cee958 100644 > > --- a/gcc/config/arm/linux-eabi.h > > +++ b/gcc/config/arm/linux-eabi.h > > @@ -98,11 +98,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) > > diff --git a/gcc/config/arm/uclinuxfdpiceabi.h > b/gcc/config/arm/uclinuxfdpiceabi.h > > new file mode 100644 > > index 0000000..43a17de > > --- /dev/null > > +++ b/gcc/config/arm/uclinuxfdpiceabi.h > > @@ -0,0 +1,53 @@ > > +/* 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}}}}}" > > + > > +/* 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. */ > > +/* Even with -static, we have to define the dynamic-linker, as we > > + have some relocations to resolve at load time. */ > > +#undef SUBTARGET_EXTRA_LINK_SPEC > > +#define SUBTARGET_EXTRA_LINK_SPEC \ > > + "%{!mno-fdpic: -m " TARGET_FDPIC_LINKER_EMULATION \ > > + "%{!shared:%{!r: -pie}} \ > > + %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \ > > + "%{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 1dce1e6..dff34cd 100644 > > --- a/libsanitizer/configure.tgt > > +++ b/libsanitizer/configure.tgt > > @@ -43,6 +43,9 @@ case "${target}" in > > ;; > > s390*-*-linux*) > > ;; > > + arm*-*-uclinuxfdpiceabi) > > + UNSUPPORTED=1 > > + ;; > > arm*-*-linux*) > > ;; > > mips*64*-*-linux*) > > > >
On 15/10/2018 11:10, Christophe Lyon wrote: > On Fri, 12 Oct 2018 at 12:01, Richard Earnshaw (lists) < > Richard.Earnshaw@arm.com> wrote: > >> On 11/10/18 14:34, Christophe Lyon wrote: >>> 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 even for static >>> link, we must specify 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. >>> >>> 2018-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. >>> * config/arm/uclinuxfdpiceabi.h: New file. >>> >>> libsanitizer/ >>> * configure.tgt (arm*-*-uclinuxfdpiceabi): Sanitizers are >>> unsupported in this configuration. >> >> The documentation (in patch 1) seems to imply that -mfdpic is available >> in all configurations and has certain effects (such as enabling -fPIE), >> but this patch set suggests that such behaviours are only available when >> the compiler is configured explicitly for an fdpic target. >> >> I think this needs to be resolved. Either -mfdpic works everywhere, or >> the option should only be available when configured for -mfdpic. >> >> > You are right, this is not clear. I tried to follow what other fdpic > targets do, > but it's not consistent either, it seems. > > So, at present, -mfdpic alone is in general not sufficient, and the user has > to use -fpic/-fPIC/-fpie/-fPIE as needed. When configured for > arm-uclinuxfdpiceabi, > this is done implicitly (thanks to this patch). > > One possibility is to rephrase the doc, and say that -fPIE is only implied > when GCC > is configured for arm-uclinuxfdpiceabi. > > Do you mean to also make -mfdpic non-existent/rejected when GCC is not > configured > for arm-uclinuxfdpiceabi? Ideally doesn't exist, so that it doesn't show up in things like --help when it doesn't work. > How to achieve that? Good question, I'm not sure, off hand. It might be possible to make the config machinery add additional opt files, but it's not something I've tried. You might want to try adding an additional opt file to extra_options for fdpic targets. R. > > > R. >> >>> >>> Change-Id: If369e0a10bb916fd72e38f71498d3c640fa85c4c >>> >>> diff --git a/gcc/config.gcc b/gcc/config.gcc >>> index 793fc69..a4f4331 100644 >>> --- a/gcc/config.gcc >>> +++ b/gcc/config.gcc >>> @@ -1144,6 +1144,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 1e3ecfb..5901154 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,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 >>> >>> #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 8585fde..4cee958 100644 >>> --- a/gcc/config/arm/linux-eabi.h >>> +++ b/gcc/config/arm/linux-eabi.h >>> @@ -98,11 +98,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) >>> diff --git a/gcc/config/arm/uclinuxfdpiceabi.h >> b/gcc/config/arm/uclinuxfdpiceabi.h >>> new file mode 100644 >>> index 0000000..43a17de >>> --- /dev/null >>> +++ b/gcc/config/arm/uclinuxfdpiceabi.h >>> @@ -0,0 +1,53 @@ >>> +/* 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}}}}}" >>> + >>> +/* 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. */ >>> +/* Even with -static, we have to define the dynamic-linker, as we >>> + have some relocations to resolve at load time. */ >>> +#undef SUBTARGET_EXTRA_LINK_SPEC >>> +#define SUBTARGET_EXTRA_LINK_SPEC \ >>> + "%{!mno-fdpic: -m " TARGET_FDPIC_LINKER_EMULATION \ >>> + "%{!shared:%{!r: -pie}} \ >>> + %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \ >>> + "%{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 1dce1e6..dff34cd 100644 >>> --- a/libsanitizer/configure.tgt >>> +++ b/libsanitizer/configure.tgt >>> @@ -43,6 +43,9 @@ case "${target}" in >>> ;; >>> s390*-*-linux*) >>> ;; >>> + arm*-*-uclinuxfdpiceabi) >>> + UNSUPPORTED=1 >>> + ;; >>> arm*-*-linux*) >>> ;; >>> mips*64*-*-linux*) >>> >> >>
On Tue, Oct 23, 2018 at 02:58:21PM +0100, Richard Earnshaw (lists) wrote: > On 15/10/2018 11:10, Christophe Lyon wrote: > > Do you mean to also make -mfdpic non-existent/rejected when GCC is not > > configured > > for arm-uclinuxfdpiceabi? > > Ideally doesn't exist, so that it doesn't show up in things like --help > when it doesn't work. > > > How to achieve that? > > Good question, I'm not sure, off hand. It might be possible to make the > config machinery add additional opt files, but it's not something I've > tried. You might want to try adding an additional opt file to > extra_options for fdpic targets. That should work yes. You could look at how 476.opt is added for powerpc, it is a comparable situation. Segher
On Tue, 23 Oct 2018 at 17:14, Segher Boessenkool <segher@kernel.crashing.org> wrote: > > On Tue, Oct 23, 2018 at 02:58:21PM +0100, Richard Earnshaw (lists) wrote: > > On 15/10/2018 11:10, Christophe Lyon wrote: > > > Do you mean to also make -mfdpic non-existent/rejected when GCC is not > > > configured > > > for arm-uclinuxfdpiceabi? > > > > Ideally doesn't exist, so that it doesn't show up in things like --help > > when it doesn't work. > > > > > How to achieve that? > > > > Good question, I'm not sure, off hand. It might be possible to make the > > config machinery add additional opt files, but it's not something I've > > tried. You might want to try adding an additional opt file to > > extra_options for fdpic targets. > > That should work yes. You could look at how 476.opt is added for powerpc, > it is a comparable situation. > Thanks, I got it to work. Now back to Richard's original question: > I think this needs to be resolved. Either -mfdpic works everywhere, or > the option should only be available when configured for -mfdpic. It's not that -mfdpic does not work everywhere, rather it is not sufficient to use it alone: it should be used along with fpic/fPIC/fpie/fPIE depending on the use case. In practice I don't know if we want to be able to use -mfdpic with a arm-linux-gnueabi toolchain, or if we are ok to have to use two different toolchains when we want to make tests/compare code generation in both cases. The 1st option means I should improve the documentation patch. For the 2nd one, I have patches in progress (which also imply reworking the doc since the option would not also be available) Christophe > > Segher
On Fri, 26 Oct 2018 at 17:07, Christophe Lyon <christophe.lyon@linaro.org> wrote: > > On Tue, 23 Oct 2018 at 17:14, Segher Boessenkool > <segher@kernel.crashing.org> wrote: > > > > On Tue, Oct 23, 2018 at 02:58:21PM +0100, Richard Earnshaw (lists) wrote: > > > On 15/10/2018 11:10, Christophe Lyon wrote: > > > > Do you mean to also make -mfdpic non-existent/rejected when GCC is not > > > > configured > > > > for arm-uclinuxfdpiceabi? > > > > > > Ideally doesn't exist, so that it doesn't show up in things like --help > > > when it doesn't work. > > > > > > > How to achieve that? > > > > > > Good question, I'm not sure, off hand. It might be possible to make the > > > config machinery add additional opt files, but it's not something I've > > > tried. You might want to try adding an additional opt file to > > > extra_options for fdpic targets. > > > > That should work yes. You could look at how 476.opt is added for powerpc, > > it is a comparable situation. > > > > Thanks, I got it to work. > > Now back to Richard's original question: > > I think this needs to be resolved. Either -mfdpic works everywhere, or > > the option should only be available when configured for -mfdpic. > It's not that -mfdpic does not work everywhere, rather it is not sufficient > to use it alone: it should be used along with fpic/fPIC/fpie/fPIE depending > on the use case. > > In practice I don't know if we want to be able to use -mfdpic with a > arm-linux-gnueabi > toolchain, or if we are ok to have to use two different toolchains > when we want to make > tests/compare code generation in both cases. > > The 1st option means I should improve the documentation patch. For the 2nd one, > I have patches in progress (which also imply reworking the doc since the option > would not also be available) > Here is an updated doc proposal (that would go in patch #1, without changing this one): @item -mfdpic @opindex mfdpic Select the FDPIC ABI, which uses function descriptors to represent pointers to functions. When the compiler is configured for @code{arm-*-uclinuxfdpiceabi} targets, this option is on by default and implies @option{-fPIE} if none of the PIC/PIE-related options is provided. On other targets, it only enables the FDPIC-specific code generation features, and the user should explicitly provide the PIC/PIE-related options as needed. The opposite @option{-mno-fdpic} option is useful (and required) to build the Linux kernel using the same toolchain as the one used to build the userland programs. Is it clearer? Does it read OK? Thanks > Christophe > > > > > > Segher
On Mon, Oct 29, 2018 at 02:45:20PM +0100, Christophe Lyon wrote: > Here is an updated doc proposal (that would go in patch #1, without > changing this one): > @item -mfdpic > @opindex mfdpic > Select the FDPIC ABI, which uses function descriptors to represent > pointers to functions. When the compiler is configured for > @code{arm-*-uclinuxfdpiceabi} targets, this option is on by default > and implies @option{-fPIE} if none of the PIC/PIE-related options is > provided. On other targets, it only enables the FDPIC-specific code > generation features, and the user should explicitly provide the > PIC/PIE-related options as needed. Most other things seem to put -mno-fdpic in an @itemx and mno-fdpic in an @opindex as well, in similar cases. > The opposite @option{-mno-fdpic} option is useful (and required) to > build the Linux kernel using the same toolchain as the one used to > build the userland programs. > > Is it clearer? Does it read OK? It reads fine I think. Segher
diff --git a/gcc/config.gcc b/gcc/config.gcc index 793fc69..a4f4331 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1144,6 +1144,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 1e3ecfb..5901154 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,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 #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 8585fde..4cee958 100644 --- a/gcc/config/arm/linux-eabi.h +++ b/gcc/config/arm/linux-eabi.h @@ -98,11 +98,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) diff --git a/gcc/config/arm/uclinuxfdpiceabi.h b/gcc/config/arm/uclinuxfdpiceabi.h new file mode 100644 index 0000000..43a17de --- /dev/null +++ b/gcc/config/arm/uclinuxfdpiceabi.h @@ -0,0 +1,53 @@ +/* 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}}}}}" + +/* 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. */ +/* Even with -static, we have to define the dynamic-linker, as we + have some relocations to resolve at load time. */ +#undef SUBTARGET_EXTRA_LINK_SPEC +#define SUBTARGET_EXTRA_LINK_SPEC \ + "%{!mno-fdpic: -m " TARGET_FDPIC_LINKER_EMULATION \ + "%{!shared:%{!r: -pie}} \ + %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \ + "%{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 1dce1e6..dff34cd 100644 --- a/libsanitizer/configure.tgt +++ b/libsanitizer/configure.tgt @@ -43,6 +43,9 @@ case "${target}" in ;; s390*-*-linux*) ;; + arm*-*-uclinuxfdpiceabi) + UNSUPPORTED=1 + ;; arm*-*-linux*) ;; mips*64*-*-linux*)