diff mbox series

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

Message ID 20190515124006.25840-4-christophe.lyon@st.com
State New
Headers show
Series FDPIC ABI for ARM | expand

Commit Message

Christophe Lyon May 15, 2019, 12:39 p.m. UTC
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.

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.
	* config/arm/uclinuxfdpiceabi.h: New file.

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

Change-Id: If369e0a10bb916fd72e38f71498d3c640fa85c4c

-- 
2.6.3

Comments

Szabolcs Nagy May 15, 2019, 1:55 p.m. UTC | #1
On 15/05/2019 13:39, 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.

...
> +/* 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}}"


i think -dynamic-linker can be avoided for -static using
-static-pie linking with rcrt0.o

but more importantly: does the abi spec require the sysv dynamic
linker name? that sounds suboptimal (in principle the same os
can support both normal elf and fdpic elf so you can test/use
an fdpic toolchain on a system with mmu, but this requires
different dynamic linker name ..otherwise one has to run
executables in a chroot or separate mount namespace to change
the dynamic linker)

> +

> +#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..c38b3f4 100644

> --- a/libsanitizer/configure.tgt

> +++ b/libsanitizer/configure.tgt

> @@ -45,6 +45,9 @@ case "${target}" in

>  	;;

>    sparc*-*-solaris2.11*)

>  	;;

> +  arm*-*-uclinuxfdpiceabi)

> +	UNSUPPORTED=1

> +	;;


musl libc has fdpic support on sh (e.g. with sh2eb-linux-muslfdpic
target and --enable-fdpic), it can probably support fdpic on arm
too with minimal changes, i assume the target name for that would
be arm-linux-muslfdpiceabi.

so i think it is better to check arm*-*fdpiceabi where the libc
does not matter (so we dont have to patch the same files when
*-muslfdpiceabi support is added).
dalias@libc.org May 15, 2019, 2:36 p.m. UTC | #2
On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:
> On 15/05/2019 13:39, 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.

> ...

> > +/* 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}}"

> 

> i think -dynamic-linker can be avoided for -static using

> -static-pie linking with rcrt0.o


Yes, -dynamic-linker should never be used with -static.

> but more importantly: does the abi spec require the sysv dynamic

> linker name? that sounds suboptimal (in principle the same os


ABI specs typically do this and we just ignore it. BFD contains
default dynamic linker strings for all sorts of ABIs, and they're all
wrong -- things like /lib/ld64.so.1, etc. I don't think it's worth
bothering with fighting the desire of folks writing ABI specs to do
this again and again. GCC overrides them all with the actually-correct
values when !static.

> can support both normal elf and fdpic elf so you can test/use

> an fdpic toolchain on a system with mmu, but this requires

> different dynamic linker name ..otherwise one has to run

> executables in a chroot or separate mount namespace to change

> the dynamic linker)


Indeed, it's a bad idea to make them clash.

> > +

> > +#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..c38b3f4 100644

> > --- a/libsanitizer/configure.tgt

> > +++ b/libsanitizer/configure.tgt

> > @@ -45,6 +45,9 @@ case "${target}" in

> >  	;;

> >    sparc*-*-solaris2.11*)

> >  	;;

> > +  arm*-*-uclinuxfdpiceabi)

> > +	UNSUPPORTED=1

> > +	;;

> 

> musl libc has fdpic support on sh (e.g. with sh2eb-linux-muslfdpic

> target and --enable-fdpic), it can probably support fdpic on arm

> too with minimal changes, i assume the target name for that would

> be arm-linux-muslfdpiceabi.


I plan to add ARM FDPIC support as soon as there is (1) published ABI
for relocation types, entry point contract, etc., and (2) there's
tooling to support it that's either upstream or can be applied as
clean patches to recent gcc (as opposed to some fork of gcc4 or
whatever it was this got started as). I think those conditions are
mostly met now.

> so i think it is better to check arm*-*fdpiceabi where the libc

> does not matter (so we dont have to patch the same files when

> *-muslfdpiceabi support is added).


Yes, that would be appreciated. Maybe we could get musl ldso names
added at the same time, too? I think they should just be the same as
the existing musl ldso names but with "-fdpic" appended before
".so.1".

Rich
Christophe Lyon May 15, 2019, 3:12 p.m. UTC | #3
On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:
>

> On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

> > On 15/05/2019 13:39, 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.

> > ...

> > > +/* 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}}"

> >

> > i think -dynamic-linker can be avoided for -static using

> > -static-pie linking with rcrt0.o

>

> Yes, -dynamic-linker should never be used with -static.


So, do you mean dropping completely the line:
+    %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \
and thus make -static unsupported, forcing users to use -static-pie instead?

> > but more importantly: does the abi spec require the sysv dynamic

> > linker name? that sounds suboptimal (in principle the same os

>

> ABI specs typically do this and we just ignore it. BFD contains

> default dynamic linker strings for all sorts of ABIs, and they're all

> wrong -- things like /lib/ld64.so.1, etc. I don't think it's worth

> bothering with fighting the desire of folks writing ABI specs to do

> this again and again. GCC overrides them all with the actually-correct

> values when !static.

>

> > can support both normal elf and fdpic elf so you can test/use

> > an fdpic toolchain on a system with mmu, but this requires

> > different dynamic linker name ..otherwise one has to run

> > executables in a chroot or separate mount namespace to change

> > the dynamic linker)

>

> Indeed, it's a bad idea to make them clash.

>


Not sure to understand your point: indeed FDPIC binaries work
on a system with mmu, provided you have the right dynamic
linker in the right place, as well as the needed runtime libs (libc, etc....)

Do you want me to change anything here?

> > > +

> > > +#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..c38b3f4 100644

> > > --- a/libsanitizer/configure.tgt

> > > +++ b/libsanitizer/configure.tgt

> > > @@ -45,6 +45,9 @@ case "${target}" in

> > >     ;;

> > >    sparc*-*-solaris2.11*)

> > >     ;;

> > > +  arm*-*-uclinuxfdpiceabi)

> > > +   UNSUPPORTED=1

> > > +   ;;

> >

> > musl libc has fdpic support on sh (e.g. with sh2eb-linux-muslfdpic

> > target and --enable-fdpic), it can probably support fdpic on arm

> > too with minimal changes, i assume the target name for that would

> > be arm-linux-muslfdpiceabi.

>

> I plan to add ARM FDPIC support as soon as there is (1) published ABI

> for relocation types, entry point contract, etc., and (2) there's


The ABI is here:
https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt

> tooling to support it that's either upstream or can be applied as

> clean patches to recent gcc (as opposed to some fork of gcc4 or

> whatever it was this got started as). I think those conditions are

> mostly met now.

This patch series applies on gcc trunk as of ~2 weeks ago

> > so i think it is better to check arm*-*fdpiceabi where the libc

> > does not matter (so we dont have to patch the same files when

> > *-muslfdpiceabi support is added).

>

Looks sane.

> Yes, that would be appreciated. Maybe we could get musl ldso names

> added at the same time, too? I think they should just be the same as

> the existing musl ldso names but with "-fdpic" appended before

> ".so.1".

Do you mean updating config/arm/linux-eabi.h and adding -fdpic to the
4 musl dynamic linker names?

> Rich
dalias@libc.org May 15, 2019, 3:37 p.m. UTC | #4
On Wed, May 15, 2019 at 05:12:11PM +0200, Christophe Lyon wrote:
> On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:

> >

> > On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

> > > On 15/05/2019 13:39, 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.

> > > ...

> > > > +/* 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}}"

> > >

> > > i think -dynamic-linker can be avoided for -static using

> > > -static-pie linking with rcrt0.o

> >

> > Yes, -dynamic-linker should never be used with -static.

> 

> So, do you mean dropping completely the line:

> +    %{static:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" \

> and thus make -static unsupported, forcing users to use -static-pie instead?


Rather I would have -static behave the same as -static-pie. The intent
on musl when we added static pie (before glibc had it) was that
-static plus -pie (including default-pie, if built as default-pie)
would yield static pie output, and our patches still do this. When
static-pie was upstreamed in gcc, it was done differently for
compatibility with legacy versions of glibc. That's not a
consideration for fdpic.

> > > but more importantly: does the abi spec require the sysv dynamic

> > > linker name? that sounds suboptimal (in principle the same os

> >

> > ABI specs typically do this and we just ignore it. BFD contains

> > default dynamic linker strings for all sorts of ABIs, and they're all

> > wrong -- things like /lib/ld64.so.1, etc. I don't think it's worth

> > bothering with fighting the desire of folks writing ABI specs to do

> > this again and again. GCC overrides them all with the actually-correct

> > values when !static.

> >

> > > can support both normal elf and fdpic elf so you can test/use

> > > an fdpic toolchain on a system with mmu, but this requires

> > > different dynamic linker name ..otherwise one has to run

> > > executables in a chroot or separate mount namespace to change

> > > the dynamic linker)

> >

> > Indeed, it's a bad idea to make them clash.

> >

> 

> Not sure to understand your point: indeed FDPIC binaries work

> on a system with mmu, provided you have the right dynamic

> linker in the right place, as well as the needed runtime libs (libc, etc....)

> 

> Do you want me to change anything here?


I think the concern is that if the PT_INTERP name is the same for
binaries with different ABIs, you wouldn't be able to have both
present in the same root fs, and this would make it more of a pain to
debug fdpic binaries on a full (with-mmu) host.

musl always uses a different PT_INTERP name for each ABI combination,
so I guess the question is whether uclibc or whatever other libc
you're intending people to use would also want to do this.

> > > > +#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..c38b3f4 100644

> > > > --- a/libsanitizer/configure.tgt

> > > > +++ b/libsanitizer/configure.tgt

> > > > @@ -45,6 +45,9 @@ case "${target}" in

> > > >     ;;

> > > >    sparc*-*-solaris2.11*)

> > > >     ;;

> > > > +  arm*-*-uclinuxfdpiceabi)

> > > > +   UNSUPPORTED=1

> > > > +   ;;

> > >

> > > musl libc has fdpic support on sh (e.g. with sh2eb-linux-muslfdpic

> > > target and --enable-fdpic), it can probably support fdpic on arm

> > > too with minimal changes, i assume the target name for that would

> > > be arm-linux-muslfdpiceabi.

> >

> > I plan to add ARM FDPIC support as soon as there is (1) published ABI

> > for relocation types, entry point contract, etc., and (2) there's

> 

> The ABI is here:

> https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt

> 

> > tooling to support it that's either upstream or can be applied as

> > clean patches to recent gcc (as opposed to some fork of gcc4 or

> > whatever it was this got started as). I think those conditions are

> > mostly met now.

> This patch series applies on gcc trunk as of ~2 weeks ago


Excellent news!

> > > so i think it is better to check arm*-*fdpiceabi where the libc

> > > does not matter (so we dont have to patch the same files when

> > > *-muslfdpiceabi support is added).

> >

> Looks sane.

> 

> > Yes, that would be appreciated. Maybe we could get musl ldso names

> > added at the same time, too? I think they should just be the same as

> > the existing musl ldso names but with "-fdpic" appended before

> > ".so.1".

> Do you mean updating config/arm/linux-eabi.h and adding -fdpic to the

> 4 musl dynamic linker names?


Yes, conditional on target being fdpic of course.

Rich
Szabolcs Nagy May 15, 2019, 3:59 p.m. UTC | #5
On 15/05/2019 16:37, Rich Felker wrote:
> On Wed, May 15, 2019 at 05:12:11PM +0200, Christophe Lyon wrote:

>> On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:

>>> On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

>>>> can support both normal elf and fdpic elf so you can test/use

>>>> an fdpic toolchain on a system with mmu, but this requires

>>>> different dynamic linker name ..otherwise one has to run

>>>> executables in a chroot or separate mount namespace to change

>>>> the dynamic linker)

>>>

>>> Indeed, it's a bad idea to make them clash.

>>>

>>

>> Not sure to understand your point: indeed FDPIC binaries work

>> on a system with mmu, provided you have the right dynamic

>> linker in the right place, as well as the needed runtime libs (libc, etc....)

>>

>> Do you want me to change anything here?

> 

> I think the concern is that if the PT_INTERP name is the same for

> binaries with different ABIs, you wouldn't be able to have both

> present in the same root fs, and this would make it more of a pain to

> debug fdpic binaries on a full (with-mmu) host.

> 

> musl always uses a different PT_INTERP name for each ABI combination,

> so I guess the question is whether uclibc or whatever other libc

> you're intending people to use would also want to do this.


glibc uses different names now for new abis, so i was expecting
some *_DYNAMIC_LINKER update, but it seems uclibc always uses
the same fixed name

/lib/ld-uClibc.so.0

i guess it makes sense for them since iirc uclibc can change
its runtime abi based on lot of build time config so having
different name for each abi variant may be impractical.
dalias@libc.org May 15, 2019, 4:06 p.m. UTC | #6
On Wed, May 15, 2019 at 03:59:39PM +0000, Szabolcs Nagy wrote:
> On 15/05/2019 16:37, Rich Felker wrote:

> > On Wed, May 15, 2019 at 05:12:11PM +0200, Christophe Lyon wrote:

> >> On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:

> >>> On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

> >>>> can support both normal elf and fdpic elf so you can test/use

> >>>> an fdpic toolchain on a system with mmu, but this requires

> >>>> different dynamic linker name ..otherwise one has to run

> >>>> executables in a chroot or separate mount namespace to change

> >>>> the dynamic linker)

> >>>

> >>> Indeed, it's a bad idea to make them clash.

> >>>

> >>

> >> Not sure to understand your point: indeed FDPIC binaries work

> >> on a system with mmu, provided you have the right dynamic

> >> linker in the right place, as well as the needed runtime libs (libc, etc....)

> >>

> >> Do you want me to change anything here?

> > 

> > I think the concern is that if the PT_INTERP name is the same for

> > binaries with different ABIs, you wouldn't be able to have both

> > present in the same root fs, and this would make it more of a pain to

> > debug fdpic binaries on a full (with-mmu) host.

> > 

> > musl always uses a different PT_INTERP name for each ABI combination,

> > so I guess the question is whether uclibc or whatever other libc

> > you're intending people to use would also want to do this.

> 

> glibc uses different names now for new abis, so i was expecting

> some *_DYNAMIC_LINKER update, but it seems uclibc always uses

> the same fixed name

> 

> /lib/ld-uClibc.so.0

> 

> i guess it makes sense for them since iirc uclibc can change

> its runtime abi based on lot of build time config so having

> different name for each abi variant may be impractical.


Yes, this "feature" of uclibc was was of the key motivations behind
the creation of musl... :-)

Rich
Christophe Lyon May 21, 2019, 3:28 p.m. UTC | #7
On Wed, 15 May 2019 at 18:06, Rich Felker <dalias@libc.org> wrote:
>

> On Wed, May 15, 2019 at 03:59:39PM +0000, Szabolcs Nagy wrote:

> > On 15/05/2019 16:37, Rich Felker wrote:

> > > On Wed, May 15, 2019 at 05:12:11PM +0200, Christophe Lyon wrote:

> > >> On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:

> > >>> On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

> > >>>> can support both normal elf and fdpic elf so you can test/use

> > >>>> an fdpic toolchain on a system with mmu, but this requires

> > >>>> different dynamic linker name ..otherwise one has to run

> > >>>> executables in a chroot or separate mount namespace to change

> > >>>> the dynamic linker)

> > >>>

> > >>> Indeed, it's a bad idea to make them clash.

> > >>>

> > >>

> > >> Not sure to understand your point: indeed FDPIC binaries work

> > >> on a system with mmu, provided you have the right dynamic

> > >> linker in the right place, as well as the needed runtime libs (libc, etc....)

> > >>

> > >> Do you want me to change anything here?

> > >

> > > I think the concern is that if the PT_INTERP name is the same for

> > > binaries with different ABIs, you wouldn't be able to have both

> > > present in the same root fs, and this would make it more of a pain to

> > > debug fdpic binaries on a full (with-mmu) host.

> > >

> > > musl always uses a different PT_INTERP name for each ABI combination,

> > > so I guess the question is whether uclibc or whatever other libc

> > > you're intending people to use would also want to do this.

> >

> > glibc uses different names now for new abis, so i was expecting

> > some *_DYNAMIC_LINKER update, but it seems uclibc always uses

> > the same fixed name

> >

> > /lib/ld-uClibc.so.0

> >

> > i guess it makes sense for them since iirc uclibc can change

> > its runtime abi based on lot of build time config so having

> > different name for each abi variant may be impractical.

>

> Yes, this "feature" of uclibc was was of the key motivations behind

> the creation of musl... :-)

>


Hi,

I discussed a bit further with Szabolcs on irc, and tried to get some
feedback from uclibc-ng community (none so far)

I propose the following 2 patches on top of this one to address part
of the concerns:
diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index 67edb42..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.  */

diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index c38b3f4..92bca69 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -45,7 +45,7 @@ case "${target}" in
        ;;
   sparc*-*-solaris2.11*)
        ;;
-  arm*-*-uclinuxfdpiceabi)
+  arm*-*-fdpiceabi)
        UNSUPPORTED=1
        ;;
   arm*-*-linux*)

However, regarding -staic/-static-pie, it seems I have several options:
(a) add support for static-pie to uclibc-ng. This means creating a new
rcrt1.o or similar, which would embed parts of the dynamic linker into
static-pie executables. This seems to involve quite a bit of work

(b) add support for FDPIC on arm to musl, which I'm not familiar with

(c) declare -static not supported on arm-FDPIC

(d) gather consensus that -static with pt_interp is ok (my preference,
since that's what the current patches do :-)

At this point, I'd prefer to stick with (d), or (c), to avoid further delaying
inclusion of FDPIC support for arm in GCC, and address improvements
later, so that it's not a constantly moving target.

Thanks,

Christophe
dalias@libc.org May 21, 2019, 3:48 p.m. UTC | #8
On Tue, May 21, 2019 at 05:28:51PM +0200, Christophe Lyon wrote:
> On Wed, 15 May 2019 at 18:06, Rich Felker <dalias@libc.org> wrote:

> >

> > On Wed, May 15, 2019 at 03:59:39PM +0000, Szabolcs Nagy wrote:

> > > On 15/05/2019 16:37, Rich Felker wrote:

> > > > On Wed, May 15, 2019 at 05:12:11PM +0200, Christophe Lyon wrote:

> > > >> On Wed, 15 May 2019 at 16:37, Rich Felker <dalias@libc.org> wrote:

> > > >>> On Wed, May 15, 2019 at 01:55:30PM +0000, Szabolcs Nagy wrote:

> > > >>>> can support both normal elf and fdpic elf so you can test/use

> > > >>>> an fdpic toolchain on a system with mmu, but this requires

> > > >>>> different dynamic linker name ..otherwise one has to run

> > > >>>> executables in a chroot or separate mount namespace to change

> > > >>>> the dynamic linker)

> > > >>>

> > > >>> Indeed, it's a bad idea to make them clash.

> > > >>>

> > > >>

> > > >> Not sure to understand your point: indeed FDPIC binaries work

> > > >> on a system with mmu, provided you have the right dynamic

> > > >> linker in the right place, as well as the needed runtime libs (libc, etc....)

> > > >>

> > > >> Do you want me to change anything here?

> > > >

> > > > I think the concern is that if the PT_INTERP name is the same for

> > > > binaries with different ABIs, you wouldn't be able to have both

> > > > present in the same root fs, and this would make it more of a pain to

> > > > debug fdpic binaries on a full (with-mmu) host.

> > > >

> > > > musl always uses a different PT_INTERP name for each ABI combination,

> > > > so I guess the question is whether uclibc or whatever other libc

> > > > you're intending people to use would also want to do this.

> > >

> > > glibc uses different names now for new abis, so i was expecting

> > > some *_DYNAMIC_LINKER update, but it seems uclibc always uses

> > > the same fixed name

> > >

> > > /lib/ld-uClibc.so.0

> > >

> > > i guess it makes sense for them since iirc uclibc can change

> > > its runtime abi based on lot of build time config so having

> > > different name for each abi variant may be impractical.

> >

> > Yes, this "feature" of uclibc was was of the key motivations behind

> > the creation of musl... :-)

> >

> 

> Hi,

> 

> I discussed a bit further with Szabolcs on irc, and tried to get some

> feedback from uclibc-ng community (none so far)

> 

> I propose the following 2 patches on top of this one to address part

> of the concerns:

> diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h

> index 67edb42..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.  */

> 

> diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt

> index c38b3f4..92bca69 100644

> --- a/libsanitizer/configure.tgt

> +++ b/libsanitizer/configure.tgt

> @@ -45,7 +45,7 @@ case "${target}" in

>         ;;

>    sparc*-*-solaris2.11*)

>         ;;

> -  arm*-*-uclinuxfdpiceabi)

> +  arm*-*-fdpiceabi)

>         UNSUPPORTED=1

>         ;;

>    arm*-*-linux*)

> 

> However, regarding -staic/-static-pie, it seems I have several options:

> (a) add support for static-pie to uclibc-ng. This means creating a new

> rcrt1.o or similar, which would embed parts of the dynamic linker into

> static-pie executables. This seems to involve quite a bit of work

> 

> (b) add support for FDPIC on arm to musl, which I'm not familiar with

> 

> (c) declare -static not supported on arm-FDPIC

> 

> (d) gather consensus that -static with pt_interp is ok (my preference,

> since that's what the current patches do :-)


musl definitely does not support static with pt_interp, and won't. If
it works, it's by chance, and not a good idea to try relying on it. If
you want to follow this path in upstream for now that's fine but it
means musl users will need to apply patches. This is already done
anyway, so it's not a *new* burden, but it's still annoying.

> At this point, I'd prefer to stick with (d), or (c), to avoid further delaying

> inclusion of FDPIC support for arm in GCC, and address improvements

> later, so that it's not a constantly moving target.


I'd find (c) mildly better as long as it's still easy for us to patch.
Providing a -static that's not actually static is not useful and will
be harder to fix later.

Rich
Szabolcs Nagy May 22, 2019, 8:39 a.m. UTC | #9
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)

> --- 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.
Christophe Lyon May 22, 2019, 8:45 a.m. UTC | #10
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
Christophe Lyon May 23, 2019, 12:45 p.m. UTC | #11
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.

Christophe
From 828696b5c23e5907c2793f7654c29975d7dfbfc4 Mon Sep 17 00:00:00 2001
From: Christophe Lyon <christophe.lyon@st.com>
Date: Thu, 8 Feb 2018 11:11:56 +0100
Subject: [ARM/FDPIC v5 03/21] [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 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.

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.
---
 gcc/config.gcc                    |  5 ++++
 gcc/config/arm/bpabi.h            |  4 ++-
 gcc/config/arm/linux-eabi.h       |  9 ++++---
 gcc/config/arm/uclinuxfdpiceabi.h | 52 +++++++++++++++++++++++++++++++++++++++
 libsanitizer/configure.tgt        |  3 +++
 5 files changed, 69 insertions(+), 4 deletions(-)
 create mode 100644 gcc/config/arm/uclinuxfdpiceabi.h

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..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  ""
+
 #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 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)
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}}}}}"
+
+/* 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}} }"				    \
+  "%{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*)
Richard Sandiford July 16, 2019, 10:34 a.m. UTC | #12
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.

> 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 ""

> +

>  #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.

> 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?

> 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?

> 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.

> +/* Add --fdpic assembler flag by default.  */

> +#undef TARGET_FDPIC_ASM_SPEC

> +#define TARGET_FDPIC_ASM_SPEC  "%{!mno-fdpic: --fdpic}"


Single space before the ".

Thanks,
Richard
dalias@libc.org July 16, 2019, 7:55 p.m. UTC | #13
On Tue, Jul 16, 2019 at 11:34:06AM +0100, Richard Sandiford wrote:
> > 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?


Yes, as I understand the above logic, which should yield:

/lib/ld-musl-arm-fdpic.so.1
/lib/ld-musl-armhf-fdpic.so.1
/lib/ld-musl-armeb-fdpic.so.1
/lib/ld-musl-armebhf-fdpic.so.1

Rich
Christophe Lyon Aug. 1, 2019, 10:13 a.m. UTC | #14
On Tue, 16 Jul 2019 at 12:34, Richard Sandiford
<richard.sandiford@arm.com> 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?

>


Sure.
Do you know if there is a way to catch linker options in the specs?
Would it be possible to still accept -static -Wl,-dynamic-linker XXX ?

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

>

> > 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 ""

>

> > +

> >  #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.

>

> > 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?

>

> > 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, I will remove it.

>

> > 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.

Indeed.

> > +/* Add --fdpic assembler flag by default.  */

> > +#undef TARGET_FDPIC_ASM_SPEC

> > +#define TARGET_FDPIC_ASM_SPEC  "%{!mno-fdpic: --fdpic}"

>

> Single space before the ".

>


Thanks,

Christophe

> Thanks,

> Richard
Richard Sandiford Aug. 6, 2019, 2:24 p.m. UTC | #15
Christophe Lyon <christophe.lyon@linaro.org> writes:
> On Tue, 16 Jul 2019 at 12:34, Richard Sandiford

> <richard.sandiford@arm.com> 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?

>>

>

> Sure.

> Do you know if there is a way to catch linker options in the specs?

> Would it be possible to still accept -static -Wl,-dynamic-linker XXX ?


Ah, no, don't know a way of doing that.  Maybe the error isn't
feasible after all then (at least not without significant work).

Richard
Christophe Lyon Aug. 29, 2019, 2:59 p.m. UTC | #16
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
Richard Sandiford Aug. 30, 2019, 9:08 a.m. UTC | #17
Christophe Lyon <christophe.lyon@st.com> writes:
> 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/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.


Copyright year should be/include 2019.

OK with that change if no Arm maintainer objects before the rest
of the patch series is approved.

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

>

> 	gcc/testsuite/

> 	* lib/target-supports.exp (check_effective_target_static): Disable

> 	for ARM FDPIC target.


OK, thanks.

Richard
diff mbox series

Patch

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..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  ""
+
 #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 66ec0ea..67edb42 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -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)
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 b241ddb..c38b3f4 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -45,6 +45,9 @@  case "${target}" in
 	;;
   sparc*-*-solaris2.11*)
 	;;
+  arm*-*-uclinuxfdpiceabi)
+	UNSUPPORTED=1
+	;;
   arm*-*-linux*)
 	;;
   mips*64*-*-linux*)